Knative: Operator’s Handbook

Script to wait until deployment is ready

If you need to automate deploying a Revision and waiting until Revision readiness, you would need a tool.

If you use the official Knative command-line tool (kn), by default it wait 600 seconds for deployment to be ready (configurable with --wait-timeout). However, kn cannot deploy YAML manifests.

If you use kubectl, you can use a bash script like this to achieve the same result:

#!/usr/bin/env bash
set -euo pipefail

##   ./ SERVICE_FILE [TIMEOUT default:600]

file="${1:?SERVICE_FILE argument not specified}" || usage

status() {
    kubectl get revision "${1:?REVISION empty}" \

reason() {
    kubectl get revision "${1:?REVISION empty}" \

wait_ready() {
    local rev
    rev="${1:?REVISION empty}"
    while :; do
        cur="$(status "${rev}")"
        echo >&2 "Ready: ${cur}"
        if [[ "$cur" == True ]]; then
            exit 0
        elif [[ "$cur" == False ]]; then
            echo >&2 "Reason: $(reason "${rev}")"
            exit 1
        sleep 2

start_timer() {
    sleep "${1:?SECS empty}"
    echo "not ready after ${1}s."
    kill -KILL -- "$pid" &>/dev/null

rev_name="$(kubectl get -f "${file}" \

start_timer "$wait_secs" &
trap "kill -KILL -- $timer_pid" EXIT

wait_ready "${rev_name}"