0

I am using AKS with Kubernetes v1.25.6 and I have started to see a number of pods with a Completed status. From what I understand these are generated when an exit 0 code is returned on the process the pod is running, which for the pods in question makes no sense. I was also given the impression that the completed state would allow me to use a command such as kubectl logs podname to review why the pod "completed".

However, I am told that the resource cannot be found. So I have decided to set up logging to a storage account from AKS using the diagnostic settings to see if I can find the data from there.

So my next step is to basically clean up all completed pods and I have seen the following command given:

kubectl delete pod --field-selector=status.phase==Succeeded

I updated this command to the following (to see what would be selected before swapping to a delete)

kubectl get pod --field-selector=status.phase==Completed

However I am told that "No resources have been found", despite a kubectl get pod command showing me nearly 20 completed pods.

If I alter the command to:

kubectl get pod --field-selector=status.phase==Running

I am shown all the running pods. Why does this not work for completed pods? Is this an AKS issue or is the command incorrect?

David Hirst
  • 193
  • 1
  • 1
  • 8

1 Answers1

0

So it turns out that "Completed" is considered failed instead of Successful which seems rather unintuitive, since Completed does not mean an error or failure.

Changing to

kubectl get pod --field-selector=status.phase==Failed

Returns the affected pods (including others that have "failed"). This is enough for me to clean up but does not allow me to specifically select "Completed" alone for other reasons but it is as close as possible to what I need.

David Hirst
  • 193
  • 1
  • 1
  • 8