Is there a way to check whether a pod status is in the completed state? I have a Pod that I only wanted to use once (where init containers didn't quite serve my purpose) and want to write a check to wait for Completed status.
I am able to get it for Running, Pending, but not for Completed.
Running:
[user@sandbox gcp_kubernetes_installation]$ kubectl get pods --field-selector=status.phase=Running -n mynamespace NAME READY STATUS RESTARTS AGE mssql-deployment-795dfcf9f7-l2b44 1/1 Running 0 6m data-load-pod 1/1 Running 0 5m
Pending:
[user@sandbox gcp_kubernetes_installation]$ kubectl get pods --field-selector=status.phase=Pending -n mynamespace NAME READY STATUS RESTARTS AGE app-deployment-0 0/1 Pending 0 5m
Completed:
[user@sandbox gcp_kubernetes_installation]$ kubectl get pod -n namespace NAME READY STATUS RESTARTS AGE mssql-deployment-795dfcf9f7-l2b44 1/1 Running 0 11m data-load-data-load-pod 0/1 Completed 0 10m app-deployment-0 0/1 Pending 0 10m [user@sandbox gcp_kubernetes_installation]$ kubectl get pods --field-selector=status.phase=Completed -n namespace No resources found.
I believe there may be a bug in the field-selector, but just wondering if there are any fixes or details on a workaround.
If the output from a specific pod is desired, run the command kubectl describe pod pod_name --namespace kube-system . The Status field should be "Running" - any other status will indicate issues with the environment. In the Conditions section, the Ready field should indicate "True".
That means inside pod's container process has been successfully completed.
PodScheduled : the Pod has been scheduled to a node. ContainersReady : all containers in the Pod are ready. Initialized : all init containers have completed successfully. Ready : the Pod is able to serve requests and should be added to the load balancing pools of all matching Services.
The correct status.phase for completed pods is Succeeded.
So, to filter only completed pods, you should use this:kubectl get pod --field-selector=status.phase=Succeeded
Although, the use of bare pods is not recommended. Consider using a Job Controller:
A Job creates one or more Pods and ensures that a specified number of them successfully terminate. As pods successfully complete, the Job tracks the successful completions.
You can check job conditions and wait for them with this:kubectl wait --for=condition=complete job/myjob
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With