k8s deployment釋出失敗回滾
阿新 • • 發佈:2021-10-29
1. deployment釋出失敗回滾
-
檢視歷史釋出版本
kubectl rollout history deployment/web
-
回滾上一個版本
kubectl rollout undo deployment/web
-
回滾歷史指定版本
kubectl rollout undo deployment/web --to-revision=2
-
注:回滾是重新部署某一次部署時的狀態,即當時版本所有配置
-
示例:yaml配置檔案
[root@k8s-master deployment]# cat web.yaml apiVersion: apps/v1 kind: Deployment metadata: name: web namespace: default annotations: # 記錄回滾引數 kubernetes.io/change-cause: "web.v1-nginx-1.19" #記錄到revision中的內容,記錄版本號 spec: replicas: 9 # Pod副本預期數量 revisionHistoryLimit: 10 # RS歷史版本儲存數量 selector: matchLabels: app: web strategy: rollingUpdate: maxSurge: 25% # 滾動更新過程最大pod副本數 maxUnavailable: 25% # 滾動更新過程中最大不可用pod副本數, type: RollingUpdate template: metadata: labels: app: web # Pod副本的標籤 spec: containers: - name: web image: nginx:1.19 readinessProbe: # 健康檢查,如果失敗,將殺死容器,來重啟 httpGet: port: 80 path: /index.html initialDelaySeconds: 10 #啟動容器後多少秒健康檢查 periodSeconds: 10 #以後間隔多少秒檢查一次 livenessProbe: # 存活檢查,失敗就會剔除 service httpGet: port: 80 path: /index.html
-
檢視history歷史記錄
[root@k8s-master deployment]# kubectl rollout history deployment web deployment.apps/web REVISION CHANGE-CAUSE 1 web.v1-nginx-1.16 2 web.v1-nginx-1.18 3 web.v1-nginx-1.19
2. 案例操作
-
查詢釋出歷史版本
[root@k8s-master deployment]# kubectl rollout history deployment web deployment.apps/web REVISION CHANGE-CAUSE 1 web.v1-nginx-1.16 2 web.v1-nginx-1.18 3 web.v1-nginx-1.19
-
回滾到上一個版本
[root@k8s-master deployment]# curl -I http://192.168.0.202:30082 HTTP/1.1 200 OK Server: nginx/1.19.5 Date: Tue, 01 Dec 2020 14:20:33 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Tue, 24 Nov 2020 13:02:03 GMT Connection: keep-alive ETag: "5fbd044b-264" Accept-Ranges: bytes # 回滾到上一個版本 [root@k8s-master deployment]# kubectl rollout undo deployment web deployment.apps/web rolled back [root@k8s-master deployment]# curl -I http://192.168.0.202:30082 HTTP/1.1 200 OK Server: nginx/1.18.0 Date: Tue, 01 Dec 2020 14:21:39 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Tue, 21 Apr 2020 14:09:01 GMT Connection: keep-alive ETag: "5e9efe7d-264" Accept-Ranges: bytes [root@k8s-master deployment]# kubectl rollout history deployment web deployment.apps/web REVISION CHANGE-CAUSE 1 web.v1-nginx-1.16 3 web.v1-nginx-1.19 4 web.v1-nginx-1.18
- 註釋:
- 發現已經回滾到nginx版本1.18版本
- 我們發現2的版本號,被4的版本號替換,3的版本號是1.19.5的nginx版本
- 註釋:
-
回滾到指定版本
[root@k8s-master deployment]# kubectl rollout undo deployment web --to-revision=3 deployment.apps/web rolled back [root@k8s-master deployment]# curl -I http://192.168.0.202:30082 HTTP/1.1 200 OK Server: nginx/1.19.5 Date: Tue, 01 Dec 2020 14:25:12 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Tue, 24 Nov 2020 13:02:03 GMT Connection: keep-alive ETag: "5fbd044b-264" Accept-Ranges: bytes [root@k8s-master deployment]# kubectl rollout history deployment web deployment.apps/web REVISION CHANGE-CAUSE 1 web.v1-nginx-1.16 4 web.v1-nginx-1.18 5 web.v1-nginx-1.19
- 註釋:在這裡,有沒有發現,我們上面的例項程式碼裡,進行配置後,版本號記錄更改,都有記錄