该问题出现在单机版测试环境(k8s v1.20.8版本),使用calico网络插件情况下解决k8s pod通过service网络之间无法互通问题解决方案

1、错误现象

[root@k8s data01]# kubectl logs -f -n kube-system kube-proxy-4p6n4
I1220 05:37:53.770985 1 node.go:172] Successfully retrieved node IP: 192.168.32.235
I1220 05:37:53.771086 1 server_others.go:142] kube-proxy node IP is an IPv4 address (192.168.32.235), assume IPv4 operation
W1220 05:37:53.815116 1 server_others.go:584] Unknown proxy mode "", assuming iptables proxy
I1220 05:37:53.815277 1 server_others.go:185] Using iptables Proxier.
I1220 05:37:53.815683 1 server.go:650] Version: v1.20.8
I1220 05:37:53.816293 1 conntrack.go:52] Setting nf_conntrack_max to 262144

日志报错Unknown proxy mode "", assuming iptables proxy

2、修改kube-proxy的配置文件,添加mode 为ipvs

[root@k8s yaml]# kubectl edit cm kube-proxy -n kube-system
ipvs:
excludeCIDRs: null
minSyncPeriod: 0s
scheduler: ""
strictARP: false
syncPeriod: 0s
tcpFinTimeout: 0s
tcpTimeout: 0s
udpTimeout: 0s
kind: KubeProxyConfiguration
metricsBindAddress: ""
mode: "ipvs" #这里默认为空,填写ipvs保存

3、ipvs模式需要注意的是要添加ip_vs相关模块

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
modprobe -- br_netfilter
EOF

4、添加执行权限

chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4

5、重启proxy插件

[root@k8s yaml]# kubectl get pod -n kube-system | grep kube-proxy |awk '{system("kubectl delete pod "$1" -n kube-system")}'
pod "kube-proxy-4p6n4" deleted
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐