k8s集群开启ipvs模式

张 佃栋 kubernetes, 虚拟化 2020-10-09 51 次浏览 , , 没有评论

1.2kube-proxy开启ipvs的前置条件
由于ipvs已经加入到了内核的主干,所以为kube-proxy开启ipvs的前提需要加载以下的内核模块:
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack_ipv4

在所有的Kubernetes节点node1和node2上执行以下脚本:
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe — ip_vs
modprobe — ip_vs_rr
modprobe — ip_vs_wrr
modprobe — ip_vs_sh
modprobe — nf_conntrack_ipv4
EOF
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4
脚本创建了的/etc/sysconfig/modules/ipvs.modules文件,保证在节点重启后能自动加载所需模块。 使用lsmod | grep -e ip_vs -e nf_conntrack_ipv4命令查看是否已经正确加载所需的内核模块。
在所有节点上安装ipset软件包
yum install ipset -y
为了方便查看ipvs规则我们要安装ipvsadm(可选)
yum install ipvsadm -y

#修改ConfigMap的kube-system/kube-proxy中的config.conf,把 mode: “” 改为mode: “ipvs” 保存退出即可
[root@k8smaster centos]# kubectl edit cm kube-proxy -n kube-system
configmap/kube-proxy edited
###删除之前的proxy pod
[root@k8smaster centos]# kubectl get pod -n kube-system |grep kube-proxy |awk ‘{system(“kubectl delete pod “$1″ -n kube-system”)}’
pod “kube-proxy-2m5jh” deleted
pod “kube-proxy-nfzfl” deleted
pod “kube-proxy-shxdt” deleted
#查看proxy运行状态
[root@k8smaster centos]# kubectl get pod -n kube-system | grep kube-proxy
kube-proxy-54qnw 1/1 Running 0 24s
kube-proxy-bzssq 1/1 Running 0 14s
kube-proxy-cvlcm 1/1 Running 0 37s
#查看日志,如果有 `Using ipvs Proxier.` 说明kube-proxy的ipvs 开启成功!
[root@k8smaster centos]# kubectl logs kube-proxy-54qnw -n kube-system

[root@master01 ~]# kubectl logs kube-proxy-47dhk -n kube-system
I0922 01:48:08.901038 1 node.go:136] Successfully retrieved node IP: 10.100.90.4
I0922 01:48:08.901117 1 server_others.go:259] Using ipvs Proxier.
W0922 01:48:08.956230 1 proxier.go:429] IPVS scheduler not specified, use rr by default
I0922 01:48:08.956660 1 server.go:583] Version: v1.18.8
I0922 01:48:08.960068 1 conntrack.go:52] Setting nf_conntrack_max to 1310720
I0922 01:48:08.961251 1 config.go:315] Starting service config controller
I0922 01:48:08.961298 1 shared_informer.go:223] Waiting for caches to sync for service config
I0922 01:48:08.961422 1 config.go:133] Starting endpoints config controller
I0922 01:48:08.961493 1 shared_informer.go:223] Waiting for caches to sync for endpoints config
I0922 01:48:09.061743 1 shared_informer.go:230] Caches are synced for service config
I0922 01:48:09.061896 1 shared_informer.go:230] Caches are synced for endpoints config
[root@master01 ~]#

本文出自张佃栋de博客,转载时请注明出处及相应链接。

本文永久链接: https://zhangdd.com/1031.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注

回顶部