我一直在玩minikube,经过一系列操作后,kubectl get pod -w的输出如下:


nginx   1/1   Running   2     10m
nginx   1/1   Running   3     10m
nginx   0/1   Completed   2     10m
nginx   0/1   CrashLoopBackOff   2     11m
nginx   1/1   Running   3     11m
nginx   1/1   Running   3     12m

我不明白第3行和第4行显示的计数。重新启动计数到底传达了什么?

最佳答案

关于CrashLoopBackOff状态:
CrashloopBackOff意味着您有一个 pods 开始,崩溃,再次开始,然后再次崩溃。

由kubelet重新启动的失败容器将以指数退避延迟(10s,20s,40s…)重新启动,上限为五分钟,并在成功执行十分钟后重置。
CrashLoopBackOff事件的发生有不同的原因,大多数情况与以下原因有关:
-容器中的应用程序不断崩溃
- pods 或容器的某些参数配置不正确
-部署期间发生错误

每当您遇到CrashLoopBackOff时,请执行kubectl describe进行调查:
kubectl describe pod POD_NAME --namespace NAMESPACE_NAME

user@minikube:~$ kubectl describe pod ubuntu-5d4bb4fd84-8gl67 --namespace default
Name:         ubuntu-5d4bb4fd84-8gl67
Namespace:    default
Priority:     0
Node:         minikube/192.168.39.216
Start Time:   Thu, 09 Jan 2020 09:51:03 +0000
Labels:       app=ubuntu
              pod-template-hash=5d4bb4fd84
Status:       Running
Controlled By:  ReplicaSet/ubuntu-5d4bb4fd84
Containers:
  ubuntu:
    Container ID:   docker://c4c0295e1e050b5e395fc7b368a8170f863159879821dd2562bc2938d17fc6fc
    Image:          ubuntu
    Image ID:       docker-pullable://ubuntu@sha256:250cc6f3f3ffc5cdaa9d8f4946ac79821aafb4d3afc93928f0de9336eba21aa4
    State:          Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Thu, 09 Jan 2020 09:54:37 +0000
      Finished:     Thu, 09 Jan 2020 09:54:37 +0000
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Thu, 09 Jan 2020 09:53:05 +0000
      Finished:     Thu, 09 Jan 2020 09:53:05 +0000
    Ready:          False
    Restart Count:  5
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-xxxst (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-xxxst:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-xxxst
    Optional:    false
QoS Class:       BestEffort
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                    From               Message
  ----     ------     ----                   ----               -------
  Normal   Scheduled  7m16s                  default-scheduler  Successfully assigned default/ubuntu-5d4bb4fd84-8gl67 to minikube
  Normal   Created    5m59s (x4 over 6m52s)  kubelet, minikube  Created container ubuntu
  Normal   Started    5m58s (x4 over 6m52s)  kubelet, minikube  Started container ubuntu
  Normal   Pulling    5m17s (x5 over 7m5s)   kubelet, minikube  Pulling image "ubuntu"
  Normal   Pulled     5m15s (x5 over 6m52s)  kubelet, minikube  Successfully pulled image "ubuntu"
  Warning  BackOff    2m2s (x24 over 6m43s)  kubelet, minikube  Back-off restarting failed container
Events部分将为您提供详细的说明。

关于kubernetes - 运行kubectl get pod -w时,kubernetes pod重启计数显示不一致的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59658516/

10-16 12:09