kubernetes集群环境搭建后pod status出现ContainerCreating
1.背景
运行kubectl get all
出现pod status为ContainerCreating
$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/mysql-deployment-6ccf56667c-9b2gg 0/1 ContainerCreating 0 127m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 160m
service/mysql NodePort 10.101.39.106 <none> 3306:30007/TCP 130m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/mysql-deployment 0/1 1 0 130m
NAME DESIRED CURRENT READY AGE
replicaset.apps/mysql-deployment-6ccf56667c 1 1 0 127m
2.分析过程
使用kubectl describe pod < podname >
查看pod的情景kubectl describe pod mysql-deployment-6ccf56667c-9b2gg
$ kubectl describe pod mysql-deployment-6ccf56667c-9b2gg
Name: mysql-deployment-6ccf56667c-9b2gg
Namespace: default
Priority: 0
Node: kmaster1/192.168.0.165
Start Time: Fri, 28 Oct 2022 18:07:49 -0400
Labels: app=mysql
pod-template-hash=6ccf56667c
Annotations: <none>
Status: Pending
IP:
IPs: <none>
Controlled By: ReplicaSet/mysql-deployment-6ccf56667c
Containers:
mysql:
Container ID:
Image: mysql:latest
Image ID:
Port: 3306/TCP
Host Port: 0/TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Environment:
MYSQL_ROOT_PASSWORD: <set to the key 'password' in secret 'mysql-root-pass'> Optional: false
MYSQL_DATABASE: <set to the key 'database' in secret 'mysql-db-url'> Optional: false
MYSQL_USER: <set to the key 'username' in secret 'mysql-user-pass'> Optional: false
MYSQL_PASSWORD: <set to the key 'password' in secret 'mysql-user-pass'> Optional: false
Mounts:
/var/lib/mysql from mysql-pv (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-hjf5p (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
mysql-pv:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: mysql-pv-claim
ReadOnly: false
kube-api-access-hjf5p:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SandboxChanged 27m (x1921 over 147m) kubelet Pod sandbox changed, it will be killed and re-created.
Warning FailedCreatePodSandBox 2m38s (x2296 over 147m) kubelet (combined from similar events): Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "f313bae848e45c78b7891244005cbef658cc3004008b3993de9e7a716447bf9d" network for pod "mysql-deployment-6ccf56667c-9b2gg": networkPlugin cni failed to set up pod "mysql-deployment-6ccf56667c-9b2gg_default" network: open /run/flannel/subnet.env: no such file or directory
最后可以看到错误原因是open /run/flannel/subnet.env: no such file or directory
3.解决方案
执行
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
命令在
/run/flannel/subnet.env
中添加FLANNEL_NETWORK=10.244.0.0/16 FLANNEL_SUBNET=10.244.0.1/24 FLANNEL_MTU=1450 FLANNEL_IPMASQ=true
执行下面的命令:
systemctl stop kubelet systemctl stop docker iptables --flush iptables -tnat --flush systemctl start kubelet systemctl start docker
本作品采用《CC 协议》,转载必须注明作者和本文链接