在k8s的资源对象中deployment类型的资源对象几乎是我们在集群运维中打交道最多的了,手动修改的话很方便命令也简单。但是如果想把这些操作放到脚本中形成自动化的过程就得想其他的方法了。
下面介绍两个命令,直接在命令行修改deployment的镜像
# kubectl set image deployment nginx nginx=registry.ctwifi.cn:5000/web/nginx:1.20 # kubectl patch deployment nginx --patch '{"spec": {"template": {"spec": {"containers": [{"name": "nginx","image":"registry.ctwifi.cn:5000/web/nginx:1.17"}]}}}}'
kubectl set 和 kubectl patch命令都可以直接对deployment对象做更新
那我们修改之后deployment有没有正常启动呢,需要一个脚本来监控deployment在修改之后的状态
#!/bin/bash # 设置Deployment名称和命名空间 deployment_name="your-deployment" namespace="your-namespace" # 检查Deployment是否处于"RollingUpdate"状态 check_status() { kubectl get deployment "$deployment_name" -n "$namespace" -o jsonpath='{.status.conditions[?(@.type=="Progressing")].reason}' } # 循环检查Deployment状态,直到出现错误或者更新成功 while true; do status=$(check_status) if [[ $status == "ProgressDeadlineExceeded" ]]; then echo "Deployment更新失败!" break elif [[ $status != "ReplicaSetUpdated" ]]; then echo "Deployment正在更新中..." sleep 10 else echo "Deployment更新成功!" break fi done
这样才算完全
参考连接:https://blog.csdn.net/qq_31977125/article/details/103142906
标签:status,kubectl,deploy,Deployment,更新,nginx,deployment,k8s From: https://www.cnblogs.com/ggborn-001/p/17831131.html