Kubeasz Install Troubleshooting

前言

k8s的安装方式有很多,kubeasz,kubespray,kubeadm,手动安装等等,今天尝试了kubeasz,遇到些问题,在此记录下.

上下文

  • 安装k8s 1.12
  • vagrant起了四台vm
  • kube-proxy模式选择ipvs
  • 网络选择flannel

安装过程

按照kubeasz文档中“多主多节点”方式配置安装,不在细说!, 本文档下kubeasz目录有相关配置文件。

Troubleshooting过程

coredns和dashboard的pod状态不是“running”

经查发现,这两货报错如下:

coredns

1
reflector.go:205] github.com/coredns/coredns/plugin/kubernetes/controller.go:348: Failed to list *v1.Service: Get https://10.68.0.1:443/api/v1/services?limit=500&resourceVersion=0: dial tcp 10.68.0.1:443: connect: connection refused

dashboard

1
Error while initializing connection to Kubernetes apiserver. This most likely means that the cluster is misconfigured (e.g., it has invalid apiserver certificates or service account's configuration) or the --apiserver-host param points to a server that does not exist. Reason: Get https://10.68.0.1:443/version: dial tcp 10.68.0.1:443: getsockopt: connection refused

简单说就是连不上kube-apiserver, “10.68.0.1”是kube-apiserver service ip , 我采用的kube-proxy模式是ipvs,用ipvsadm可见。

从图上看,ipvs将对10.68.0.1的请求路由到”10.0.2.15”上,这是不对的,

在kube-apiserver的配置里,是有配置“–bind-address=172.16.20.11”,应该是路由到bind-address的,但为什么不是呢?

经查有一个参数“–advertise-address”,其解释如下

1
2
--advertise-address ip                 
The IP address on which to advertise the apiserver to members of the cluster. This address must be reachable by the rest of the cluster. If blank, the --bind-address will be used. If --bind-address is unspecified, the host's default interface will be used.

说的很明白,即使没这个参数,bind-address会起一样的作用,不管怎样,加上去试试,加上“–advertise-address=172.16.20.11”重启kube-apiserver,哈哈,效果如下

此时,coredns与dashboard的pod已进入”running”状态。

不同node的pod相互不能ping通

(1) 查路由表,正常的路由表如下

(2) 有个节点的路由表不正常,如下

重启该节点,路由表ok!,但不同node的pod还是相互不能ping通

(3) 想想数据包是怎样从这个node的pod到另一个node的pod上的


注:现在用cni0网桥代替docker0了

从图上可知,数据最终是要通过flannel发送出去的,对于有多个网卡的vm,flannel需要知道从哪个接口发送数据出去!,实际情况确实如此。

1
...flanneld 使用系统缺省路由所在的接口与其它节点通信,对于有多个网络接口(如内网和公网)的节点,可以用 -iface 参数指定通信接口,如上面的 eth0 接口;...

导出flannel daemonset yaml文件,基于它添加“–iface”参数。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
kubectl get ds kube-flannel-ds -o yaml -n kube-system > flannel-ds.yaml

修改如下,

.....
containers:
- args:
- --ip-masq
- --kube-subnet-mgr
- --iface=enp0s8 # 添加此行!
command:
- /opt/bin/flanneld
.....

delete该ds,而后再apply。

OK ,问题解决!

参考

(1) https://github.com/kubernetes/kubernetes/issues/51881

(2) https://www.centos.bz/2017/06/k8s-flannel-network/