1.由于容器的网络暂时还没有,coredns无法分配的ip会处于pending状态,这里需要手动部署flannel插件
代码语言:javascript复制[root@k8s-01 ~]# kubectl -n kube-system get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
coredns-78c7b4d59d-c4dcl 0/1 Pending 0 45m
coredns-78c7b4d59d-d6rrv 0/1 Pending 0 45m
etcd-k8s-01 1/1 Running 0 46m 192.168.31.100 k8s-01
etcd-k8s-02 1/1 Running 0 28m 192.168.31.101 k8s-02
etcd-k8s-03 1/1 Running 0 27m 192.168.31.102 k8s-03
kube-apiserver-k8s-01 1/1 Running 0 46m 192.168.31.100 k8s-01
kube-apiserver-k8s-02 1/1 Running 0 28m 192.168.31.101 k8s-02
kube-apiserver-k8s-03 1/1 Running 0 27m 192.168.31.102 k8s-03
kube-controller-manager-k8s-01 1/1 Running 1 46m 192.168.31.100 k8s-01
kube-controller-manager-k8s-02 1/1 Running 0 28m 192.168.31.101 k8s-02
kube-controller-manager-k8s-03 1/1 Running 0 27m 192.168.31.102 k8s-03
kube-proxy-7rlb4 1/1 Running 0 27m 192.168.31.102 k8s-03
kube-proxy-c8kbl 1/1 Running 0 45m 192.168.31.100 k8s-01
kube-proxy-f87b8 1/1 Running 0 28m 192.168.31.101 k8s-02
kube-proxy-pcx6p 1/1 Running 1 2m59s 192.168.31.104 k8s-05
kube-proxy-zscwf 1/1 Running 1 3m4s 192.168.31.103 k8s-04
kube-scheduler-k8s-01 1/1 Running 1 46m 192.168.31.100 k8s-01
kube-scheduler-k8s-02 1/1 Running 0 28m 192.168.31.101 k8s-02
kube-scheduler-k8s-03 1/1 Running 0 27m 192.168.31.102 k8s-03
2.安装flannel
代码语言:javascript复制#手动打patch,后续扩的node也记得打下
nodes=`kubectl get node --no-headers | awk '{print $1}'`
for node in $nodes;do
cidr=`kubectl get node "$node" -o jsonpath='{.spec.podCIDRs[0]}'`
[ -z "$(kubectl get node $node -o jsonpath='{.spec.podCIDR}')" ] && {
kubectl patch node "$node" -p '{"spec":{"podCIDR":"'"$cidr"'"}}'
}
done
wget http://down.i4t.com/k8s1.18/kube-flannel.yml
kubectl apply -f kube-flannel.yml
3.flannel如果存在多网卡,需要在kube-flannel.yml中指定网卡
代码语言:javascript复制 containers:
- name: kube-flannel
image: quay.io/coreos/flannel:v0.12.0-amd64
command:
- /opt/bin/flanneld
args:
- --ip-masq
- --kube-subnet-mgr
- --iface=eth0 # 如果是多网卡的话,指定内网网卡的名称
温馨提示: 在kubeadm.yaml文件中设置了podSubnet网段,同时在flannel中网段也要设置相同的。 (我这里默认就是相同的配置)