【发布时间】:2020-02-02 02:58:21
【问题描述】:
当我为 nginx 设置 nginx 部署 (replica=1) 和服务 (nodeport) 时,我可以通过 CLUSTER-IP 从任何其他 pod 访问服务 (http),但无法访问 nginx pod 中的服务本身。 这种限制有什么原因吗?
模拟这种行为的步骤:
1) 创建 nginx 部署
kubectl create deployment nginx --image=helioay/nginx
2)创建服务(nodeport)
kubectl create service nodeport nginx --tcp=80:80
3) 检查 pod 和服务
[helio@kub-1 nginx]$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-67f769c566-jfhxl 1/1 Running 0 22m
[helio@kub-1 nginx]$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 45h
nginx NodePort 10.43.3.216 <none> 80:31790/TCP 20m
4) 用 Centos 运行另一个容器/pod,我可以看到我可以访问 nginx 调用服务定义的 CLUSTER-IP:
[helio@kub-1 nginx]$ kubectl run -it --rm --image=centos -- bash
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
If you don't see a command prompt, try pressing enter.
[root@bash-5d65698d48-klgvz /]# curl nginx
<!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>
5) 连接到 nginx pod 并通过 CLUSTER-IP 调用 (curl) nginx... 无响应:
[helio@kub-1 nginx]$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-67f769c566-jfhxl 1/1 Running 0 25m
[tecnotree@kub-1 nginx]$ kubectl exec -it nginx-67f769c566-jfhxl /bin/bash
root@nginx-67f769c566-jfhxl:/# curl nginx
^C
root@nginx-67f769c566-jfhxl:/# curl 10.43.3.216
^C
==> 可以看到 DNS 正在解析 nginx 名称,但不知何故它实际上无法到达 nginx 应用程序。
我曾尝试使用 NodePort 和 ClusterIP 服务配置,但总是相同的行为。
我希望我可以从 kubernet 集群中的任何 POD 访问 CLUSTER-IP.... 这种行为有什么特殊原因或有什么方法可以让它工作吗?
【问题讨论】:
-
什么显示你的猫
/etc/resolv.conf, nslookup hello, netstat -tlnp,你用的是什么图片? -
嗨@Hanx。经过大量谷歌搜索后,我可以在 kubernet 上找到以下问题。 github.com/kubernetes/kubernetes/issues/20475 我尝试了一些解决方法,但还没有奏效。谢谢
标签: kubernetes