4

I am trying to create an automated pipeline that would run multiple pods one after another on a namespace. The current issue is, between runs I want to wait for a pod to be fully deleted before running the next. Are there any ways to check if a given pod is fully deleted?

Current script:

kubectl delete -f pod.yaml
sleep 10
kubectl create -f pod.yaml
error when creating "pod.yaml": object is being deleted: pods "test-pod" already exists
Rico
  • 58,485
  • 12
  • 111
  • 141
ZPrime
  • 393
  • 4
  • 8

4 Answers4

7

You can do something like this:

kubectl delete -f pod.yaml
until kubectl get pod <pod-name> 2>&1 >/dev/null; do sleep 10; done
kubectl create -f pod.yaml

Basically, wait until kubectl get pod <pod-name> returns an error because it doesn't exist.

Rico
  • 58,485
  • 12
  • 111
  • 141
4

In case you want to delete the pod immediately, use this.

kubectl delete pod NAME --grace-period=0 --force
Rajith
  • 101
  • 1
  • 2
3

kubectl 1.11+ waits for the deletion to be completed before delete returns.

Jordan Liggitt
  • 16,933
  • 2
  • 56
  • 44
3

Use --wait option, i.e.:

kubectl delete -f your.yaml --wait=true
pb100
  • 736
  • 3
  • 11
  • 20