环境
-
Kubernetes version:
v1.16.2 -
OS:
NAME=“CentOS Linux”
VERSION=“7 (Core)”
ID=“centos”
ID_LIKE=“rhel fedora”
VERSION_ID=“7”
PRETTY_NAME=“CentOS Linux 7 (Core)”
ANSI_COLOR=“0;31”
CPE_NAME=“cpe:/o:centos:centos:7”
HOME_URL=“https://www.centos.org/”
BUG_REPORT_URL=“https://bugs.centos.org/”CENTOS_MANTISBT_PROJECT=“CentOS-7”
CENTOS_MANTISBT_PROJECT_VERSION=“7”
REDHAT_SUPPORT_PRODUCT=“centos”
REDHAT_SUPPORT_PRODUCT_VERSION=“7” -
部署方式
kubeadm
操作以及遇到的问题
kubeadm正常的部署完成之后,由于我没有设置proxy的mode, 所以kube-proxy会在启动的时候自行的去判断到底使用哪种模式,kube-proxy支持的模式有三种
- user-space,
- iptabels,
- ipvs
每种类型的详细介绍,请参考官网kube-proxy mode,所以在启动的时候默认是iptabels模式,集群正常起来后,我想更改为ipvs模式,所以我只需要更改对于的启动参数:proxy-mode=ipvs即可,但是在更改完成之后,kube-proxy daemonset新建的pod还是使用iptables模式,其中错误种有错误信息提示找不到:ip_vs, ip_vs_rr, ip_vs_wrr, ip_vs_sh模块,但是我主机上是已经正常的安装了对应得ipvs需要的这几个模块(在主机上未使用modprobe加载对应ipvs模块),并且通过挂在宿主机的/lib/modules 到容器中的/lib/modules。而且在kube-proxy的代码,在判断能否使用ipvs模块的时候,明确的调用了modprobe – [ip_vs, ip_vs_rr, ip_vs_wrr, ip_vs_sh]去加载了,但是始终会报错,找不到对应的ipvs模块。错误信息如下
1121 10:21:08.420967 1 proxier.go:597] Failed to load kernel module ip_vs_rr with modprobe. You can ignore this message when kube-proxy is running inside container without mounting /lib/modules, err: exit status 1,out:modprobe: ERROR: could not insert 'ip_vs_rr': Exec format error
W1121 10:21:08.421825 1 proxier.go:597] Failed to load kernel module ip_vs_wrr with modprobe. You can ignore this message when kube-proxy is running inside container without mounting /lib/modules, err: exit status 1,out:modprobe: ERROR: could not insert 'ip_vs_wrr': Exec format error
W1121 10:21:08.422624 1 proxier.go:597] Failed to load kernel module ip_vs_sh with modprobe. You can ignore this message when kube-proxy is running inside container without mounting /lib/modules, err: exit status 1,out:modprobe: ERROR: could not insert 'ip_vs_sh': Exec format error
E1121 10:21:08.423949 1 server_others.go:339] can't determine whether to use ipvs proxy, error: IPVS proxier will not be used because the following required kernel modules are not loaded: [ip_vs ip_vs_rr ip_vs_wrr ip_vs_sh]
后面的详细错误error是我自己编译代码种加的信息,原来的方法是调用cmd.run,只返回错误,只有exit status 1,没有详细的错误信息,所以我更改了他的方法,调用cmd.CompileOutPut方法。获取详细的错误信息。看了相关部分的proxy的代码逻辑,逻辑是没有任何问题的,检查ipvs模块的顺序如下:
- /lib/modules/$(uname -a)/modules.builtin
- modprobe – [ip_vs, ip_vs_rr, ip_vs_wrr, ip_vs_sh]
- /proc/modules
最后,我手动的在主机上去执行modprobe – [ip_vs, ip_vs_rr, ip_vs_wrr, ip_vs_sh] 然后删除掉就的kube-proxy pod,然后查看日志,正常使用ipvs模式。
总结:
当使用容器部署kube-proxy的时候,使用ipvs模式,需要在宿主机上手动的去吧所有的ipvs模块都挂载到内核种去。否则kube-proxy在启动的时候,如果配置为ipvs模式,在去检查挂载ipvs以及其依赖模的时候不会成功,从而导致使用ipvs模式失败,转而使用iptabels模式。