真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Kubernetes的RollingUpdate實(shí)戰(zhàn)

一.背景

隨著Kubernetes的進(jìn)一步深入使用,我們越來越體會到它給我們的工作帶來的高效與便利。Rolling Update是Kubernetes系統(tǒng)中的一個(gè)強(qiáng)大的功能,能夠?yàn)槲覀兊倪\(yùn)維工作帶來極大的便利。

成都創(chuàng)新互聯(lián)于2013年開始,先為鹽都等服務(wù)建站,鹽都等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為鹽都企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

二.步驟

2.1 部署最初始版本Deployment。

初始Deployment的YAML如下:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: deployment-rollout
spec:
  replicas: 4
  template:
    metadata:
      labels:
        test: httpd
    spec:
      containers:
      - name: httpd-rollout-test
        image: httpd:2.2.31
        ports:
        - containerPort: 80

執(zhí)行命令:

[root@k8s-m ~]# kubectl get deployment -o wide
NAME                 DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE    CONTAINERS           IMAGES         SELECTOR
deployment-rollout   4         4         4            4           107s   httpd-rollout-test   httpd:2.2.31   test=httpd
[root@k8s-m ~]# kubectl get replicaset -o wide
NAME                            DESIRED   CURRENT   READY   AGE    CONTAINERS           IMAGES         SELECTOR
deployment-rollout-5fb9c69c5c   4         4         4       116s   httpd-rollout-test   httpd:2.2.31   pod-template-hash=5fb9c69c5c,test=httpd

2.2 將初始版本升級。

升級到2.4.31,YAML如下:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: deployment-rollout
spec:
  revisionHistoryLimit: 10
  replicas: 4
  template:
    metadata:
      labels:
        test: httpd
    spec:
      containers:
      - name: httpd-rollout-test
        image: httpd:2.4.33
        ports:
        - containerPort: 80

執(zhí)行命令:

[root@k8s-m ~]# kubectl apply -f Httpd-Deployment-rollout-v1.yaml
deployment.apps/deployment-rollout configured
[root@k8s-m ~]# kubectl get deployment -o wide
NAME                 DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS           IMAGES         SELECTOR
deployment-rollout   4         5         2            3           3m57s   httpd-rollout-test   httpd:2.4.33   test=httpd
[root@k8s-m ~]# kubectl get replicaset -o wide
NAME                            DESIRED   CURRENT   READY   AGE     CONTAINERS           IMAGES         SELECTOR
deployment-rollout-54766f574f   2         2         0       93s     httpd-rollout-test   httpd:2.4.33   pod-template-hash=54766f574f,test=httpd
deployment-rollout-5fb9c69c5c   3         3         3       4m12s   httpd-rollout-test   httpd:2.2.31   pod-template-hash=5fb9c69c5c,test=httpd
[root@k8s-m ~]# kubectl get pod -o wide
NAME                                  READY   STATUS              RESTARTS   AGE     IP             NODE     NOMINATED NODE
deployment-rollout-54766f574f-668pc   0/1     ContainerCreating   0          114s             k8s-n1   
deployment-rollout-54766f574f-ssz67   0/1     ContainerCreating   0          115s             k8s-n2   
deployment-rollout-5fb9c69c5c-m5dvs   1/1     Running             0          4m34s   10.244.2.47    k8s-n2   
deployment-rollout-5fb9c69c5c-p9grr   1/1     Running             0          4m34s   10.244.1.113   k8s-n1   
deployment-rollout-5fb9c69c5c-tzm7w   1/1     Running             0          4m34s   10.244.2.48    k8s-n2   

一會兒后再觀察一下:

[root@k8s-m ~]# kubectl get replicaset -o wide
NAME                            DESIRED   CURRENT   READY   AGE     CONTAINERS           IMAGES         SELECTOR
deployment-rollout-54766f574f   4         4         4       4m24s   httpd-rollout-test   httpd:2.4.33   pod-template-hash=54766f574f,test=httpd
deployment-rollout-5fb9c69c5c   0         0         0       7m3s    httpd-rollout-test   httpd:2.2.31   pod-template-hash=5fb9c69c5c,test=httpd
[root@k8s-m ~]# kubectl get deployment -o wide
NAME                 DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS           IMAGES         SELECTOR
deployment-rollout   4         4         4            4           7m18s   httpd-rollout-test   httpd:2.4.33   test=httpd
[root@k8s-m ~]# kubectl get pod -o wide
NAME                                  READY   STATUS    RESTARTS   AGE     IP             NODE     NOMINATED NODE
deployment-rollout-54766f574f-668pc   1/1     Running   0          4m48s   10.244.1.114   k8s-n1   
deployment-rollout-54766f574f-h7gf9   1/1     Running   0          99s     10.244.2.50    k8s-n2   
deployment-rollout-54766f574f-ssz67   1/1     Running   0          4m49s   10.244.2.49    k8s-n2   
deployment-rollout-54766f574f-vklvr   1/1     Running   0          41s     10.244.1.115   k8s-n1   

在此過程中,我們會發(fā)現(xiàn),ReplicaSet deployment-rollout-5fb9c69c5c逐步被deployment-rollout-54766f574f取代,創(chuàng)建新版本的Pod之后,原始版本的Pod被終止。這是一個(gè)平滑的升級過程。Kubernetes提供了兩個(gè)參數(shù)maxSurge和maxUnavailable來精細(xì)控制Pod的替換數(shù)量。

2.3 版本的回滾。

默認(rèn)情況下,Kubernetes只會保留最近幾個(gè)revision。在上面的升級過程中,通過revisionHistoryLimit設(shè)置了revision的數(shù)量。我們通過命令來看一下:

[root@k8s-m ~]# kubectl rollout history deployment deployment-rollout
deployment.extensions/deployment-rollout
REVISION  CHANGE-CAUSE
1         
2         

繼續(xù)升級。新版的YAML如下:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: deployment-rollout
spec:
  revisionHistoryLimit: 10
  replicas: 4
  template:
    metadata:
      labels:
        test: httpd
    spec:
      containers:
      - name: httpd-rollout-test
        image: httpd:2.4.34
        ports:
        - containerPort: 80

執(zhí)行升級并記錄升級日志。

[root@k8s-m ~]# kubectl apply -f Httpd-Deployment-rollout-v2.yaml --record
deployment.apps/deployment-rollout configured
[root@k8s-m ~]# kubectl rollout history deployment deployment-rollout
deployment.extensions/deployment-rollout
REVISION  CHANGE-CAUSE
1         
2         
3         kubectl apply --filename=Httpd-Deployment-rollout-v2.yaml --record=true
[root@k8s-m ~]# kubectl get deployment deployment-rollout -o wide
NAME                 DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS           IMAGES         SELECTOR
deployment-rollout   4         4         4            4           31m   httpd-rollout-test   httpd:2.4.34   test=httpd
[root@k8s-m ~]# kubectl get replicaset -o wide
NAME                            DESIRED   CURRENT   READY   AGE     CONTAINERS           IMAGES         SELECTOR
deployment-rollout-54766f574f   0         0         0       29m     httpd-rollout-test   httpd:2.4.33   pod-template-hash=54766f574f,test=httpd
deployment-rollout-54fc66bb6    4         4         4       6m12s   httpd-rollout-test   httpd:2.4.34   pod-template-hash=54fc66bb6,test=httpd
deployment-rollout-5fb9c69c5c   0         0         0       32m     httpd-rollout-test   httpd:2.2.31   pod-template-hash=5fb9c69c5c,test=httpd
[root@k8s-m ~]# kubectl get pod -o wide
NAME                                 READY   STATUS    RESTARTS   AGE     IP             NODE     NOMINATED NODE
deployment-rollout-54fc66bb6-2zvhk   1/1     Running   0          6m26s   10.244.1.116   k8s-n1   
deployment-rollout-54fc66bb6-7rsj6   1/1     Running   0          4m16s   10.244.1.117   k8s-n1   
deployment-rollout-54fc66bb6-nlx4h   1/1     Running   0          6m26s   10.244.2.51    k8s-n2   
deployment-rollout-54fc66bb6-xxnrg   1/1     Running   0          6m24s   10.244.2.52    k8s-n2   

修改YAML文件中鏡像的版本繼續(xù)升級,觀察升級結(jié)果:

[root@k8s-m ~]# kubectl rollout history deployment deployment-rollout
deployment.extensions/deployment-rollout
REVISION  CHANGE-CAUSE
1         
2         
3         kubectl apply --filename=Httpd-Deployment-rollout-v2.yaml --record=true
4         kubectl apply --filename=Httpd-Deployment-rollout-v3.yaml --record=true

[root@k8s-m ~]# kubectl get replicaset -o wide
NAME                            DESIRED   CURRENT   READY   AGE     CONTAINERS           IMAGES         SELECTOR
deployment-rollout-54766f574f   0         0         0       33m     httpd-rollout-test   httpd:2.4.33   pod-template-hash=54766f574f,test=httpd
deployment-rollout-54fc66bb6    0         0         0       10m     httpd-rollout-test   httpd:2.4.34   pod-template-hash=54fc66bb6,test=httpd
deployment-rollout-5b99bbfbbc   4         4         4       2m33s   httpd-rollout-test   httpd:2.4.35   pod-template-hash=5b99bbfbbc,test=httpd
deployment-rollout-5fb9c69c5c   0         0         0       36m     httpd-rollout-test   httpd:2.2.31   pod-template-hash=5fb9c69c5c,test=httpd
[root@k8s-m ~]# kubectl get pod -o wide
NAME                                  READY   STATUS    RESTARTS   AGE     IP             NODE     NOMINATED NODE
deployment-rollout-5b99bbfbbc-7mdg9   1/1     Running   0          65s     10.244.1.119   k8s-n1   
deployment-rollout-5b99bbfbbc-9mfbk   1/1     Running   0          2m40s   10.244.1.118   k8s-n1   
deployment-rollout-5b99bbfbbc-jn5sb   1/1     Running   0          2m40s   10.244.2.53    k8s-n2   
deployment-rollout-5b99bbfbbc-tr6t2   1/1     Running   0          2m38s   10.244.2.54    k8s-n2   

httpd的image均已經(jīng)升級到2.4.35,接下來我們試一下回滾到v2版本:

[root@k8s-m ~]# kubectl rollout undo deployment deployment-rollout --to-revision=3
deployment.extensions/deployment-rollout
[root@k8s-m ~]# kubectl get deployment -o wide
NAME                 DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS           IMAGES         SELECTOR
deployment-rollout   4         4         4            4           42m   httpd-rollout-test   httpd:2.4.34   test=httpd
[root@k8s-m ~]# kubectl get replicaset -o wide
NAME                            DESIRED   CURRENT   READY   AGE     CONTAINERS           IMAGES         SELECTOR
deployment-rollout-54766f574f   0         0         0       39m     httpd-rollout-test   httpd:2.4.33   pod-template-hash=54766f574f,test=httpd
deployment-rollout-54fc66bb6    4         4         4       16m     httpd-rollout-test   httpd:2.4.34   pod-template-hash=54fc66bb6,test=httpd
deployment-rollout-5b99bbfbbc   0         0         0       8m35s   httpd-rollout-test   httpd:2.4.35   pod-template-hash=5b99bbfbbc,test=httpd
deployment-rollout-5fb9c69c5c   0         0         0       42m     httpd-rollout-test   httpd:2.2.31   pod-template-hash=5fb9c69c5c,test=httpd
[root@k8s-m ~]# kubectl get pod -o wide
NAME                                 READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE
deployment-rollout-54fc66bb6-bjskn   1/1     Running   0          68s   10.244.1.121   k8s-n1   
deployment-rollout-54fc66bb6-c65th   1/1     Running   0          70s   10.244.2.55    k8s-n2   
deployment-rollout-54fc66bb6-cwpbk   1/1     Running   0          70s   10.244.1.120   k8s-n1   
deployment-rollout-54fc66bb6-lz9xt   1/1     Running   0          68s   10.244.2.56    k8s-n2   
[root@k8s-m ~]# kubectl rollout history deployment deployment-rollout
deployment.extensions/deployment-rollout
REVISION  CHANGE-CAUSE
1         
2         
4         kubectl apply --filename=Httpd-Deployment-rollout-v3.yaml --record=true
5         kubectl apply --filename=Httpd-Deployment-rollout-v2.yaml --record=true

每次升級或回滾操作之后REVISION的數(shù)字都會增加1。通過kubectl history,我們可以看到每次升級記錄,--record記錄了每次操作的詳細(xì)過程。通過kubectl undo執(zhí)行回滾操作,選項(xiàng)--to-revision指定了回滾的修訂版本號。

三.總結(jié)

3.1. 再次被Kubernetes的魅力所折服,平常工作中的灰度升級/發(fā)布/更新(按批次停止老版本實(shí)例,啟用新版本實(shí)例,新老版本共存,逐步擴(kuò)大新版本范圍,最終把所有用戶遷移到新版本上),藍(lán)綠升級/發(fā)布/更新(不停止老版本,另外部署一套新版本,新版本通過測試發(fā)布后刪除老版本),滾動升級/發(fā)布/更新(一個(gè)或多個(gè)服務(wù)停止,執(zhí)行更新,逐步將新版本投入使用,周而復(fù)始,最終完成整個(gè)集群中所有實(shí)例的版本更新)這些概念理解更加透徹。

3.2. 目前有些資料已經(jīng)不適用于新版本了,不要被網(wǎng)上的資料所誤導(dǎo),一定要立足與官方文檔和系統(tǒng)幫助。例如:

Kubernetes 的Deploy相關(guān)的命令只有:

Deploy Commands:
  rollout        Manage the rollout of a resource
  scale          為 Deployment, ReplicaSet, Replication Controller 或者 Job 設(shè)置一個(gè)新的副本數(shù)量
  autoscale      自動調(diào)整一個(gè) Deployment, ReplicaSet, 或者 ReplicationController 的副本數(shù)量

Rollout可用資源類型:

Valid resource types include:
  * deployments
  * daemonsets
  * statefulsets

3.3 Rollout updat也可以通過YAML來實(shí)現(xiàn),后續(xù)文章會介紹。

四.相關(guān)資料

4.1 本文相關(guān)的yaml文件

4.2 官方資料


文章名稱:Kubernetes的RollingUpdate實(shí)戰(zhàn)
文章出自:http://weahome.cn/article/jhcohd.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部