Search code examples
kubernetes

kubectl wait not working for creation of resources


How do you get around waiting on resources not yes created?

In script I get:

kubectl wait --for=condition=ready --timeout=60s -n <some namespace> --all pods

error: no matching resources found

Solution

  • This is a community wiki answer posted for better visibility. Feel free to expand it.

    As documented:

    Experimental: Wait for a specific condition on one or many resources.

    The command takes multiple resources and waits until the specified condition is seen in the Status field of every given resource.

    Alternatively, the command can wait for the given set of resources to be deleted by providing the "delete" keyword as the value to the --for flag.

    A successful message will be printed to stdout indicating when the specified condition has been met. One can use -o option to change to output destination.

    This command will not work for the resources that hasn't been created yet. @EmruzHossain has posted two valid points:

    • Make sure you have provided a valid namespace.

    • First wait for the resource to get created. Probably a loop running kubectl get periodically. When the desired resource is found, break the loop. Then, run kubectl wait to wait for the resource to be ready.

    Also, there is this open thread: kubectl wait for un-existed resource. #83242 which is still waiting (no pun intended) to be implemented.