当我为nginx设置nginx部署(副本= 1)和服务(节点端口)时,我可以通过CLUSTER-IP从任何其他Pod访问服务(http),但是我无法在Nginx Pod中访问该服务本身。 有什么限制的理由吗?
模拟这种行为的步骤:
1)创建nginx部署
kubectl create deployment nginx --image=helioay/nginx
2)创建服务(节点端口)
kubectl create service nodeport nginx --tcp=80:80
3)检查吊舱和服务
[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运行另一个容器/吊舱,我可以访问名为服务定义的CLUSTER-IP的nginx:
[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。...是否有任何特殊原因导致这种现象或使之正常工作?
答案 0 :(得分:0)
这是标准行为。
在minikube中,您可以解决运行中的问题:
minikube ssh
sudo ip link set docker0 promisc on
有几个打开/关闭的问题
整个行为都很模糊