【发布时间】:2018-01-17 15:18:04
【问题描述】:
我使用kubeadm 创建了一个包含 5 个 VM(1 个主服务器和 4 个运行 Ubuntu 16.04.3 LTS 的从属服务器)的 K8s 集群。我使用flannel 在集群中设置网络。我能够成功部署应用程序。然后,我通过 NodePort 服务公开了它。从这里开始,我的事情变得复杂了。
在开始之前,我在 master 和节点上禁用了默认的 firewalld 服务。
我从K8s Services doc 了解到,NodePort 类型在集群中的所有节点上公开了服务。但是,当我创建它时,该服务仅在集群中 4 个节点中的 2 个节点上公开。我猜这不是预期的行为(对吗?)
对于故障排除,以下是一些资源规格:
root@vm-vivekse-003:~# kubectl get nodes
NAME STATUS AGE VERSION
vm-deepejai-00b Ready 5m v1.7.3
vm-plashkar-006 Ready 4d v1.7.3
vm-rosnthom-00f Ready 4d v1.7.3
vm-vivekse-003 Ready 4d v1.7.3 //the master
vm-vivekse-004 Ready 16h v1.7.3
root@vm-vivekse-003:~# kubectl get pods -o wide -n playground
NAME READY STATUS RESTARTS AGE IP NODE
kubernetes-bootcamp-2457653786-9qk80 1/1 Running 0 2d 10.244.3.6 vm-rosnthom-00f
springboot-helloworld-2842952983-rw0gc 1/1 Running 0 1d 10.244.3.7 vm-rosnthom-00f
root@vm-vivekse-003:~# kubectl get svc -o wide -n playground
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
sb-hw-svc 10.101.180.19 <nodes> 9000:30847/TCP 5h run=springboot-helloworld
root@vm-vivekse-003:~# kubectl describe svc sb-hw-svc -n playground
Name: sb-hw-svc
Namespace: playground
Labels: <none>
Annotations: <none>
Selector: run=springboot-helloworld
Type: NodePort
IP: 10.101.180.19
Port: <unset> 9000/TCP
NodePort: <unset> 30847/TCP
Endpoints: 10.244.3.7:9000
Session Affinity: None
Events: <none>
root@vm-vivekse-003:~# kubectl get endpoints sb-hw-svc -n playground -o yaml
apiVersion: v1
kind: Endpoints
metadata:
creationTimestamp: 2017-08-09T06:28:06Z
name: sb-hw-svc
namespace: playground
resourceVersion: "588958"
selfLink: /api/v1/namespaces/playground/endpoints/sb-hw-svc
uid: e76d9cc1-7ccb-11e7-bc6a-fa163efaba6b
subsets:
- addresses:
- ip: 10.244.3.7
nodeName: vm-rosnthom-00f
targetRef:
kind: Pod
name: springboot-helloworld-2842952983-rw0gc
namespace: playground
resourceVersion: "473859"
uid: 16d9db68-7c1a-11e7-bc6a-fa163efaba6b
ports:
- port: 9000
protocol: TCP
经过一番修改后,我意识到在这 2 个“故障”节点上,这些服务在这些主机本身内是不可用的。
Node01(工作):
root@vm-vivekse-004:~# curl 127.0.0.1:30847 //<localhost>:<nodeport>
Hello Docker World!!
root@vm-vivekse-004:~# curl 10.101.180.19:9000 //<cluster-ip>:<port>
Hello Docker World!!
root@vm-vivekse-004:~# curl 10.244.3.7:9000 //<pod-ip>:<port>
Hello Docker World!!
Node02(工作):
root@vm-rosnthom-00f:~# curl 127.0.0.1:30847
Hello Docker World!!
root@vm-rosnthom-00f:~# curl 10.101.180.19:9000
Hello Docker World!!
root@vm-rosnthom-00f:~# curl 10.244.3.7:9000
Hello Docker World!!
Node03(不工作):
root@vm-plashkar-006:~# curl 127.0.0.1:30847
curl: (7) Failed to connect to 127.0.0.1 port 30847: Connection timed out
root@vm-plashkar-006:~# curl 10.101.180.19:9000
curl: (7) Failed to connect to 10.101.180.19 port 9000: Connection timed out
root@vm-plashkar-006:~# curl 10.244.3.7:9000
curl: (7) Failed to connect to 10.244.3.7 port 9000: Connection timed out
Node04(不工作):
root@vm-deepejai-00b:/# curl 127.0.0.1:30847
curl: (7) Failed to connect to 127.0.0.1 port 30847: Connection timed out
root@vm-deepejai-00b:/# curl 10.101.180.19:9000
curl: (7) Failed to connect to 10.101.180.19 port 9000: Connection timed out
root@vm-deepejai-00b:/# curl 10.244.3.7:9000
curl: (7) Failed to connect to 10.244.3.7 port 9000: Connection timed out
在所有 4 个从站上尝试了 netstat 和 telnet。这是输出:
Node01(工作主机):
root@vm-vivekse-004:~# netstat -tulpn | grep 30847
tcp6 0 0 :::30847 :::* LISTEN 27808/kube-proxy
root@vm-vivekse-004:~# telnet 127.0.0.1 30847
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Node02(工作主机):
root@vm-rosnthom-00f:~# netstat -tulpn | grep 30847
tcp6 0 0 :::30847 :::* LISTEN 11842/kube-proxy
root@vm-rosnthom-00f:~# telnet 127.0.0.1 30847
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Node03(不工作的主机):
root@vm-plashkar-006:~# netstat -tulpn | grep 30847
tcp6 0 0 :::30847 :::* LISTEN 7791/kube-proxy
root@vm-plashkar-006:~# telnet 127.0.0.1 30847
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection timed out
Node04(不工作的主机):
root@vm-deepejai-00b:/# netstat -tulpn | grep 30847
tcp6 0 0 :::30847 :::* LISTEN 689/kube-proxy
root@vm-deepejai-00b:/# telnet 127.0.0.1 30847
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection timed out
添加信息:
从kubectl get pods 的输出中,我可以看到pod 实际上部署在slave vm-rosnthom-00f 上。我可以从所有 5 个虚拟机中 ping 这个主机,curl vm-rosnthom-00f:30847 也适用于所有虚拟机。
我可以清楚地看到内部集群网络混乱,但我不确定如何解决它!所有从站的iptables -L 都是相同的,甚至所有从站的本地环回 (ifconfig lo) 都已启动并运行。我完全不知道如何解决它!
【问题讨论】:
-
确认一下,所有非docker接口的IP地址是否与docker、pods、services有独立的IP空间?我想看到的命令是
root@vm-deepejai-00b:/# curl THE_IP_OF_vm-vivekse-004:30847,以确保vm-deepejai-00b可以将流量路由到vm-vivekse-004,因为无论如何这就是幕后发生的事情 -
另外,为了清楚起见,您是否检查了
iptables -t nat -L以及iptables -L(我不知道您是否是这个意思) -
@MatthewLDaniel 至于您的第一条评论,curl 有效:
root@vm-deepejai-00b:~# curl 173.36.23.4:30847 <enter> Hello Docker World!!其中 173.36.23.4 是 vm-vivekse-004 的 IP -
@MatthewLDaniel 至于你的第二条评论,当我说
iptables -L因为所有奴隶都是相同的时,我想我有点过火了。实际上,iptables -L对于 Node02(工作节点)和 Node04(非工作节点)[diffchecker.com/JZzyspEL] 是相同的,对于 Node01(工作节点)和 Node03(非工作节点)[diffchecker.com/3X6WkdMR]是相同的> -
另外,
iptables -t nat -L对于 Node02 和 Node04 [diffchecker.com/me6PhHCd]几乎相同,对于 Node01 和 Node03 [diffchecker.com/CusUUMnN] 相同
标签: kubernetes flannel