簡體   English   中英

Kubernetes 指定命名空間時 Pod 無法聯系另一個 pod

[英]Kubernetes Pod not able to contact another pod when Namespace specified

我在 centOS 7 上使用 Kubernetes。

Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:23:11Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:13:49Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}

我確實使用以下prod_www_pod.yaml在“生產”命名空間上部署了 Nginx pod:

apiVersion: v1
kind: Pod
metadata:
  name: www
  namespace: production
  labels:
    app: www
spec:
  containers:
  - name: nginx
    image: myrepo:5001/nginx

我已經部署了第二個( prod_debug.yaml )以檢查一切是否正常運行。

apiVersion: v1
kind: Pod
metadata:
  name: debug
  namespace: production
spec:
  containers:
  - name: debug
    image: myrepo:5001/debug:latest
    command:
    - "sleep"
    - "10000"

我可以在正確的名稱空間上看到兩者,

[plaurent@kubmaster deployment]$ kubectl get po
No resources found in default namespace.
[plaurent@kubmaster deployment]$ kubectl get po -n production
NAME    READY   STATUS    RESTARTS   AGE
debug   1/1     Running   0          94s
www     1/1     Running   0          3m57s

但是當嘗試從調試 curl www 時,我有:

[plaurent@kubmaster deployment]$ kubectl exec -it -n production debug -- sh
/ # curl www
Nothing there
/ # 

kubectl delete po debug www -n production之后,我嘗試安裝相同的,除了刪除元數據上指定的命名空間。

[plaurent@kubmaster deployment]$ kubectl get po
NAME    READY   STATUS    RESTARTS   AGE
debug   1/1     Running   0          10s
www     1/1     Running   0          18s

並且在嘗試從調試中聯系 www 時,它運行良好。

[plaurent@kubmaster deployment]$ kubectl exec -it debug -- sh
/ # curl www
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
/ # 

有人可以指出我正確的方向嗎?

問候,

皮埃爾

您無法通過 dns 訪問 pod,除非您已為其配置了hostnamesubdomain ,並且訪問它的方式與您的做法不同。

可能您在default命名空間中有一個名為www的服務,它將請求轉發到 pod,但在您的production命名空間中,您沒有該服務。

要確認我在說什么,請在您的default命名空間和production命名空間中運行kubectl get svc

如果我是對的,請通過kubectl expose pod...公開您的 pod,或通過 yaml 文件創建服務。

現在,請注意創建 pod 是個壞主意。 最好使用 1 個副本創建 e 部署。

這適用於默認命名空間,而不是生產命名空間,因為 kube-dns 默認是如何配置的。 kube-dns 的默認 ndots 配置識別default.svc.cluster.local 因此,當使用默認命名空間時,默認值允許 kube-dns 定位 www。 但由於production.svc.cluster.local沒有默認條目,因此名稱解析失敗。

您需要配置服務以在生產命名空間中公開 www pod(也可以使用無頭服務)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM