Auto-learner
Auto-learner

Reputation: 1511

kubectl wait --for=condition=complete --timeout=30s

I am trying to check the status of a pod using kubectl wait command through this documentation. Following is the command that i am trying

kubectl wait --for=condition=complete --timeout=30s -n d1 job/test-job1-oo-9j9kj

Following is the error that i am getting

Kubectl error: status.conditions accessor error: Failure is of the type string, expected map[string]interface{}

and my kubectl -o json output can be accessed via this github link.

Can someone help me to fix the issue

Upvotes: 53

Views: 120950

Answers (4)

Noam Manos
Noam Manos

Reputation: 16971

To wait until your pod is running, check for "condition=ready". In addition, prefer to filter by label, rather than specifying pod id. For example:

$ kubectl wait --for=condition=ready pod -l app=netshoot 
pod/netshoot-58785d5fc7-xt6fg condition met

Another option is rollout status - To wait until the deployment is done:

$ kubectl rollout status deployment netshoot
deployment "netshoot" successfully rolled out

Both options work great in automation scripts, when it is required to wait for an app to be installed. However, as @CallMeLaNN noted for the second option, deployment "rolled out" does not check if its pods are ready or failed.

Update: A very handy tip I found about kubectl wait is to use --for jsonpath if the available conditions are not sufficient. For example, to wait up to 3m for an Operator Subscription with an InstalPlan to be ready, I don't check for its condition but for its state:

$ kubectl wait --for jsonpath='{.status.state}'=AtLatestKnown sub mysub -n myns --timeout=3m

Upvotes: 69

yurinne
yurinne

Reputation: 31

Even if --for=condition=complete doesn't exist, you can use --for=condition=ready=False

This will wait until your pod stop running which is what you seem to want. At least, it worked for me.

Upvotes: 3

Daniel Robinson
Daniel Robinson

Reputation: 465

As outlined by Rico you can't wait for the complete state on the pod, assuming you want to wait for the job to complete use the following

kubectl wait --for=condition=complete --timeout=30s -n d1 job/test-job1

Upvotes: 6

Rico
Rico

Reputation: 61521

This totally looks like you are running kubectl wait --for=condition=complete on a Pod as described in your output rather than a Job.

A pod doesn't have the --for=condition=complete option. Exactly, what I get when I run it on a pod:

$ kubectl wait --for=condition=complete pod/mypod-xxxxxxxxxx-xxxxx
error: .status.conditions accessor error: Failure is of the type string, expected map[string]interface{}

Upvotes: 23

Related Questions