kubernetes的pod一直处于ContainerCreating状态

解决思路:

[root@test ~]# kubectl describe deployment web
Name:                   web
Namespace:              default
CreationTimestamp:      Thu, 11 Mar 2021 05:01:09 -0500
Labels:                 app=web
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=web
Replicas:               1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=web
  Containers:
   nginx:
    Image:        nginx
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   web-96d5df5c8 (1/1 replicas created)
Events:          <none>

查看events

[root@test ~]# kubectl get events
LAST SEEN   TYPE      REASON                   OBJECT                    MESSAGE
9s          Normal    SandboxChanged           pod/web-96d5df5c8-l2ngm   Pod sandbox changed, it will be killed and re-created.
5m9s        Warning   FailedCreatePodSandBox   pod/web-96d5df5c8-l2ngm   (combined from similar events): Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "c90e419f191fe929e43090240e6cef89b0aee252bc2c410b203ed7eb2947b184" network for pod "web-96d5df5c8-l2ngm": networkPlugin cni failed to set up pod "web-96d5df5c8-l2ngm_default" network: failed to set bridge addr: "cni0" already has an IP address different from 10.244.1.1/24

报错内容为:

Warning   FailedCreatePodSandBox   pod/web-96d5df5c8-l2ngm   
(combined from similar events): Failed to create pod sandbox: rpc error: code = Unknown
desc = failed to set up sandbox container "c90e419f191fe929e43090240e6cef89b0aee252bc2c410b203ed7eb2947b184"
network for pod "web-96d5df5c8-l2ngm": networkPlugin cni failed to set up pod "web-96d5df5c8-l2ngm_default"
network: failed to set bridge addr: "cni0" already has an IP address different from 10.244.1.1/24

  从上面的图中我们可以看到flannel.1的IP为10.244.1.0,然后我们又使用cat /run/flannel/subnet.env,该文件内容如下:

  解决办法:

方法1:将cni0的IP段修改为10.244.0.1

方法2:将这个错误的网卡删掉,之后会自动创建,操作如下:

sudo ifconfig cni0 down    
sudo ip link delete cni0

查看结果:

 参考:https://blog.csdn.net/Wuli_SmBug/article/details/104712653

posted @ 2021-03-11 20:43  fat_girl_spring  阅读(556)  评论(0编辑  收藏  举报