溫馨提示×

溫馨提示×

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

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

kubernetes 控制器

發(fā)布時間:2020-07-09 08:50:15 來源:網(wǎng)絡(luò) 閱讀:232 作者:wx5a98a78793203 欄目:系統(tǒng)運維

1.基礎(chǔ)

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

2.滾動升級

vim de.yaml #修改yaml里的鏡像版本
kubernetes 控制器

 apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deploy
  namespace: default
spec:
  replicas: 5
  selector:
    matchLabels:
      app: myapp
      release: dev
  strategy:
    rollingUpdate:
    #設(shè)置策略為滾動更新,還有一個重建更新,全部一起結(jié)束一起新建 不友好這里就不介紹了
      maxSurge: 1
      #最大可超出預(yù)設(shè)值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 #使用命令查看
kubernetes 控制器
可以看到當(dāng)前鏡像版本已經(jīng)換成了v2 且模板也變了,之前的v1版本還保這方便回滾,yaml文件內(nèi)容修改一次就會當(dāng)做一次更新,最后一串?dāng)?shù)字就是通過yaml文件計算出來的
注意: deployment的pod模板被更改時才會創(chuàng)建新的修訂版本,例如更新模板標(biāo)簽或者容器鏡像可以觸發(fā)滾動更新, 其它操作例如擴展副本數(shù)將不會觸發(fā)deployment的更新操作

金絲雀發(fā)布

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"
#原理就是先升級一個容器的版本,執(zhí)行pause 暫停升級任務(wù),待升級的那個容器經(jīng)過真實用戶測試后無錯后解除暫停
kubernetes 控制器
kubectl get rs -o wide #查看控制器能看到,有1個v3版,5個v2版本,出現(xiàn)6個的原因是我滾動策略定義了升級可允許存在6個
kubectl rollout resume deploy myapp-deploy
#解除暫停
kubernetes 控制器
#解除暫停后能看到,v2版本在一點點的關(guān)閉向v3版轉(zhuǎn)移,最終v2全部關(guān)閉,v3版5個容器全部正常上線

回滾

 kubectl rollout history deployment/nginx-deployment
 #查看升級歷史記錄
 kubectl rollout history deployment/nginx-deployment --revision=2
 #查看某個升級歷史記錄的的詳細(xì)信息
kubectl rollout undo deployment/nginx-deployment
#回滾到上一個版本
kubectl rollout undo deployment/nginx-deployment --to-revision=2
#回滾到指定版本
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI