<p>I've created a replicaset on Kubernetes using a <code>yaml</code> file, while the replicaset is created - the pods are not starting .. giving <code>CrashLoopBackOff</code> error.</p>
<p>Please see the <code>yaml</code> file &amp; the pod status below:</p>
<pre class="lang-yaml prettyprint-override"><code>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
</code></pre>
<p>Here is output, when list the pods:</p>
<pre><code>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
</code></pre>
<p>output of describe command</p>
<pre><code>$ 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:  &lt;none&gt;
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:           &lt;none&gt;
    Host Port:      &lt;none&gt;
    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:    &lt;none&gt;
    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:       &lt;nil&gt;
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              &lt;none&gt;
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 &quot;busybox&quot; in 4.009613585s
  Normal   Pulled     138m                  kubelet            Successfully pulled image &quot;busybox&quot; in 4.339635544s
  Normal   Pulled     138m                  kubelet            Successfully pulled image &quot;busybox&quot; 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 &quot;busybox&quot; in 2.344639501s
  Normal   Pulling    136m (x5 over 138m)   kubelet            Pulling image &quot;busybox&quot;
  Normal   Pulled     136m                  kubelet            Successfully pulled image &quot;busybox&quot; in 1.114394958s
  Warning  BackOff    61s (x231 over 138m)  kubelet            Back-off restarting failed container

</code></pre>
<p>How do I fix this?
Also, what is the best way to debug these error?</p>

Karan Alang
<p>busybox default to the docker command <code>sh</code> which opens a shell and because the container is neither not started with a terminal attached the <code>sh</code> process exits immediatly after container startup leading to the <code>CrashLoopBackOff</code> Status of your pods.</p>
<p>Try switching to an image that is intended to have a long running/always running process, e.g. <code>nginx</code> or define a <code>command</code> ( = docker entrypoint equivalent) and an <code>argument</code> ( = docker CMD equivalent), e.g.</p>
<pre><code>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: [&quot;sh&quot;]
          args: [&quot;-c&quot;, &quot;while true; do echo Hello from busybox; sleep 100;done&quot;]
  replicas: 4
  selector:
    matchLabels:
      type: front-end
</code></pre>
