kubernetes rolling update 滚动更新

Environment

  • OS version: CentOS 7.3
  • kuberadm version: 1.7.5
  • docker version: 1.12.6

Creating a Deployment

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 2
      maxUnavailable: 1
  minReadySeconds: 15
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.12
        ports:
        - containerPort: 80

关键部分

  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 2
      maxUnavailable: 1
  minReadySeconds: 15
  • type: 使用RollingUpdate(滚动更新)策略

  • maxSurge: 最大激增数, 指更新过程中, 最多可以比replicas预先设定值多出的pod数量, 可以为固定值或百分比(默认25%), 更新过程中最多会有replicas + maxSurge个pod

  • maxUnavailable: 最大无效数, 指更新过程中, 最多有几个pod处于无法服务状态, 当maxSurge不为0时, 此栏位也不可为0, 整个更新过程中, 会有maxUnavailable个pod处于Terminating状态

  • minReadySeconds: 容器内应用的启动时间, pod变为run状态, 会在minReadySeconds后继续更新下一个pod. 如果不设置该属性, pod会在run成功后, 立即更新下一个pod.

执行滚动更新

$ kubectl set image deployment nginx nginx=nginx:1.11 --record

观察pod状态, 请注意AGE栏

状态1: 初始激增3

NAME                     READY     STATUS              RESTARTS   AGE
nginx-2367425312-75z2x   1/1       Terminating         0          21m
nginx-2367425312-db9v4   1/1       Running             0          21m
nginx-2367425312-ghj39   1/1       Running             0          21m
nginx-4182544083-k0gcx   0/1       ContainerCreating   0          2s
nginx-4182544083-n175h   0/1       ContainerCreating   0          2s
nginx-4182544083-vvlqf   0/1       ContainerCreating   0          2s

状态2: 激增3完成, 不可用1

nginx-2367425312-75z2x   0/1       Terminating   0          21m
nginx-2367425312-db9v4   1/1       Running       0          21m
nginx-2367425312-ghj39   1/1       Running       0          21m
nginx-4182544083-k0gcx   1/1       Running       0          10s
nginx-4182544083-n175h   1/1       Running       0          10s
nginx-4182544083-vvlqf   1/1       Running       0          10s

状态3: 剔除不可用pod

nginx-2367425312-db9v4   1/1       Running       0          21m
nginx-2367425312-ghj39   1/1       Terminating   0          21m
nginx-4182544083-k0gcx   1/1       Running       0          19s
nginx-4182544083-n175h   1/1       Running       0          19s
nginx-4182544083-vvlqf   1/1       Running       0          19s

状态4: 继续剔除不可用pod

nginx-2367425312-db9v4   1/1       Terminating   0          21m
nginx-4182544083-k0gcx   1/1       Running       0          30s
nginx-4182544083-n175h   1/1       Running       0          30s
nginx-4182544083-vvlqf   1/1       Running       0          30s

状态5: 恒定replicas数量

nginx-4182544083-k0gcx   1/1       Running   0          35s
nginx-4182544083-n175h   1/1       Running   0          35s
nginx-4182544083-vvlqf   1/1       Running   0          35s

查看滚动更新状态

$ kubectl rollout status deployment nginx

你可能感兴趣的:(kubernetes rolling update 滚动更新)