0
votes

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

3
Based on name i guess two of pods are jobs. Could you share job/cronjob YAMLS you have used for those jobapp? Also provide output of kubectl describe <pod_name> -n api. In some scenarios pod could go runnung > CrashLoopBackOff but in most of the cases its just go straight to CrashLoopBackOff if there is something wrong. It would be good to reproduce this behavior and check if this scenario was running > Crash. - PjoterS

3 Answers

2
votes

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.

0
votes

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.

0
votes

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.