Using kubectl to wait until a pvc is bound

Viewed 680

I wanna use kubectl wait command to wait until a pvc is bound.

I tried kubectl wait --for=condition=bound pvc/my-pvc-claim --timeout=2s with a pvc which is already bound, but it doesn't seem to work. This is the output error: timed out waiting for the condition on persistentvolumeclaims/my-pvc-claim.

I read kubectl wait documentation, but still can't understand which condition I should use. How can I accomplish that? Is there a more complete documentation explaining how to do that?

3 Answers

You can use the following command:

while [[ $(kubectl get pvc myclaim -o 'jsonpath={..status.phase}') != "Bound" ]]; do echo "waiting for PVC status" && sleep 1; done

Use the jsonpath provided in subudears answer as the for option. So this way you can utilise kubectl wait

kubectl wait --for=jsonpath='{.status.phase}'=Bound pvc/my-pvc
Related