apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deploy
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: myapp
release: dev
template:
metadata:
labels:
app: myapp
release: dev
spec:
containers:
- name: myapp-rongqi
image: ikubernetes/myapp:v1
vim de.yaml #修改yaml里的鏡像版本
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deploy
namespace: default
spec:
replicas: 5
selector:
matchLabels:
app: myapp
release: dev
strategy:
rollingUpdate:
#設置策略為滾動更新,還有一個重建更新,全部一起結束一起新建 不友好這里就不介紹了
maxSurge: 1
#大可超出預設值1個容器
maxUnavailable: 0
#大可有0個容器不可用 ,整體表示更新時可同時可有6個容器,必須保證有5個容器可用
template:
metadata:
labels:
app: myapp
release: dev
spec:
containers:
- name: myapp-rongqi
image: ikubernetes/myapp:v1
kubectl apply -f de.yaml #用apply更新配置
[root@cs25 ~]# kubectl get pod -l app=myapp -w
NAME READY STATUS RESTARTS AGE
myapp-deploy-576d479bcc-bt7hz 1/1 Running 0 47m
myapp-deploy-576d479bcc-bzqwv 1/1 Running 0 11m
myapp-deploy-576d479bcc-hf6kb 1/1 Running 0 47m
myapp-deploy-576d479bcc-hgb6w 1/1 Running 0 11m
myapp-deploy-576d479bcc-vztqp 1/1 Running 0 11m
myapp-deploy-7f969b64fb-2frdn 0/1 Pending 0 0s
myapp-deploy-576d479bcc-vztqp 1/1 Terminating 0 12m
myapp-deploy-7f969b64fb-6lhjw 0/1 Pending 0 0s
myapp-deploy-7f969b64fb-2frdn 0/1 Pending 0 0s
myapp-deploy-7f969b64fb-6lhjw 0/1 Pending 0 0s
myapp-deploy-7f969b64fb-5ms8f 0/1 Pending 0 0s
myapp-deploy-7f969b64fb-5ms8f 0/1 Pending 0 0s
myapp-deploy-7f969b64fb-6lhjw 0/1 ContainerCreating 0 1s
myapp-deploy-7f969b64fb-2frdn 0/1 ContainerCreating 0 1s
myapp-deploy-7f969b64fb-5ms8f 0/1 ContainerCreating 0 0s
myapp-deploy-7f969b64fb-2frdn 0/1 ContainerCreating 0 35s
myapp-deploy-7f969b64fb-5ms8f 0/1 ContainerCreating 0 35s
myapp-deploy-7f969b64fb-6lhjw 0/1 ContainerCreating 0 36s
myapp-deploy-576d479bcc-vztqp 0/1 Terminating 0 12m
myapp-deploy-576d479bcc-vztqp 0/1 Terminating 0 12m
myapp-deploy-576d479bcc-vztqp 0/1 Terminating 0 12m
myapp-deploy-7f969b64fb-5ms8f 1/1 Running 0 43s
myapp-deploy-7f969b64fb-2frdn 1/1 Running 0 47s
myapp-deploy-7f969b64fb-6lhjw 1/1 Running 0 51s
myapp-deploy-576d479bcc-hgb6w 1/1 Terminating 0 13m
myapp-deploy-576d479bcc-bzqwv 1/1 Terminating 0 13m
myapp-deploy-576d479bcc-bt7hz 1/1 Terminating 0 49m
myapp-deploy-7f969b64fb-gprvk 0/1 Pending 0 0s
myapp-deploy-7f969b64fb-fwdbr 0/1 Pending 0 0s
myapp-deploy-7f969b64fb-fwdbr 0/1 Pending 0 1s
myapp-deploy-7f969b64fb-gprvk 0/1 Pending 0 1s
myapp-deploy-7f969b64fb-fwdbr 0/1 ContainerCreating 0 1s
myapp-deploy-7f969b64fb-gprvk 0/1 ContainerCreating 0 1s
myapp-deploy-576d479bcc-hgb6w 0/1 Terminating 0 13m
myapp-deploy-576d479bcc-bzqwv 0/1 Terminating 0 13m
myapp-deploy-7f969b64fb-fwdbr 0/1 ContainerCreating 0 18s
myapp-deploy-7f969b64fb-gprvk 0/1 ContainerCreating 0 19s
myapp-deploy-576d479bcc-hgb6w 0/1 Terminating 0 13m
myapp-deploy-576d479bcc-bt7hz 0/1 Terminating 0 49m
myapp-deploy-576d479bcc-bzqwv 0/1 Terminating 0 13m
myapp-deploy-7f969b64fb-gprvk 1/1 Running 0 20s
myapp-deploy-7f969b64fb-fwdbr 1/1 Running 0 20s
kubectl get rs -o wide #使用命令查看
可以看到當前鏡像版本已經換成了v2 且模板也變了,之前的v1版本還保這方便回滾,yaml文件內容修改一次就會當做一次更新,最后一串數字就是通過yaml文件計算出來的
注意: deployment的pod模板被更改時才會創建新的修訂版本,例如更新模板標簽或者容器鏡像可以觸發滾動更新, 其它操作例如擴展副本數將不會觸發deployment的更新操作
kubectl set image deploy myapp-deploy myapp-rongqi=ikubernetes/myapp:v3 && kubectl rollout pause deploy myapp-deploy
#kubectl set image deploy "控制器Name" "容器name"=ikubernetes/myapp:v3 && kubectl rollout pause deploy "控制器Name"
#原理就是先升級一個容器的版本,執行pause 暫停升級任務,待升級的那個容器經過真實用戶測試后無錯后解除暫停
kubectl get rs -o wide #查看控制器能看到,有1個v3版,5個v2版本,出現6個的原因是我滾動策略定義了升級可允許存在6個
kubectl rollout resume deploy myapp-deploy
#解除暫停
#解除暫停后能看到,v2版本在一點點的關閉向v3版轉移,最終v2全部關閉,v3版5個容器全部正常上線
kubectl rollout history deployment/nginx-deployment
#查看升級歷史記錄
kubectl rollout history deployment/nginx-deployment --revision=2
#查看某個升級歷史記錄的的詳細信息
kubectl rollout undo deployment/nginx-deployment
#回滾到上一個版本
kubectl rollout undo deployment/nginx-deployment --to-revision=2
#回滾到指定版本
另外有需要云服務器可以了解下創新互聯cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
分享文章:kubernetes控制器-創新互聯
當前地址:http://vcdvsql.cn/article22/epdcc.html
成都網站建設公司_創新互聯,為您提供全網營銷推廣、外貿網站建設、App設計、關鍵詞優化、虛擬主機、外貿建站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯