Why the pod status is coming as crashloopbackoff in my case?

9/7/2019

I created a pod which just calculates the pi and exits and it should run again. On monitoring I observed the status was running, then turned completed and finally crashloopbackoff .

I tried different images, but issue is the same.

apiVersion: v1
kind: Pod
metadata:
  name: pi
spec:
    containers:
      - name: pi
        image: perl
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]

Running and Completed status in a series. But i see CrashLoopBackOff.
qvamjak@qvamjak:~/Jobs$ kubectl get pods
NAME           READY   STATUS             RESTARTS   AGE
pi             0/1     CrashLoopBackOff   16         63m
-- Vamsi Jakkula
containers
kubernetes
kubernetes-pod

1 Answer

9/7/2019

This is due to the restartPolicy of your pod, by default it is Always, which means the pod expects all its containers to be long-running (e.g., HTTP server), if any container in the pod exits (even successfully with code 0), it will be restarted. In this case, you want to set restartPolicy as OnFailure. See https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy.

In addition to that, Job instead of Pod is the resource type you want for run-to-completion applications, because Job manages pods for you and offers more guarantees than unmanaged Pod.

-- Dagang
Source: StackOverflow