4

I am trying to find a command or a sample shell snippet where I can wait until the list of Kubernetes pods is successful. I have checked the answer but it was not giving any output. Can someone guide me or suggest an approach, I am completely new to kubernetes.

kubectl -n test-ns get jobs -w

NAME     DESIRED   SUCCESSFUL   AGE
test-1    1         1            2d
test-2    1         1            2d
test-3    1         1            2d
test-4    1         1            2d


until kubectl get jobs -n test-ns  -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}' | grep True ; do sleep 1 ; done

This is not giving any output

Rico
  • 58,485
  • 12
  • 111
  • 141
Auto-learner
  • 1,411
  • 7
  • 26
  • 43

3 Answers3

3

To wait until your pods are running, check for "condition=ready" and filter by app label, for example:

$ kubectl wait --for=condition=ready pod -l app=netshoot 
pod/netshoot-58785d5fc7-xt6fg condition met
Noam Manos
  • 15,216
  • 3
  • 86
  • 85
1

you need to use this command

kubectl rollout status 
Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
1

If you want to use kubectl as described here where it gets all the jobs, you need to use .items[*]... in your JSONpath (That answer is for just one specific job). For example:

kubectl -n test-ns get jobs \
  -o jsonpath='{.items[*].status.conditions[?(@.type=="Complete")].status}' \
  | grep True
Rico
  • 58,485
  • 12
  • 111
  • 141