act*_*nda 0 networking kubernetes
我在默认命名空间中有一个 nginx pod,并且有一个公开该 pod 的 ClusterIP 服务。
\n$ kubectl run nginx-pod --image=nginx\n$ kubectl expose po nginx-pod --name=nginx-service --port=8080 --target-port=80 --type=ClusterIP\n
Run Code Online (Sandbox Code Playgroud)\n我可以从集群内部通过其内部 IP 访问该服务。
\n$ kubectl get svc nginx-service\nNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE\nnginx-service ClusterIP 10.100.5.218 <none> 8080/TCP 2m49s\n$ wget -O- 10.100.5.218:8080\n
Run Code Online (Sandbox Code Playgroud)\n--> 200 好
\n我可以从 Pod 内部按名称访问该服务。
\n$ kubectl run tmp -it --rm --image=busybox --command -- /bin/sh -c 'wget -O- nginx-service:8080'\n
Run Code Online (Sandbox Code Playgroud)\n--> 200 好
\n但是,为什么我无法从 Pod 外部按名称访问服务?
\n$ wget -O- nginx-service:8080\n
Run Code Online (Sandbox Code Playgroud)\n或者
\n$ wget -O- nginx-service.default.svc.cluster.local:8080\n
Run Code Online (Sandbox Code Playgroud)\n-->wget: unable to resolve host address \xe2\x80\x98nginx-service\xe2\x80\x99
神奇的服务主机名(和 Pod 主机名)由“集群 DNS”服务提供,现在通常是 CoreDNS。针对内部 CoreDNS 的 resolv.conf 会自动注入到所有 pod 中。但我猜测“pod 外部”是指在其 resolv.conf 中没有此类条目的底层主机上。
归档时间: |
|
查看次数: |
349 次 |
最近记录: |