kubectl wait for a pod to complete

Viewed 3451

I have a pod spec which runs a command like rm -rf /some/path

i create the pod using kubectl apply -f ...

now i want to wait till the pod completes. i can see that the pod is done, kubectl get pod/<mypod> shows STATUS Completed

How do i wait for this condition?

i have looked at kubectl wait ... but that doesnt seem to help me

kubectl wait --for=condition=complete pod/<my-pod> seems to just block. I havent deleted the pod, it is still there in the Completed status

1 Answers

The command that you use: kubectl wait --for=condition=complete pod/<my-pod> will not work because a pod doesn't have such condition. Pod Conditions are as follows:

  • PodScheduled: the Pod has been scheduled to a node.

  • ContainersReady: all containers in the Pod are ready.

  • Initialized: all init containers have started successfully.

  • Ready: the Pod is able to serve requests and should be added to the load balancing pools of all matching Services.

The phase for a successfully completed pod is called succeeded:

All containers in the Pod have terminated in success, and will not be restarted.

It would be better however if you use kubectl wait for Jobs instead of bare Pods and than execute kubectl wait --for=condition=complete job/myjob.

Related