使用Kubeadm安装K8s集群,在安装flannel网络插件后,发现pod: kube-flannel-ds 一直是CrashLoopBackOff

报错内容如下:

log is DEPRECATED and will be removed in a future version. Use logs instead.
I0823 03:28:21.342352       1 main.go:514] Determining IP address of default interface
I0823 03:28:21.343054       1 main.go:527] Using interface with name eth0 and address 172.20.101.105
I0823 03:28:21.343152       1 main.go:544] Defaulting external address to interface address (172.20.101.105)
I0823 03:28:21.540726       1 kube.go:126] Waiting 10m0s for node controller to sync
I0823 03:28:21.540872       1 kube.go:309] Starting kube subnet manager
I0823 03:28:22.550948       1 kube.go:133] Node controller sync successful
I0823 03:28:22.551040       1 main.go:244] Created subnet manager: Kubernetes Subnet Manager - cnvs-kubm-101-105
I0823 03:28:22.551061       1 main.go:247] Installing signal handlers
I0823 03:28:22.551355       1 main.go:386] Found network config - Backend type: vxlan
I0823 03:28:22.551530       1 vxlan.go:120] VXLAN config: VNI=1 Port=0 GBP=false DirectRouting=false
E0823 03:28:22.552149       1 main.go:289] Error registering network: failed to acquire lease: node "cnvs-kubm-101-105" pod cidr not assigned
I0823 03:28:22.639464       1 main.go:366] Stopping shutdownHandler...

[root@cnvs-kubm-101-103 kubeinstall]# kubectl get pod -n kube-system 
NAME                                        READY   STATUS              RESTARTS   AGE
coredns-5c98db65d4-6h976                    0/1     ContainerCreating   0          62m
coredns-5c98db65d4-hgwwd                    0/1     ContainerCreating   0          62m

kube-controller-manager-cnvs-kubm-101-105   1/1     Running             0          57m
kube-flannel-ds-amd64-2hpct                 0/1     CrashLoopBackOff    16         60m
kube-flannel-ds-amd64-6cq6j                 0/1     CrashLoopBackOff    15         54m
kube-flannel-ds-amd64-9bvpb                 0/1     CrashLoopBackOff    15         54m
kube-flannel-ds-amd64-9kv6n                 0/1     CrashLoopBackOff    16         59m
kube-flannel-ds-amd64-dt47n                 0/1     CrashLoopBackOff    15         54m
kube-flannel-ds-amd64-f24jg                 0/1     CrashLoopBackOff    15         58m
kube-flannel-ds-amd64-gf6pn                 0/1     CrashLoopBackOff    15         54m
kube-flannel-ds-amd64-h5zqm                 0/1     CrashLoopBackOff    15         56m
kube-flannel-ds-amd64-jqbxz                 0/1     CrashLoopBackOff    15         54m
kube-flannel-ds-amd64-vw2rr                 0/1     CrashLoopBackOff    15         54m
kube-flannel-ds-amd64-vwwbs                 0/1     CrashLoopBackOff    15         54m

解决办法1:

执行Kubeadm Init的时候,增加 --pod-network-cidr 10.244.0.0/16参数。

注意,安装Flannel时,kubectl create -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml如果yml中的"Network": "10.244.0.0/16"和--pod-network-cidr不一样,就修改成一样的。不然可能会使得Node间Cluster IP不通。

解决办法2:

可以先打印默认集群初始化配置,修改后引导集群:

kubeadm config print init-defaults > kubeadm-init.yaml

修改后内容如下:


apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 172.19.8.111
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  name: node-01
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controlPlaneEndpoint: "172.19.8.250:8443"
controllerManager: {}
dns:
  type: CoreDNS
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
kubernetesVersion: v1.15.0
networking:
  dnsDomain: cluster.local
  serviceSubnet: 10.245.0.0/16   《=== 注意网段
  podSubnet: "10.244.0.0/16"     《=== 注意网段
scheduler: {}

master上面都配置Nginx反向代理 API Server;
172.20.101.253 是master节点的vip;
Nginx 代理端口为 16443 端口;
API Server使用 6443 端口;

使用config指定初始化集群。


### 测试运行
kubeadm init \
--config=/etc/kubeinstall/kubeadm-init.yaml \
--upload-certs \
--dry-run 

### 下载软件包 (按需使用)
kubeadm config images pull