初始化集群:
kubeadm init --kubernetes-version=1.21.2 --apiserver-advertise-address=10.0.4.11 --pod-network-cidr=10.244.0.0/16
注意:
1、需要用内网ip设置服务器的ip
2、在worker节点执行命令,使它可以访问master节点
iptables -t nat -A OUTPUT -d 10.1.0.2(master节点内网ip) -j DNAT --to-destination 101.34.62.96(master节点公网ip)
如果遇到cni网络问题,如执行journalctl -xe 查到错误如下:
Dec 03 17:00:37 worker01 kubelet[30369]: I1203 17:00:37.215120 30369 cni.go:239] "Unable to update cni config" err="no networks found in /etc/cni/net.d"
Dec 03 17:00:39 worker01 kubelet[30369]: E1203 17:00:39.600812 30369 kubelet.go:2211] "Container runtime network not ready" networkReady="NetworkReady=false
可以通过以下方式解决:
mkdir -p /etc/cni/net.d
cat > /etc/cni/net.d/10-flannel.conflist << EOF
{
"name": "cbr0",
"plugins": [
{
"type": "flannel",
"delegate": {
"hairpinMode": true,
"isDefaultGateway": true
}
},
{
"type": "portmap",
"capabilities": {
"portMappings": true
}
}
]
}
EOF
网友评论