91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

k8s之滾動更新(Rolling Update)與回滾

發布時間:2020-08-05 21:06:33 來源:網絡 閱讀:815 作者:wuseeger 欄目:系統運維
滾動更新

滾動更新是一次只更新一小部分副本,成功后,再更新更多的副本,最終完成所有副本的更新。滾動更新的最大的好處是零停機,整個更新過程始終有副本在運行,從而保證了業務的連續性。

下面我們部署三副本應用,初始鏡像為 httpd:2.2.31,然后將其更新到 httpd:2.2.32。

httpd:2.2.31 的配置文件如下:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: httpd
spec:
  replicas: 3
  template:
    metadata:
      labels:
        run: httpd
    spec:
      containers:
      - name: httpd
        image: httpd:2.2.31
        ports:
        - containerPort: 80

通過 kubectl apply 部署。

[root@k8s-master ~]# kubectl apply -f httpd.yml 
deployment.apps/httpd created
[root@k8s-master ~]# 
[root@k8s-master ~]# kubectl get deployments httpd -o wide
NAME    READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES         SELECTOR
httpd   0/3     3            0           14s   httpd        httpd:2.2.31   run=httpd
[root@k8s-master ~]# kubectl get replicasets -o wide
NAME               DESIRED   CURRENT   READY   AGE   CONTAINERS   IMAGES         SELECTOR
httpd-56df754d56   3         3         3       37s   httpd        httpd:2.2.31   pod-template-hash=56df754d56,run=httpd
[root@k8s-master ~]# kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
httpd-56df754d56-5hjt6   1/1     Running   0          52s
httpd-56df754d56-ngw9l   1/1     Running   0          52s
httpd-56df754d56-qtgbt   1/1     Running   0          52s

部署過程如下:

  1. 創建 Deployment httpd
  2. 創建 ReplicaSet httpd-551879778
  3. 創建三個 Pod
  4. 當前鏡像為 httpd:2.2.31

將配置文件中 httpd:2.2.31 替換為 httpd:2.2.32,再次執行 kubectl apply。

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: httpd
spec:
  replicas: 3
  template:
    metadata:
      labels:
        run: httpd
    spec:
      containers:
      - name: httpd
        image: httpd:2.2.32
        ports:
        - containerPort: 80
[root@k8s-master ~]# kubectl apply -f httpd.yml 
deployment.apps/httpd configured
[root@k8s-master ~]# 
[root@k8s-master ~]# kubectl get deployments httpd -o wide
NAME    READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS   IMAGES         SELECTOR
httpd   3/3     1            3           3m54s   httpd        httpd:2.2.32   run=httpd
[root@k8s-master ~]# kubectl get replicasets -o wide
NAME               DESIRED   CURRENT   READY   AGE    CONTAINERS   IMAGES         SELECTOR
httpd-56df754d56   2         2         2       4m8s   httpd        httpd:2.2.31   pod-template-hash=56df754d56,run=httpd
httpd-77896d99b5   2         2         1       28s    httpd        httpd:2.2.32   pod-template-hash=77896d99b5,run=httpd
[root@k8s-master ~]# 
[root@k8s-master ~]# kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
httpd-77896d99b5-pk52m   1/1     Running   0          24s
httpd-77896d99b5-pmlr9   1/1     Running   0          40s
httpd-77896d99b5-spn96   1/1     Running   0          9s

我們發現了如下變化:

  1. Deployment httpd 的鏡像更新為 httpd:2.2.32
  2. 新創建了 ReplicaSet httpd-1276601241,鏡像為 httpd:2.2.32,并且管理了三個新的 Pod。
  3. 之前的 ReplicaSet httpd-551879778 里面已經沒有任何 Pod。

結論是:ReplicaSet httpd-551879778 的三個 httpd:2.2.31 Pod 已經被 ReplicaSet httpd-1276601241 的三個 httpd:2.2.32 Pod 替換了。

具體過程可以通過 kubectl describe deployment httpd 查看。

Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  6m4s   deployment-controller  Scaled up replica set httpd-56df754d56 to 3
  Normal  ScalingReplicaSet  2m23s  deployment-controller  Scaled up replica set httpd-77896d99b5 to 1
  Normal  ScalingReplicaSet  2m7s   deployment-controller  Scaled down replica set httpd-56df754d56 to 2
  Normal  ScalingReplicaSet  2m7s   deployment-controller  Scaled up replica set httpd-77896d99b5 to 2
  Normal  ScalingReplicaSet  112s   deployment-controller  Scaled down replica set httpd-56df754d56 to 1
  Normal  ScalingReplicaSet  112s   deployment-controller  Scaled up replica set httpd-77896d99b5 to 3
  Normal  ScalingReplicaSet  110s   deployment-controller  Scaled down replica set httpd-56df754d56 to 0

每次只更新替換一個 Pod:

  1. ReplicaSet httpd-1276601241 增加一個 Pod,總數為 1。
  2. ReplicaSet httpd-551879778 減少一個 Pod,總數為 2。
  3. ReplicaSet httpd-1276601241 增加一個 Pod,總數為 2。
  4. ReplicaSet httpd-551879778 減少一個 Pod,總數為 1。
  5. ReplicaSet httpd-1276601241 增加一個 Pod,總數為 3。
  6. ReplicaSet httpd-551879778 減少一個 Pod,總數為 0。

每次替換的 Pod 數量是可以定制的。Kubernetes 提供了兩個參數 maxSurge 和 maxUnavailable 來精細控制 Pod 的替換數量,我們將在后面結合 Health Check 特性一起討論。

回滾

kubectl apply 每次更新應用時 Kubernetes 都會記錄下當前的配置,保存為一個 revision(版次),這樣就可以回滾到某個特定 revision。

默認配置下,Kubernetes 只會保留最近的幾個 revision,可以在 Deployment 配置文件中通過 revisionHistoryLimit 屬性增加 revision 數量。

下面實踐回滾功能。應用有如下三個配置文件 httpd.v1.yml,httpd.v2.yml 和 httpd.v3.yml,分別對應不同的 httpd 鏡像 2.4.16,2.4.17 和 2.4.18:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: httpd
spec:
  revisionHistoryLimit: 10
  replicas: 3
  template:
    metadata:
      labels:
        run: httpd
    spec:
      containers:
      - name: httpd
        image: httpd:2.4.16
        ports:
        - containerPort: 80
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: httpd
spec:
  revisionHistoryLimit: 10
  replicas: 3
  template:
    metadata:
      labels:
        run: httpd
    spec:
      containers:
      - name: httpd
        image: httpd:2.4.17
        ports:
        - containerPort: 80
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: httpd
spec:
  revisionHistoryLimit: 10
  replicas: 3
  template:
    metadata:
      labels:
        run: httpd
    spec:
      containers:
      - name: httpd
        image: httpd:2.4.18
        ports:
        - containerPort: 80

通過 kubectl apply 部署并更新應用:

[root@k8s-master ~]# kubectl apply -f httpd.v1.yml --record 
deployment.apps/httpd created
[root@k8s-master ~]# kubectl get deployments httpd -o wide
NAME    READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES         SELECTOR
httpd   3/3     3            3           36s   httpd        httpd:2.4.16   run=httpd
[root@k8s-master ~]# kubectl apply -f httpd.v2.yml --record  
deployment.apps/httpd configured
[root@k8s-master ~]# kubectl get deployments httpd -o wide  
NAME    READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS   IMAGES         SELECTOR
httpd   3/3     1            3           2m24s   httpd        httpd:2.4.17   run=httpd
[root@k8s-master ~]# kubectl apply -f httpd.v3.yml --record  
deployment.apps/httpd configured
[root@k8s-master ~]# kubectl get deployments httpd -o wide  
NAME    READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS   IMAGES         SELECTOR
httpd   3/3     1            3           2m43s   httpd        httpd:2.4.18   run=httpd

--record 的作用是將當前命令記錄到 revision 記錄中,這樣我們就可以知道每個 revison 對應的是哪個配置文件。通過 kubectl rollout history deployment httpd 查看 revison 歷史記錄。

[root@k8s-master ~]# kubectl rollout history deployment httpd 
deployment.extensions/httpd 
REVISION  CHANGE-CAUSE
1         kubectl apply --filename=httpd.v1.yml --record=true
2         kubectl apply --filename=httpd.v2.yml --record=true
3         kubectl apply --filename=httpd.v3.yml --record=true

CHANGE-CAUSE 就是 --record 的結果。如果要回滾到某個版本,比如 revision 1,可以執行命令 kubectl rollout undo deployment httpd --to-revision=1:

[root@k8s-master ~]# kubectl rollout undo deployment httpd --to-revision=1
deployment.extensions/httpd rolled back
[root@k8s-master ~]# kubectl get deployments. httpd -o wide
NAME    READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS   IMAGES         SELECTOR
httpd   3/3     3            3           6m50s   httpd        httpd:2.4.16   run=httpd

此時,revison 歷史記錄也會發生相應變化。

[root@k8s-master ~]# kubectl rollout history deployment httpd    deployment.extensions/httpd 
REVISION  CHANGE-CAUSE
2         kubectl apply --filename=httpd.v2.yml --record=true
3         kubectl apply --filename=httpd.v3.yml --record=true
4         kubectl apply --filename=httpd.v1.yml --record=true

revison 1 變成了 revison 4。不過我們可以通過 CHANGE-CAUSE 知道每個 revison 的具體含義。所以一定要在執行 kubectl apply 時加上 --record參數。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

积石山| 儋州市| 天长市| 陇川县| 宁都县| 鹤山市| 云和县| 泰顺县| 体育| 营山县| 黄龙县| 安阳县| 穆棱市| 游戏| 武隆县| 通河县| 岑巩县| 慈溪市| 苍山县| 古浪县| 神池县| 古丈县| 红原县| 西宁市| 兰坪| 工布江达县| 舟曲县| 喀什市| 紫云| 西和县| 青海省| 云南省| 宜昌市| 无锡市| 顺义区| 康保县| 安仁县| 宁晋县| 宜川县| 安庆市| 伊宁市|