2023-01-31
檢查deployment的image版本
kubectl get deploy -o wide -n major | grep -e admin-system -e NAME
deployment admin-syste 這個 NAME是 admin-system
admin-system=registry.gitlab……… 的 admin-system 是container name
registry.gitlab……… 是新的 image
kubectl set image deployment admin-system admin-system=registry.gitlab.........
檢查deployment的image版本確認有更換
kubectl get deploy -o wide -n major | grep -e admin-system -e NAME
查看紀錄
kubectl rollout history deploy admin-system -n major
回滾上一個版本
kubectl rollout undo deployment admin-system
確認回滾狀態
kubectl rollout status deployment admin-system -n major
好吧寫個 shell …..
shell 不熟寫 python3
#!/usr/bin/env python3
import subprocess
def output(cmd,show=1):
dooutput = subprocess.Popen([cmd], shell=True,stdout=subprocess.PIPE, encoding='utf-8').communicate()[0]
if show == 1:
print(dooutput)
else:
return dooutput.replace("\n", "")
output("kubectl get deploy -o wide -n beta|awk '{print $1}'")
deploy = input("Input deploy name ==> ")
cmd = "kubectl get deploy -o wide -n beta|grep "+deploy+"|awk '{print $1,$6,$7}'"
info = output(cmd, show=0).split()
print ("NAME : "+info[0])
print ("CONTAINERS : "+info[1])
print ("IMAGES : "+info[2])
print ("")
output("kubectl get pod -n beta |grep -e NAME -e "+deploy)
image = input("Input new image ==> ")
output("kubectl set image deployment "+info[0]+" "+info[1]+"="+image+" -n beta")
output("kubectl get deploy -o wide -n beta|grep -e NAME -e "+deploy)
output("kubectl rollout status deployment "+deploy+" -n beta")
output("kubectl get pod -n beta |grep -e NAME -e "+deploy)