Skip to main content

Kubernetes - Kubectl - The wait Operation

22 Feb 2021 - Cody Merritt Anhorn

This article will be a quick one, going over the wait operation for kubectl. It’s relatively simple to use, but helps immeasurably helpful with automation scripts.

Details

In my case I wanted to make my deployment scripts less error prone during a database migration job. I have a job that run in Kubernetes during a deployment that will run Database migrations, and with most database migrations you probably dont want to deploy a new application without having a fully updated database. To help facilitate the process of updating the database, but not deploying the application till it was done I used the wait operation to delay startup till it is done running.

Below is pretty much it, just using wait, this takes in the resources you are waiting for to finish. It also comes with a --for option that can be used to trigger a success on a condition, in my case I want the wait to trigger on a complete condition, this way if it does not in a certain type period complete it will trigger a figure of the job and not deploy the application. Checkout Kubectl Operations for more details about wait and other operations supported by Kubectl.

kubectl wait --for=condition=complete job/auth-migrate-database-job

Categories: blog kubernetes

Tags: Kubernetes Kubectl Command Line


Cody Merritt Anhorn
Email: cody.anhorn@hotmail.com