kubernetes 學習筆記3

kubernetes  自動發佈和回滾

deployment 引入的目的是爲了更好的解決pod的編排問題。
 
  • 建立一個deployment對象來生成對應的replica set 並完成 pod副本的建立過程
  • 檢查deployment的狀態來看部署動做是否完成(pod副本的數量是否達到預期的值)
  • 更新deployment以建立新的pod(好比鏡像升級)
  • 若是當前deployment不穩定,則回滾至一個早先的deployment版本
建立deployment
$ kubectl create -f docs/user-guide/nginx-deployment.yaml --record
deployment "nginx-deployment」 created
查看正在建立或者正在更新的deplyment
$ kubectl get deployments
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3         0         0            0           1s
$ kubectl get deployments
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3         3         3            3           18s
查看replica set 和 pod
$ kubectl get rs
NAME                          DESIRED   CURRENT   AGE
nginx-deployment-2035384211   3         3         18s
查看生成的各個pod的歸屬關係
$ kubectl get pods --show-labels
NAME                                READY     STATUS    RESTARTS   AGE       LABELS
nginx-deployment-2035384211-7ci7o   1/1       Running   0          18s       app=nginx,pod-template-hash=2035384211
nginx-deployment-2035384211-kzszj   1/1       Running   0          18s       app=nginx,pod-template-hash=2035384211
nginx-deployment-2035384211-qqcnn   1/1       Running   0          18s       app=nginx,pod-template-hash=2035384211
查看deployment的狀態
$ kubectl rollout status deployment/nginx-deployment
deployment "nginx-deployment" successfully rolled out
更新deployment
 
當deployment 裏面的pod模版更改了
                         label更新了
                         容器鏡像改變了,那麼會觸發deployment從新發布,若是deployment進行擴展,那麼不會觸發deployment
 
能夠直接寫命令進行更改
kubectl set image deployment/nginx-deployment nginx=nginx:1.9.1
deployment "nginx-deployment" image updated
也能夠進行編輯進行更改
$ kubectl edit deployment/nginx-deployment
deployment "nginx-deployment" edited
查看發佈的狀態
$ kubectl rollout status deployment/nginx-deployment
Waiting for rollout to finish: 2 out of 3 new replicas have been updated...
deployment "nginx-deployment" successfully rolled out
若是發佈成功
$ kubectl get deployments
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3         3         3            3           36s
$ kubectl get rs
NAME                          DESIRED   CURRENT   AGE
nginx-deployment-1564180365   3         3         6s
nginx-deployment-2035384211   0         0         36s
$ kubectl get pods
NAME                                READY     STATUS    RESTARTS   AGE
nginx-deployment-1564180365-khku8   1/1       Running   0          14s
nginx-deployment-1564180365-nacti   1/1       Running   0          14s
nginx-deployment-1564180365-z9gth   1/1       Running   0          14s
更新pod,咱們只需更新deployment裏面的templement
當咱們更新deployment時候,當有合適的pod產生的時候,k8s纔會刪除老的pod,當老的pod被刪除足夠多時,纔會繼續產生新的pod
 
 
deployment 回滾
查看deployment詳細信息
$ kubectl describe deployment
查看deployment的發佈歷史
$ kubectl rollout history deployment/nginx-deployment
能夠回滾至任一個以前的版本
$ kubectl rollout undo deployment/nginx-deployment
deployment "nginx-deployment" rolled back
$ kubectl rollout undo deployment/nginx-deployment --to-revision=2
deployment "nginx-deployment" rolled back
擴展deployment

ou can scale a Deployment by using the following command:nginx

$ kubectl scale deployment nginx-deployment --replicas 10
deployment "nginx-deployment" scaled
$ kubectl autoscale deployment nginx-deployment --min=10 --max=15 --cpu-percent=80
deployment "nginx-deployment" autoscaled
暫停或者回復一個deployment
$ kubectl set image deployment/nginx-deployment nginx=nginx:1.9.1; kubectl rollout pause deployment/nginx-deployment
deployment "nginx-deployment" image updated
deployment "nginx-deployment" paused
deployment的狀態
deployment爲processing狀態的狀況爲:
1.deployment正在建立rs
2.deployment正在擴展或者刪除rs
 
deploymen爲何會失敗
  • Insufficient quota
  • Readiness probe failures
  • Image pull errors
  • Insufficient permissions
  • Limit ranges
  • Application runtime misconfiguration
相關文章
相關標籤/搜索