记一次K8S安装后的网络问题
环境信息
Client Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.2", GitCommit:"5835544ca568b757a8ecae5c153f317e5736700e", GitTreeState:"clean", BuildDate:"2022-09-21T14:33:49Z", GoVersion:"go1.19.1", Compiler:"gc", Platform:"darwin/arm64"}
runtime版本
[root@master ~]# ctr version
Client:
Version: v1.6.11
Revision: d986545181c905378b0f90faa9c5eae3cbfa3755
Go version: go1.18.8
Server:
Version: v1.6.11
Revision: d986545181c905378b0f90faa9c5eae3cbfa3755
UUID: 03a38ed9-7388-4eab-bbcf-a97e6665e14c
操作系统
Centos 7.9
内核:3.10.0-1062.el7.x86_64
集群初始化后问题
配置pod子网为10.244.0.0/16网段
networking:
dnsDomain: cluster.local
serviceSubnet: 10.96.0.0/12
podSubnet: 10.244.0.0/16
- 问题:初始化完成后创建pod的IP并非指定的10.244.0.0/16网段,而是10.88.0.0/网段
问题截图:
- 查看
/etc/cni/net.d/10-containerd-net.conflist
文件发现其中配置的10.88.0.0/16地址
{
"cniVersion": "1.0.0",
"name": "containerd-net",
"plugins": [
{
"type": "bridge",
"bridge": "cni0",
"isGateway": true,
"ipMasq": true,
"promiscMode": true,
"ipam": {
"type": "host-local",
"ranges": [
[{
"subnet": "10.88.0.0/16"
}],
[{
"subnet": "2001:4860:4860::/64"
}]
],
"routes": [
{ "dst": "0.0.0.0/0" },
{ "dst": "::/0" }
]
}
},
{
"type": "portmap",
"capabilities": {"portMappings": true}
}
]
}
但是,10.88.0.0/16这个cni网络插件类型是bridge,网桥名称是cni0
但是使用 bridge 网络的容器无法跨多个宿主机进行通信,跨主机通信需要借助其他的 cni 插件,比如上面我们安装的Flannel,或者 Calico 等等,由于我们这里有两个 cni 配置,所以我们需要将10-containerd-net.conflist
文件删除,因为如果这个目录中有多个 cni 配置文件,kubelet 将会使用按文件名的字典顺序排列的第一个作为配置文件,所以前面默认选择使用的是containerd-net
这个插件
# 备份
mv /etc/cni/net.d/10-containerd-net.conflist /etc/cni/net.d/10-containerd-net.conflist.bak
# 删除cni0,并重新启动containerd、kubelet
ifconfig cni0 down && ip link delete cni0
systemctl daemon-reload➜ ~ systemctl restart containerd kubelet
# 重建coredns
kubectl delete -f -n kube-system coredns-565d847f94-9vw7s coredns-565d847f94-l4gsf
标签:cni0,16,containerd,网络,问题,0.0,net,cni
From: https://www.cnblogs.com/wenkuna/p/16978050.html