【问题标题】:CrashLoopBackOff error when creating k38 replica set创建 k38 副本集时出现 CrashLoopBackOff 错误
【发布时间】:2021-12-18 09:25:52
【问题描述】:

我在 Kubernetes 上使用 yaml 文件创建了一个副本集,同时创建了副本集 - pod 没有启动 .. 给出 CrashLoopBackOff 错误。

请查看yaml 文件和下面的 pod 状态:

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: new-replica-set
  labels:
    app: new-replica-set
    type: front-end
spec:
  template:
    metadata:
      name: myimage
      labels:
        app: myimg-app
        type: front-end
    spec:
      containers:
        - name: my-busybody
          image: busybox
  replicas: 4
  selector:
    matchLabels:
      type: front-end

这是列出 pod 时的输出:

new-replica-set-8v4l2               0/1     CrashLoopBackOff   10 (38s ago)   27m
new-replica-set-kd6nq               0/1     CrashLoopBackOff   10 (44s ago)   27m
new-replica-set-nkkns               0/1     CrashLoopBackOff   10 (21s ago)   27m
new-replica-set-psjcc               0/1     CrashLoopBackOff   10 (40s ago)   27m

描述命令的输出

$ kubectl describe pods new-replica-set-8v4l2
Name:         new-replica-set-8v4l2
Namespace:    default
Priority:     0
Node:         minikube/192.168.49.2
Start Time:   Wed, 03 Nov 2021 19:57:54 -0700
Labels:       app=myimg-app
              type=front-end
Annotations:  <none>
Status:       Running
IP:           172.17.0.14
IPs:
  IP:           172.17.0.14
Controlled By:  ReplicaSet/new-replica-set
Containers:
  my-busybody:
    Container ID:   docker://67dec2d3a1e6d73fa4e67222e5d57fd980a1e6bf6593fbf3f275474e36956077
    Image:          busybox
    Image ID:       docker-pullable://busybox@sha256:15e927f78df2cc772b70713543d6b651e3cd8370abf86b2ea4644a9fba21107f
    Port:           <none>
    Host Port:      <none>
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Wed, 03 Nov 2021 22:12:32 -0700
      Finished:     Wed, 03 Nov 2021 22:12:32 -0700
    Ready:          False
    Restart Count:  16
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-lvnh6 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  kube-api-access-lvnh6:
    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   Scheduled  138m                  default-scheduler  Successfully assigned default/new-replica-set-8v4l2 to minikube
  Normal   Pulled     138m                  kubelet            Successfully pulled image "busybox" in 4.009613585s
  Normal   Pulled     138m                  kubelet            Successfully pulled image "busybox" in 4.339635544s
  Normal   Pulled     138m                  kubelet            Successfully pulled image "busybox" in 2.293243043s
  Normal   Created    137m (x4 over 138m)   kubelet            Created container my-busybody
  Normal   Started    137m (x4 over 138m)   kubelet            Started container my-busybody
  Normal   Pulled     137m                  kubelet            Successfully pulled image "busybox" in 2.344639501s
  Normal   Pulling    136m (x5 over 138m)   kubelet            Pulling image "busybox"
  Normal   Pulled     136m                  kubelet            Successfully pulled image "busybox" in 1.114394958s
  Warning  BackOff    61s (x231 over 138m)  kubelet            Back-off restarting failed container

我该如何解决这个问题? 另外,调试这些错误的最佳方法是什么?

【问题讨论】:

  • kubectl describe pods new-replica-set-8v4l2 的输出是什么?
  • @KamolHasan - 我已经在上面更新了 describe 命令的输出

标签: kubernetes


【解决方案1】:

busybox 默认使用 docker 命令 sh,它会打开一个 shell,并且由于容器既不是未通过附加终端启动的,所以 sh 进程在容器启动后立即退出,从而导致您的 pod 处于 CrashLoopBackOff 状态。

尝试切换到旨在具有长时间运行/始终运行过程的图像,例如nginx 或定义 command(= docker 入口点等效项)和 argument(= docker CMD 等效项),例如

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: new-replica-set
  labels:
    app: new-replica-set
    type: front-end
spec:
  template:
    metadata:
      name: myimage
      labels:
        app: myimg-app
        type: front-end
    spec:
      containers:
        - name: my-busybody
          image: busybox
          command: ["sh"]
          args: ["-c", "while true; do echo Hello from busybox; sleep 100;done"]
  replicas: 4
  selector:
    matchLabels:
      type: front-end

【讨论】:

  • 感谢更新,是的 - 如果指定了命令,busybox 将关闭
猜你喜欢
  • 2020-05-04
  • 2013-06-29
  • 1970-01-01
  • 2020-01-08
  • 2021-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多