Debugging kubernetes pods in Completed status forever but not ready

12/6/2019

Would there be any reason if I'm trying to run a pod on a k8s cluster which stays in the 'Completed' status forever but is never in ready status 'Ready 0/1' ... although there are core-dns , kube-proxy pods,etc running successfully scheduled under each node in the nodepool assigned to a k8s cluster ... all the worker nodes seems to be in healthy state

-- Avi
azure-aks
kubernetes

3 Answers

12/6/2019

This sounds like the pod lifecycle has ended and most of the reasons is probably because your pod have finished the task it is meant for.

Something like next example will not do anything, it will be created successfully then started, will pull the image and then it will be marked as completed.

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: test-pod
    image: busybox
    resources:

Here is how it will look:

NAMESPACE     NAME                                                             READY   STATUS      RESTARTS   AGE
default       my-pod                                                       0/1     Completed   1          3s
default       testapp-1                                                        0/1     Pending     0          92m
default       web-0                                                            1/1     Running     0          3h2m
kube-system   event-exporter-v0.2.5-7df89f4b8f-mc7kt                           2/2     Running     0          7d19h
kube-system   fluentd-gcp-scaler-54ccb89d5-9pp8z                               1/1     Running     0          7d19h
kube-system   fluentd-gcp-v3.1.1-gdr9l                                         2/2     Running     0          123m
kube-system   fluentd-gcp-v3.1.1-pt8zp                                         2/2     Running     0          3h2m
kube-system   fluentd-gcp-v3.1.1-xwhkn                                         2/2     Running     5          172m
kube-system   fluentd-gcp-v3.1.1-zh29w                                         2/2     Running     0          7d19h

For this case, I will recommend you to check your yaml, check what kind of pod you are running? and what is it meant for?

Even, and with test purposes, you can add a command argument to keep it running.

command: ["/bin/sh","-c"]
args: ["command one; command two && command three"]

something like:

args: ["-c", "while true; do echo hello; sleep 10;done"]

The yaml with commands added would look like this:

 apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: test-pod
    image: busybox
    resources:
    command: ["/bin/sh","-c"]
    args: ["-c", "while true; do echo hello; sleep 10;done"]

Here is how it will look:

NAMESPACE     NAME                                                             READY   STATUS    RESTARTS   AGE
default       my-pod                                                       1/1     Running   0          8m56s
default       testapp-1                                                        0/1     Pending   0          90m
default       web-0                                                            1/1     Running   0          3h
kube-system   event-exporter-v0.2.5-7df89f4b8f-mc7kt                           2/2     Running   0          7d19h
kube-system   fluentd-gcp-scaler-54ccb89d5-9pp8z                               1/1     Running   0          7d19h
kube-system   fluentd-gcp-v3.1.1-gdr9l                                         2/2     Running   0          122m

Another thing that will help is a kubectl describe pod $POD_NAME, to analyze this further.

-- Ariel Palacios
Source: StackOverflow

12/6/2019

This issue got nothing to do with k8s cluster or setup. It's mostly with your Dockerfile.

For the pod to be in running state, you need to have the container as an executable, for that usually an Entrypoint that specifies the instructions would solve the problem you are facing.

A better approach to resolve this or debug this particular issue would be, by running the respective docker container on a localmachine before deploying that onto k8s cluster.

-- BinaryMonster
Source: StackOverflow

12/6/2019

The message Completed, most likely implies that the k8s started your container, then the container subsequently exited. In Dockerfile, the ENTRYPOINT defines the process with pid 1 which the docker container should hold, otherwise it terminates, so whatever the pod is trying to do, you need to check whether the ENTRYPOINT command is looping, and doesn't die.

For side notes, Kubernetes will try to restart the pod, once it terminates but after few tries the pod status may turn into CrashLoopBackOff and you will see message something similar to Back-off restarting failed container.

-- dropyourcoffee
Source: StackOverflow