1.查看kube-proxy默认的工作模式
[root@master231 pod]# kubectl -n kube-system logs -f kube-proxy-249qg
I0619 00:38:43.415748 1 node.go:163] Successfully retrieved node IP: 10.0.0.232
I0619 00:38:43.416120 1 server_others.go:138] "Detected node IP" address="10.0.0.232"
I0619 00:38:43.416172 1 server_others.go:572] "Unknown proxy mode, assuming iptables proxy" proxyMode=""
I0619 00:38:43.565784 1 server_others.go:206] "Using iptables Proxier"
2.修改默认的工作模式
[root@master231 pod]# kubectl -n kube-system edit cm kube-proxy
configmap/kube-proxy edited
[root@master231 pod]#
[root@master231 pod]# kubectl -n kube-system get cm kube-proxy -o yaml | grep mode
mode: "ipvs"
3.所有节点安装ipvs相关模块管理工具
3.1 所有worker节点安装ipvs相关组件
yum -y install conntrack-tools ipvsadm.x86_64
3.2 编写加载ipvs的配置文件
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
3.3 加载ipvs相关模块并查看
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4
4.重启Pod让其cm的配置生效
[aster231 pod]# kubectl -n kube-system get pods| grep kube-proxy
kube-proxy-249qg 1/1 Running 2 (3d11h ago) 5d19h
kube-proxy-ch2n6 1/1 Running 2 (3d11h ago) 5d19h
kube-proxy-vvt4v 1/1 Running 2 (3d11h ago) 5d19h
[root@master231 pod]#
[root@master231 pod]# kubectl -n kube-system delete pods `kubectl -n kube-system get pods| grep kube-proxy| awk '{print $1}'`
pod "kube-proxy-249qg" deleted
pod "kube-proxy-ch2n6" deleted
pod "kube-proxy-vvt4v" deleted
[root@master231 pod]#
[root@master231 pod]# kubectl -n kube-system get pods| grep kube-proxy
kube-proxy-9d2r6 1/1 Running 0 4s
kube-proxy-js28w 1/1 Running 0 4s
kube-proxy-w9bh4 1/1 Running 0 4s
[root@master231 pod]#
[root@master231 pod]# root@m
5.验证是否生效
[root@master231 pod]# kubectl -n kube-system get pods| grep kube-proxy
kube-proxy-9d2r6 1/1 Running 0 4s
kube-proxy-js28w 1/1 Running 0 4s
kube-proxy-w9bh4 1/1 Running 0 4s
[root@master231 pod]#
[root@master231 pod]#
[root@master231 pod]# kubectl -n kube-system logs -f kube-proxy-9d2r6
I0620 02:51:25.342319 1 node.go:163] Successfully retrieved node IP: 10.0.0.231
I0620 02:51:25.342434 1 server_others.go:138] "Detected node IP" address="10.0.0.231"
I0620 02:51:25.366439 1 server_others.go:269] "Using ipvs Proxier"
6.查看svc的映射基于ipvs
[root@master231 pod]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 20h
myweb ClusterIP 10.200.100.100 <none> 8888/TCP 18h
myweb-nodeport NodePort 10.200.15.152 <none> 8888:30080/TCP 107m
[root@master231 pod]#
[root@master231 pod]#
[root@master231 pod]# ipvsadm -ln | grep 10.200.100.100 -A 3
TCP 10.200.100.100:8888 rr
-> 10.100.1.78:80 Masq 1 0 0
-> 10.100.1.79:80 Masq 1 0 0
-> 10.100.2.97:80 Masq 1 0 0
[root@master231 pod]#
[root@master231 pod]#
[root@master231 pod]# kubectl describe svc myweb
Name: myweb
Namespace: default
Labels: <none>
Annotations: <none>
Selector: apps=web
Type: ClusterIP
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.200.100.100
IPs: 10.200.100.100
Port: <unset> 8888/TCP
TargetPort: 80/TCP
Endpoints: 10.100.1.78:80,10.100.1.79:80,10.100.2.97:80
Session Affinity: None
Events: <none>
[root@master231 pod]#