Back-off restarting failed container报错

我的配置文件中有这样一小段

apiVersion: v1
kind: Pod
metadata: 
  name: busybox
  namespace: default
  labels:
    app: busybox
spec: 
  containers:
  - name: busybox
    image: busybox

来测试配置清单是否可用。

出现错误时:
kubectl logs busybox -p
这时候因为没有访问 是看不到日志的

kubectl describe pod busybox
看到了问题所在:

Events: Type Reason Age From
Message ---- ------ ---- ----
------- Normal Scheduled 87s default-scheduler Successfully assigned default/busybox to node2 Normal Pulled
71s kubelet Successfully pulled image
“busybox” in 15.824134554s Normal Pulled 69s
kubelet Successfully pulled image “busybox” in 1.345001397s
Normal Pulled 36s kubelet Successfully
pulled image “busybox” in 15.738609779s Normal Created 36s (x3
over 71s) kubelet Created container busybox Normal
Started 36s (x3 over 71s) kubelet Started container
busybox Warning BackOff 22s (x4 over 68s) kubelet
Back-off restarting failed container Normal Pulling 11s (x4
over 87s) kubelet Pulling image “busybox”

原来是这样。镜像启动容器后,容器内部没有常驻进程,导致容器启动成功后即退出,从而进行了持续的重启。

只需要给容器加上一个常驻的进程就可以
那么就可以写成

apiVersion: v1
kind: Pod
metadata: 
  name: busybox
  namespace: default
  labels:
    app: busybox
spec: 
  containers:
  - name: busybox
    image: busybox
    command: ["/bin/sh","-ce","sleep 3600"]

在这里插入图片描述

你可能感兴趣的:(kubernetes,docker,#linux,kubernetes,云计算,linux)