k8s在pod内无法ping通servicename和ClusterIP以及API-Server

1,240 阅读1分钟

今天发现一个问题,就是如果集群使用的是 iptables 模式,则 pod 内是无法 ping 通 API-Server 或者其他的 servce-name 的,使用 nslookup 域名解析也解析不出来,排查一通才发现原来是必须要使用 ipvs 模式才能 ping 通

检查 kube-proxy 使用的是 IPVS 还是 iptables 模式:

方式一: curl -v localhost:10249/proxyMode

➜  ~ curl localhost:10249/proxyMode
iptables%    这就代表iptables模式

查看 iptables 链使用命令 iptables-save

方式二:直接查看kube-proxy的日志

➜  ~ k logs kube-proxy-q4xtg -n kube-system
I1022 11:57:33.414580       1 node.go:163] Successfully retrieved node IP: 10.37.18.97
I1022 11:57:33.414717       1 server_others.go:138] "Detected node IP" address="10.37.18.97"
I1022 11:57:33.449471       1 server_others.go:269]  "Using ipvs Proxier" 
I1022 11:57:33.449510       1 server_others.go:271]  "Creating dualStackProxier for ipvs" 
I1022 11:57:33.449528       1 server_others.go:491] "Detect-local-mode set to ClusterCIDR, but no IPv6 cluster CIDR defined, , defaulting to no-op detect-local for IPv6"
I1022 11:57:33.450391       1 proxier.go:436] "IPVS scheduler not specified, use rr by default"
I1022 11:57:33.450673       1 proxier.go:436] "IPVS scheduler not specified, use rr by default"
I1022 11:57:33.450715       1 ipset.go:113] "Ipset name truncated" ipSetName="KUBE-6-LOAD-BALANCER-SOURCE-CIDR" truncatedName="KUBE-6-LOAD-BALANCER-SOURCE-CID"
I1022 11:57:33.450739       1 ipset.go:113] "Ipset name truncated" ipSetName="KUBE-6-NODE-PORT-LOCAL-SCTP-HASH" truncatedName="KUBE-6-NODE-PORT-LOCAL-SCTP-HAS"
I1022 11:57:33.451063       1 server.go:656] "Version info" version="v1.23.8"

可以看到有 Using ipvs Proxier

查看 ipvs 使用使用命令 ipvsadm -ln

参考文章

k8s在pod内无法ping通servicename和ClusterIP_mb63e0bfee4d9bf的技术博客_51CTO博客