1、现象
[root@master ~]# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 121d
mysql ClusterIP 10.108.129.221 <none> 3306/TCP 20h
[root@master ~]# ping 10.108.129.221
PING 10.108.129.221 (10.108.129.221) 56(84) bytes of data.
2、日志分析
[root@master mysql]# kubectl get pods -n kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
coredns-58cc8c89f4-57rf2 1/1 Running 7 121d 10.244.0.21 master <none> <none>
coredns-58cc8c89f4-g2m5z 1/1 Running 7 121d 10.244.0.22 master <none> <none>
etcd-master 1/1 Running 7 121d 192.168.10. 8 master <none> <none>
kube-apiserver-master 1/1 Running 7 121d 192.168.10. 8 master <none> <none>
kube-controller-manager-master 1/1 Running 10 121d 192.168.10. 8 master <none> <none>
kube-flannel-ds-amd64-vzncs 1/1 Running 8 117d 192.168.10. 8 master <none> <none>
kube-flannel-ds-amd64-xxcx9 1/1 Running 23 117d 192.168.10. 9 node1 <none> <none>
kube-proxy-hqhcw 1/1 Running 9 121d 192.168.10. 9 node1 <none> <none>
kube-proxy-qbm7c 1/1 Running 7 121d 192.168.10. 8 master <none> <none>
kube-scheduler-master 1/1 Running 10 121d 192.168.10. 8 master <none> <none>
[root@master mysql]# kubectl logs -n kube-system kube-proxy-qbm7c
W0925 03:11:36.888283 1 proxier.go:597] Failed to load kernel module ip_vs with modprobe. You can ignore this message when kube-proxy is running inside co ntainer without mounting /lib/modules
W0925 03:11:36.891813 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
W0925 03:11:36.892924 1 proxier.go:597] Failed to load kernel module ip_vs _wrr with modprobe. You can ignore this message when kube-proxy is running insid e container without mounting /lib/modules
W0925 03:11:36.895151 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
W0925 03:11:36.903640 1 server_others.go:329] Flag proxy-mode="" unknown, assuming iptables proxy
I0925 03:11:36.920099 1 node.go:135] Successfully retrieved node IP: 192.1 68.10.8
3、添加IPV4模块
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
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
4、修改kupe-proxy的模式
[root@master modules]# kubectl edit cm kube-proxy -n kube-system

5、重启kupe-proxy
[root@master modules]# kubectl get pod -n kube-system | grep kube-proxy |awk '{system("kubectl delete pod "$1" -n kube-system")}'
6、查看日志
[root@master modules]# kubectl get pods -n kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
coredns-58cc8c89f4-57rf2 1/1 Running 7 121d 10.244.0.21 master <none> <none>
coredns-58cc8c89f4-g2m5z 1/1 Running 7 121d 10.244.0.22 master <none> <none>
etcd-master 1/1 Running 7 121d 192.168.10.8 master <none> <none>
kube-apiserver-master 1/1 Running 7 121d 192.168.10.8 master <none> <none>
kube-controller-manager-master 1/1 Running 10 121d 192.168.10.8 master <none> <none>
kube-flannel-ds-amd64-vzncs 1/1 Running 8 117d 192.168.10.8 master <none> <none>
kube-flannel-ds-amd64-xxcx9 1/1 Running 23 117d 192.168.10.9 node1 <none> <none>
kube-proxy-675fs 1/1 Running 0 20s 192.168.10.8 master <none> <none>
kube-proxy-pd7xx 1/1 Running 0 31s 192.168.10.9 node1 <none> <none>
kube-scheduler-master 1/1 Running 10 121d 192.168.10.8 master <none> <none>
[root@master modules]# kubectl logs -n kube-system kube-proxy-675fs
I0925 04:42:45.491108 1 node.go:135] Successfully retrieved node IP: 192.168.10.8
I0925 04:42:45.491211 1 server_others.go:176] Using ipvs Proxier.
W0925 04:42:45.491527 1 proxier.go:420] IPVS scheduler not specified, use rr by default
I0925 04:42:45.491963 1 server.go:529] Version: v1.16.0
I0925 04:42:45.554910 1 conntrack.go:52] Setting nf_conntrack_max to 131072
I0925 04:42:45.555597 1 config.go:313] Starting service config controller
I0925 04:42:45.555668 1 shared_informer.go:197] Waiting for caches to sync for service config
I0925 04:42:45.555773 1 config.go:131] Starting endpoints config controller
I0925 04:42:45.555826 1 shared_informer.go:197] Waiting for caches to sync for endpoints config
I0925 04:42:45.656347 1 shared_informer.go:204] Caches are synced for service config
I0925 04:42:45.656533 1 shared_informer.go:204] Caches are synced for endpoints config
7、测试
[root@master modules]# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 121d
mysql ClusterIP 10.108.129.221 <none> 3306/TCP 18h
[root@master modules]# ping 10.108.129.221
PING 10.108.129.221 (10.108.129.221) 56(84) bytes of data.
64 bytes from 10.108.129.221: icmp_seq=1 ttl=64 time=0.102 ms
64 bytes from 10.108.129.221: icmp_seq=2 ttl=64 time=0.054 ms