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?