Ensure Kubernetes Deployment has completed and all pods are updated and available

后端 未结 2 761
长发绾君心
长发绾君心 2021-02-04 04:36

The status of a deployment indicates that you can look at a deployments observedGeneration vs generation and when observedGeneration >= genera

2条回答
  •  忘掉有多难
    2021-02-04 04:49

    Just use a rollout status:

    kubectl rollout status deployment/
    

    This will run in foreground, it waits and displays the status, and exits when rollout is complete on success or failure. If you're writing a shell script, then check the return code right after the command, something like this.

    kubectl rollout status deployment/
    if [[ "$?" -ne 0 ]] then
        echo "deployment failed!"
        exit 1
    fi
    

    To even further automate your script:

    deployment_name=$(kubectl get deployment -n  | awk '!/NAME/{print $1}')  
    kubectl rollout status deployment/"${deployment_name}" -n 
    if [[ "$?" -ne 0 ]] then
        echo "deployment failed!"
        #exit 1
    else
        echo "deployment succeeded"
    fi
    

    If you're running in default namespace then you could leave out the -n . The command awk '!/NAME/{print $1}') extracts the first field (deployment name), while ignoring the first row which is the header(NAME READY UP-TO-DATE AVAILABLE AGE). If you have more than one deployment files then you could also add more regex or pattern to awk: e.g. awk '!/NAME//{print $1}')

提交回复
热议问题