成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專(zhuān)欄INFORMATION COLUMN

k8s容器之deployment控制器鏡像更新

IT那活兒 / 2821人閱讀
k8s容器之deployment控制器鏡像更新

點(diǎn)擊上方“IT那活兒”,關(guān)注后了解更多內(nèi)容,不管IT什么活兒,干就完了?。?!



Deployment
  • 支持ReplicaSet的所有功能;
  • 支持發(fā)布的停止、繼續(xù);
  • 支持滾動(dòng)升級(jí)和回滾版本。



創(chuàng)建deployment
創(chuàng)建pc-deployment.yaml,內(nèi)容如下:
apiVersion: apps/v1
kind: Deployment
metadata:
 name: pc-deployment
 namespace: dev
spec:
 replicas: 3
 selector:
   matchLabels:
     app: nginx-pod
 template:
   metadata:
     labels:
       app: nginx-pod
   spec:
     containers:
     - name: nginx
       image: nginx:1.17.1
yaml
# 創(chuàng)建deployment:
[root@k8s-master01 ~]# kubectl create -f pc-deployment.yaml --record=true
deployment.apps/pc-deployment created
# 查看deployment;
# UP-TO-DATE 最新版本的pod的數(shù)量;
# AVAILABLE  當(dāng)前可用的pod的數(shù)量。
[root@k8s-master01 ~]# kubectl get deploy pc-deployment -n dev
NAME READY UP-TO-DATE AVAILABLE AGE
pc-deployment 3/3     3            3           15s
# 查看rs;
# 發(fā)現(xiàn)rs的名稱是在原來(lái)deployment的名字后面添加了一個(gè)10位數(shù)的隨機(jī)串。
[root@k8s-master01 ~]# kubectl get rs -n dev
NAME DESIRED CURRENT READY AGE
pc-deployment-6696798b78 3         3         3       23s
# 查看pod:
[root@k8s-master01 ~]# kubectl get pods -n dev
NAME READY STATUS RESTARTS AGE
pc-deployment-6696798b78-d2c8n 1/1     Running 0          107s
pc-deployment-6696798b78-smpvp 1/1     Running 0          107s
pc-deployment-6696798b78-wvjd8 1/1     Running 0          107s




擴(kuò)縮容
# 變更副本數(shù)量為5個(gè):
[root@k8s-master01 ~]# kubectl scale deploy pc-deployment --replicas=5  -n dev
deployment.apps/pc-deployment scaled
# 查看deployment:
[root@k8s-master01 ~]# kubectl get deploy pc-deployment -n dev
NAME READY UP-TO-DATE AVAILABLE AGE
pc-deployment 5/5     5            5           2m
# 查看pod:
[root@k8s-master01 ~]# kubectl get pods -n dev
NAME READY STATUS RESTARTS AGE
pc-deployment-6696798b78-d2c8n 1/1     Running 0          4m19s
pc-deployment-6696798b78-jxmdq 1/1     Running 0          94s
pc-deployment-6696798b78-mktqv 1/1     Running 0          93s
pc-deployment-6696798b78-smpvp 1/1     Running 0          4m19s
pc-deployment-6696798b78-wvjd8 1/1     Running 0          4m19s
# 編輯deployment的副本數(shù)量,修改spec:replicas: 4即可。
[root@k8s-master01 ~]# kubectl edit deploy pc-deployment -n dev
deployment.apps/pc-deployment edited
# 查看pod:
[root@k8s-master01 ~]# kubectl get pods -n dev
NAME READY STATUS RESTARTS AGE
pc-deployment-6696798b78-d2c8n 1/1     Running 0          5m23s
pc-deployment-6696798b78-jxmdq 1/1     Running 0          2m38s
pc-deployment-6696798b78-smpvp 1/1     Running 0          5m23s
pc-deployment-6696798b78-wvjd8 1/1     Running 0          5m23s




鏡像更新
deployment支持兩種更新策略:重建更新和滾動(dòng)更新,可以通過(guò)strategy指定策略類(lèi)型,支持兩個(gè)屬性:
1. 重建更新
編輯pc-deployment.yaml,在spec節(jié)點(diǎn)下添加更新策略:
apiVersion: apps/v1
kind: Deployment
metadata:
 name: pc-deployment
 namespace: dev
spec:
 strategy: # 策略
   type: Recreate # 重建更新
 replicas: 3
 selector:
   matchLabels:
     app: nginx-pod
 template:
   metadata:
     labels:
       app: nginx-pod
   spec:
     containers:
     - name: nginx
       image: nginx:1.17.1
yaml
# 變更鏡像:
[root@k8s-master01 ~]# kubectl set image deployment pc-deployment nginx=nginx:1.17.2 -n dev
deployment.apps/pc-deployment image updated
# 觀察升級(jí)過(guò)程:
[root@k8s-master01 ~]# kubectl get pods -n dev -w
NAME READY STATUS RESTARTS AGE
pc-deployment-5d89bdfbf9-65qcw 1/1     Running 0          31s
pc-deployment-5d89bdfbf9-w5nzv 1/1     Running 0          31s
pc-deployment-5d89bdfbf9-xpt7w 1/1     Running 0          31s

pc-deployment-5d89bdfbf9-xpt7w 1/1     Terminating 0          41s
pc-deployment-5d89bdfbf9-65qcw 1/1     Terminating 0          41s
pc-deployment-5d89bdfbf9-w5nzv 1/1     Terminating 0          41s

pc-deployment-675d469f8b-grn8z 0/1     Pending 0          0s
pc-deployment-675d469f8b-hbl4v 0/1     Pending 0          0s
pc-deployment-675d469f8b-67nz2 0/1     Pending 0          0s

pc-deployment-675d469f8b-grn8z 0/1     ContainerCreating 0          0s
pc-deployment-675d469f8b-hbl4v 0/1     ContainerCreating 0          0s
pc-deployment-675d469f8b-67nz2 0/1     ContainerCreating 0          0s

pc-deployment-675d469f8b-grn8z 1/1     Running 0          1s
pc-deployment-675d469f8b-67nz2 1/1     Running 0          1s
pc-deployment-675d469f8b-hbl4v 1/1     Running 0          2s


2. 滾動(dòng)更新
2.1 編輯pc-deployment.yaml,在spec節(jié)點(diǎn)下添加更新策略
apiVersion: apps/v1
kind: Deployment
metadata:
 name: pc-deployment
 namespace: dev
spec:
 strategy: # 策略
   type: RollingUpdate # 滾動(dòng)更新策略
   rollingUpdate:
     maxSurge: 25% 
     maxUnavailable: 25%
 replicas: 3
 selector:
   matchLabels:
     app: nginx-pod
 template:
   metadata:
     labels:
       app: nginx-pod
   spec:
     containers:
     - name: nginx
       image: nginx:1.17.2
yaml
2.2 創(chuàng)建deploy進(jìn)行驗(yàn)證
# 變更鏡像:
[root@k8s-master01 ~]# kubectl set image deployment pc-deployment nginx=nginx:1.17.3 -n dev 
deployment.apps/pc-deployment image updated
# 觀察升級(jí)過(guò)程:
[root@k8s-master01 ~]# kubectl get pods -n dev -w
NAME READY STATUS RESTARTS AGE
pc-deployment-c848d767-8rbzt 1/1     Running 0          31m
pc-deployment-c848d767-h4p68 1/1     Running 0          31m
pc-deployment-c848d767-hlmz4 1/1     Running 0          31m
pc-deployment-c848d767-rrqcn 1/1     Running 0          31m

pc-deployment-966bf7f44-226rx 0/1     Pending 0          0s
pc-deployment-966bf7f44-226rx 0/1     ContainerCreating 0          0s
pc-deployment-966bf7f44-226rx 1/1     Running 0          1s
pc-deployment-c848d767-h4p68 0/1     Terminating 0          34m

pc-deployment-966bf7f44-cnd44 0/1     Pending 0          0s
pc-deployment-966bf7f44-cnd44 0/1     ContainerCreating 0          0s
pc-deployment-966bf7f44-cnd44 1/1     Running 0          2s
pc-deployment-c848d767-hlmz4 0/1     Terminating 0          34m

pc-deployment-966bf7f44-px48p 0/1     Pending 0          0s
pc-deployment-966bf7f44-px48p 0/1     ContainerCreating 0          0s
pc-deployment-966bf7f44-px48p 1/1     Running 0          0s
pc-deployment-c848d767-8rbzt 0/1     Terminating 0          34m

pc-deployment-966bf7f44-dkmqp 0/1     Pending 0          0s
pc-deployment-966bf7f44-dkmqp 0/1     ContainerCreating 0          0s
pc-deployment-966bf7f44-dkmqp 1/1     Running 0          2s
pc-deployment-c848d767-rrqcn 0/1     Terminating 0          34m
# 至此,新版本的pod創(chuàng)建完畢,就版本的pod銷(xiāo)毀完畢。
# 中間過(guò)程是滾動(dòng)進(jìn)行的,也就是邊銷(xiāo)毀邊創(chuàng)建。
2.3 鏡像更新中rs的變化
# 查看rs,發(fā)現(xiàn)原來(lái)的rs的依舊存在,只是pod數(shù)量變?yōu)榱?,而后又新產(chǎn)生了一個(gè)rs,pod數(shù)量為4:
[root@k8s-master01 ~]# kubectl get rs -n dev
NAME DESIRED CURRENT READY AGE
pc-deployment-6696798b78 0         0         0       7m37s
pc-deployment-6696798b11 0         0         0       5m37s
pc-deployment-c848d76789 4         4         4       72s




版本回退
deployment支持版本升級(jí)過(guò)程中的暫停、繼續(xù)功能以及版本回退等諸多功能。
kubectl rollout:版本升級(jí)相關(guān)功能,支持下面的選項(xiàng):
  • status 顯示當(dāng)前升級(jí)狀態(tài);
  • history 顯示 升級(jí)歷史記錄;
  • pause 暫停版本升級(jí)過(guò)程;
  • resume 繼續(xù)已經(jīng)暫停的版本升級(jí)過(guò)程;
  • restart 重啟版本升級(jí)過(guò)程;
  • undo 回滾到上一級(jí)版本(可以使用--to-revision回滾到指定版本)。
# 重新創(chuàng)建deploy,--record  記錄deployment更新。
[root@master ~]# kubectl create -f pc-deployment.yaml --record
# 查看當(dāng)前升級(jí)版本的狀態(tài):
[root@k8s-master01 ~]# kubectl rollout status deploy pc-deployment -n dev
deployment "pc-deployment" successfully rolled out
# 查看升級(jí)歷史記錄:
[root@k8s-master01 ~]# kubectl rollout history deploy pc-deployment -n dev
deployment.apps/pc-deployment
REVISION CHANGE-CAUSE
1         kubectl create --filename=pc-deployment.yaml --record=true
2         kubectl create --filename=pc-deployment.yaml --record=true
3         kubectl create --filename=pc-deployment.yaml --record=true
# 可以發(fā)現(xiàn)有三次版本記錄,說(shuō)明完成過(guò)兩次升級(jí)。
# 版本回滾。
# 這里直接使用--to-revision=1回滾到了1版本, 如果省略這個(gè)選項(xiàng),就是回退到上個(gè)版本,就是2版本。
[root@k8s-master01 ~]# kubectl rollout undo deployment pc-deployment --to-revision=1 -n dev
deployment.apps/pc-deployment rolled back
# 查看發(fā)現(xiàn),通過(guò)nginx鏡像版本可以發(fā)現(xiàn)到了第一版。
[root@k8s-master01 ~]# kubectl get deploy -n dev -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES
pc-deployment 4/4     4            4           74m   nginx nginx:1.17.1
# 查看rs,發(fā)現(xiàn)第一個(gè)rs中有4個(gè)pod運(yùn)行,后面兩個(gè)版本的rs中pod為運(yùn)行。
# 其實(shí)deployment之所以可是實(shí)現(xiàn)版本的回滾,就是通過(guò)記錄下歷史rs來(lái)實(shí)現(xiàn)的。
# 一旦想回滾到哪個(gè)版本,只需要將當(dāng)前版本pod數(shù)量降為0,然后將回滾版本的pod提升為目標(biāo)數(shù)量就可以了。
[root@k8s-master01 ~]# kubectl get rs -n dev
NAME DESIRED CURRENT READY AGE
pc-deployment-6696798b78 4         4         4       78m
pc-deployment-966bf7f44 0         0         0       37m
pc-deployment-c848d767 0         0         0       71m




金絲雀發(fā)布(灰度發(fā)布)
Deployment控制器支持控制更新過(guò)程中的控制,如“暫停(pause)”或“繼續(xù)(resume)”更新操作。
# 更新deployment的版本,并配置暫停deployment:
[root@k8s-master01 ~]# kubectl set image deploy pc-deployment nginx=nginx:1.17.4 -n dev && kubectl rollout pause deployment pc-deployment -n dev
deployment.apps/pc-deployment image updated
deployment.apps/pc-deployment paused
#觀察更新?tīng)顟B(tài):
[root@k8s-master01 ~]# kubectl rollout status deploy pc-deployment -n dev 
Waiting for deployment "pc-deployment" rollout to finish: 2 out of 4 new replicas have been updated...
# 監(jiān)控更新的過(guò)程,可以看到已經(jīng)新增了一個(gè)資源,但是并未按照預(yù)期的狀態(tài)去刪除一個(gè)舊的資源,就是因?yàn)槭褂昧藀ause暫停命令。
[root@k8s-master01 ~]# kubectl get rs -n dev -o wide
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES
pc-deployment-5d89bdfbf9 3         3         3       19m     nginx nginx:1.17.1   
pc-deployment-675d469f8b 0         0         0       14m     nginx nginx:1.17.2   
pc-deployment-6c9f56fcfb 2         2         2       3m16s nginx nginx:1.17.4   
[root@k8s-master01 ~]# kubectl get pods -n dev
NAME READY STATUS RESTARTS AGE
pc-deployment-5d89bdfbf9-rj8sq 1/1     Running 0          7m33s
pc-deployment-5d89bdfbf9-ttwgg 1/1     Running 0          7m35s
pc-deployment-5d89bdfbf9-v4wvc 1/1     Running 0          7m34s
pc-deployment-6c9f56fcfb-996rt 1/1     Running 0          3m31s
pc-deployment-6c9f56fcfb-j2gtj 1/1     Running 0          3m31s
# 確保更新的pod沒(méi)問(wèn)題了,繼續(xù)更新:
[root@k8s-master01 ~]# kubectl rollout resume deploy pc-deployment -n dev
deployment.apps/pc-deployment resumed
# 查看最后的更新情況:
[root@k8s-master01 ~]# kubectl get rs -n dev -o wide
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES
pc-deployment-5d89bdfbf9 0         0         0       21m     nginx nginx:1.17.1   
pc-deployment-675d469f8b 0         0         0       16m     nginx nginx:1.17.2   
pc-deployment-6c9f56fcfb 4         4         4       5m11s nginx nginx:1.17.4   

[root@k8s-master01 ~]# kubectl get pods -n dev
NAME READY STATUS RESTARTS AGE
pc-deployment-6c9f56fcfb-7bfwh 1/1     Running 0          37s
pc-deployment-6c9f56fcfb-996rt 1/1     Running 0          5m27s
pc-deployment-6c9f56fcfb-j2gtj 1/1     Running 0          5m27s
pc-deployment-6c9f56fcfb-rf84v 1/1     Running 0          37s






本文作者:劉川陵

本文來(lái)源:IT那活兒(上海新炬王翦團(tuán)隊(duì))

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/129554.html

相關(guān)文章

  • kubernetes學(xué)習(xí)

    摘要:知識(shí)點(diǎn)核心組件保存整個(gè)集群的狀態(tài)信息,感覺(jué)相當(dāng)于的數(shù)據(jù)庫(kù)提供對(duì)資源操作的唯一入口,并提供認(rèn)證授權(quán),訪問(wèn)控制,注冊(cè)與發(fā)現(xiàn)等機(jī)制負(fù)責(zé)維護(hù)集群的狀態(tài),故障檢測(cè),自動(dòng)擴(kuò)展,滾動(dòng)更新等負(fù)責(zé)對(duì)資源的調(diào)度,按著預(yù)定的調(diào)度策略將調(diào)度到相應(yīng)的集群上負(fù)責(zé)維護(hù)容 kubernetes kubernetes 知識(shí)點(diǎn) 1. 核心組件 etcd 保存整個(gè)集群的狀態(tài)信息,感覺(jué)相當(dāng)于k8s的數(shù)據(jù)庫(kù) apiserve...

    lncwwn 評(píng)論0 收藏0
  • kubernetes學(xué)習(xí)

    摘要:知識(shí)點(diǎn)核心組件保存整個(gè)集群的狀態(tài)信息,感覺(jué)相當(dāng)于的數(shù)據(jù)庫(kù)提供對(duì)資源操作的唯一入口,并提供認(rèn)證授權(quán),訪問(wèn)控制,注冊(cè)與發(fā)現(xiàn)等機(jī)制負(fù)責(zé)維護(hù)集群的狀態(tài),故障檢測(cè),自動(dòng)擴(kuò)展,滾動(dòng)更新等負(fù)責(zé)對(duì)資源的調(diào)度,按著預(yù)定的調(diào)度策略將調(diào)度到相應(yīng)的集群上負(fù)責(zé)維護(hù)容 kubernetes kubernetes 知識(shí)點(diǎn) 1. 核心組件 etcd 保存整個(gè)集群的狀態(tài)信息,感覺(jué)相當(dāng)于k8s的數(shù)據(jù)庫(kù) apiserve...

    jayce 評(píng)論0 收藏0
  • 初試k8s,通過(guò)rancher自頂向下的學(xué)習(xí)kubernetes

    摘要:下面我想介紹另一種學(xué)習(xí)思路,自頂向下的學(xué)習(xí)。是通過(guò)虛擬機(jī)創(chuàng)建集群,支持多種虛擬機(jī),我這里用的。對(duì)內(nèi)或?qū)ν獗┞斗?wù)。和的控制器,通過(guò)配置的規(guī)則來(lái)管理。三個(gè)主要的命令行程序用了啟動(dòng)集群。需要在所以節(jié)點(diǎn)上運(yùn)行,處理集群內(nèi)部通訊,類(lèi)似。 之前就玩過(guò)docker,但是一直不知道怎么把容器運(yùn)用到生產(chǎn)上。構(gòu)建一個(gè)docker鏡像,把他run起來(lái)很簡(jiǎn)單;難的是容器的部署(CICD),容器的網(wǎng)絡(luò),數(shù)據(jù)持...

    marser 評(píng)論0 收藏0
  • 初試k8s,通過(guò)rancher自頂向下的學(xué)習(xí)kubernetes

    摘要:下面我想介紹另一種學(xué)習(xí)思路,自頂向下的學(xué)習(xí)。是通過(guò)虛擬機(jī)創(chuàng)建集群,支持多種虛擬機(jī),我這里用的。對(duì)內(nèi)或?qū)ν獗┞斗?wù)。和的控制器,通過(guò)配置的規(guī)則來(lái)管理。三個(gè)主要的命令行程序用了啟動(dòng)集群。需要在所以節(jié)點(diǎn)上運(yùn)行,處理集群內(nèi)部通訊,類(lèi)似。 之前就玩過(guò)docker,但是一直不知道怎么把容器運(yùn)用到生產(chǎn)上。構(gòu)建一個(gè)docker鏡像,把他run起來(lái)很簡(jiǎn)單;難的是容器的部署(CICD),容器的網(wǎng)絡(luò),數(shù)據(jù)持...

    tinyq 評(píng)論0 收藏0
  • 初試k8s,通過(guò)rancher自頂向下的學(xué)習(xí)kubernetes

    摘要:下面我想介紹另一種學(xué)習(xí)思路,自頂向下的學(xué)習(xí)。是通過(guò)虛擬機(jī)創(chuàng)建集群,支持多種虛擬機(jī),我這里用的。對(duì)內(nèi)或?qū)ν獗┞斗?wù)。和的控制器,通過(guò)配置的規(guī)則來(lái)管理。三個(gè)主要的命令行程序用了啟動(dòng)集群。需要在所以節(jié)點(diǎn)上運(yùn)行,處理集群內(nèi)部通訊,類(lèi)似。 之前就玩過(guò)docker,但是一直不知道怎么把容器運(yùn)用到生產(chǎn)上。構(gòu)建一個(gè)docker鏡像,把他run起來(lái)很簡(jiǎn)單;難的是容器的部署(CICD),容器的網(wǎng)絡(luò),數(shù)據(jù)持...

    jemygraw 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<