kubernetes giving CrashLoopBackOff error while creating pods

1/17/2020

I'm creating a pod of node container, and it is giving CrashLoopBackOff error.

kubectl get pods

enter image description here

kubectl describe pod test-node3

enter image description here

Any help would be appreciated.

-- Abhishek Kumar
docker
kubernetes
linux
orchestration

3 Answers

1/17/2020

Your container does not have a long running process. The main process in the container is exiting with exit code 0 which usually means that the process has terminated successfully. You can see it in the kubectl describe output you have shared.

Reason: Completed 
Exit Code: 0
-- Shashank V
Source: StackOverflow

1/17/2020

You can add command as below so that pod will remain in running state.

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: myapp-container
    image: busybox
    command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']

Ref: Doc

-- JithZ
Source: StackOverflow

1/17/2020

Once Pod is assigned to a node by scheduler, kubelet starts creating containers using container runtime. There are three possible states of containers: Waiting, Running and Terminated.

Terminated: Indicates that the container completed its execution and has stopped running.

A container enters into this when it has successfully completed execution or when it has failed for some reason. Regardless, a reason and exit code is displayed, as well as the container’s start and finish time.

On your screenshot its clear that container inside pod is running to completion with its work done, with exit code 0 as below snippet

  State:          Terminated
    Reason:       Completed
    Exit Code:    0

You should either add a long running process to your container or define restartPolicy: Never on pod definition.

Tested your image with adding correct restart policy and POD runs correctly to completion with no crash

kubectl run test --image=abhishekk27/kube-pub:new --restart=Never

$ kubectl get pods
NAME      READY   STATUS      RESTARTS   AGE
test      0/1     Completed   0          8m12s

yaml genrated :

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: test
  name: test
spec:
  containers:
  - image: abhishekk27/kube-pub:new
    name: test
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never

Result:

$ kubectl describe pod test
Name:         test
Namespace:    default
Priority:     0
Node:         dlv-k8s-node-1/131.160.200.104
Start Time:   Fri, 17 Jan 2020 09:45:00 +0000
Labels:       run=test
Annotations:  <none>
Status:       Succeeded
IP:           10.244.1.12
IPs:
  IP:  10.244.1.12
Containers:
  test:
    Container ID:   docker://b335e5fef022dced824f85ba2bfe4c024608c9b5463599eb36591a14d709786d
    Image:          abhishekk27/kube-pub:new
    Image ID:       docker-pullable://abhishekk27/kube-pub@sha256:6a696bd733edaa48b9be781960f4ee178d16f1c9aea51e53bd0f54326a3d05b1
    Port:           <none>
    Host Port:      <none>
    State:          Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Fri, 17 Jan 2020 09:45:48 +0000
      Finished:     Fri, 17 Jan 2020 09:45:48 +0000
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-7f4mt (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-7f4mt:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-7f4mt
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age    From                     Message
  ----    ------     ----   ----                     -------
  Normal  Scheduled  6m50s  default-scheduler        Successfully assigned default/test to dlv-k8s-node-1
  Normal  Pulling    6m46s  kubelet, dlv-k8s-node-1  Pulling image "abhishekk27/kube-pub:new"
  Normal  Pulled     5m58s  kubelet, dlv-k8s-node-1  Successfully pulled image "abhishekk27/kube-pub:new"
  Normal  Created    5m58s  kubelet, dlv-k8s-node-1  Created container test
  Normal  Started    5m58s  kubelet, dlv-k8s-node-1  Started container test
-- DT.
Source: StackOverflow