Kubernetes api not shows error pod status

9/1/2020

i tried ListPodForAllNamespaces() using Kubernetes API C# library .Using Status.Phase property to get the current status of the pod. when i tried to kubectl comman to get the pod status ,it is shows as crashloop and error state.

kubectl get pods -n api
NAME                                 READY   STATUS             RESTARTS   AGE
test-web-api-78777-2zlwl             1/1     Running            0          9m8s
jobapp1-878787-knt46                 0/1     CrashLoopBackOff   5          4m53s
jobapp2-878787-knt46                 0/1     Error              5          4m53s

but if the pod status is error state ,the Kubernetes api shows as running. below is my code

var config = KubernetesClientConfiguration.InClusterConfig();//for local testing BuildDefaultConfig && for cluster testing InClusterConfig
    var client = new Kubernetes(config);
    var namespaces = client.ListPodForAllNamespaces();
    foreach (var ns in namespaces.Items){
        Console.WriteLine(ns.Metadata.Name +" status - "+ns.Status.Phase);
    }

OUTPUT IS

test-web-api-78777-2zlwl status - Running
jobapp1-878787-knt46 status - Running
jobapp2-878787-knt46 status - Running

-- avancho marchos
c#
kubernetes

3 Answers

9/1/2020

Try

kubectl describe [-n namespace] pod [pod_id]

You may see something there that tells you why the pod is in a crashed state.. also you can check in the google cloud console whether anything is reported there.

-- Rob Evans
Source: StackOverflow

9/16/2021

This Main Status may still show running if during the point of querying status was running, and later it can become something else, thus to escape this problem , I would suggest to use properties of pod object(type :V1PodList) from in K8client in C# like :

pod.Status.Conditions.Any(x=>x.Status== "False")

This will actualy give status of 4 conditions i.e Initialized ,Ready,ContainersReady & PodScheduled. For a successfull running pod , all 4 will be true , else atleast one of them will be false.

-- Paras Patidar
Source: StackOverflow

9/1/2020

Neither your kubectl command nor your C# kubernetes api is wrong.

You can see that the last two pods restarted 5 times. Each of them was in Running state for some time during restarting for 5 times.

When you ran your C# api, all of the pods were actually in Running phase.

If you run your C# api after waiting for a bit, you will see that they are not in Running phase.

-- Masudur Rahman
Source: StackOverflow