滾動升級Deployment
現在我們將剛剛保存的yaml文件中的nginx鏡像修改為 nginx:1.13.3,然后在spec下面添加滾動升級策略:
|  
               
                 1 
                 
               
                 2 
                 
               
                 3 
                 
               
                 4 
                 
               
                 5 
                 
               
                 6 
                 
               
                 7 
                 
               |  
              
                
                minReadySeconds: 5 
                 
                
                strategy: 
                 
                
                  # indicate which strategy we want for rolling update 
                 
                
                  type: RollingUpdate 
                 
                
                  rollingUpdate: 
                 
                
                    maxSurge: 1 
                 
                
                    maxUnavailable: 1 
                 
               |  
            
- minReadySeconds: 
          
- Kubernetes在等待設置的時間后才進行升級
 - 如果沒有設置該值,Kubernetes會假設該容器啟動起來后就提供服務了
 - 如果沒有設置該值,在某些極端情況下可能會造成服務服務正常運行
 
 - maxSurge: 
          
- 升級過程中最多可以比原先設置多出的POD數量
 - 例如:maxSurage=1,replicas=5,則表示Kubernetes會先啟動1一個新的Pod后才刪掉一個舊的POD,整個升級過程中最多會有5 1個POD。
 
 - maxUnavaible: 
          
- 升級過程中最多有多少個POD處於無法提供服務的狀態
 - 當 maxSurge不為0時,該值也不能為0
 - 例如:maxUnavaible=1,則表示Kubernetes整個升級過程中最多會有1個POD處於無法服務的狀態。
 
 
然后執行命令:
|  
               
                 1 
                 
               
                 2 
                 
               |  
              
                
                $ kubectl apply -f nginx-deployment.yaml 
                 
               
                 deployment 
                 "nginx-deploy" configured 
                 
               |  
            
實例操作:
spec:
  minReadySeconds: 120
  progressDeadlineSeconds: 600
  replicas: 2
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: image-train-prod-k8s
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
 
          
.spec.minReadySecondsis an optional field that specifies the minimum number of seconds for which a newly created Pod should be ready without any of its containers crashing, for it to be considered available. This defaults to 0 (the Pod will be considered available as soon as it is ready). To learn more about when a Pod is considered ready, see Container Probes
So your newly created app pod have to be ready for .spec.minReadySeconds seconds to be considered as available.
