K3s agent所在节点上的pod无法访问集群内外的任何网络

环境信息:
K3s 版本:
k3s version v1.27.4+k3s1 (36645e73)
go version go1.20.6

节点 CPU 架构、操作系统和版本::
Linux prod-node2 3.10.0-1160.49.1.el7.x86_64 #1 SMP Tue Nov 30 15:51:32 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

集群配置:
1 servers, 1 agents

问题描述:
阿里云内网中,agent 节点通过curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -的方式正常加入了集群,没有添加额外的参数选项。之后在该 agent 节点上的pod发现启动失败,进入容器内部,发现无法访问集群内的 service(通过xxx.default.svc.cluster.local或者clusterIP 均不能访问),再尝试访问外网也不行(ping www.baidu.com卡住无任何输出)。但是调度到 server 节点上 pod 访问集群内外网络均是正常的。

阿里云的安全组中开放了必要的端口,感觉上应该和端口无关。

尝试搜索了网上的资源,也许是和 cidr 有关。但是部署时我并未额外设置 cidr 相关的选项,实际 pod 的ip都在10.42.0.0/16网段范围内,service 也都在10.43.0.0/16网段范围内。

复现步骤:

  • 安装 K3s 的命令:
# server
$ curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -
# agent
$ curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -

预期结果:
server和agent均正常安装,可正常调度pod,pod可正常访问集群内部和外部网络。

实际结果:
server和agent均正常安装,可正常调度pod,但agent节点上的pod无法访问集群内其他service,也无法访问公网(域名和IP均不行),server节点上的pod可以正常访问这些网络。

附加上下文/日志:

日志
[root@debug-576f4c844f-x5jzr /]# ping www.baidu.com
^C
[root@debug-576f4c844f-x5jzr /]# cat /etc/resolv.conf 
search default.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.43.0.10
options ndots:5
[root@debug-576f4c844f-x5jzr /]# nslookup etcd.default.svc.cluster.local
^C
[root@debug-576f4c844f-x5jzr /]# telnet 10.43.154.188 2379
Trying 10.43.154.188...
^C

已解决。确实是端口号的原因。我看错了一个安全组,结果就是server端开启了8472,agent端没开启8472。server和agent均开启UDP 8472后解决。

1 个赞