Monday, April 1, 2019

How to setup rolling update in kubernetes deployments


Please note that below rolling update exercise is only applicable if you maintaining container image versioning for each deployment. That means you cannot perform rolling update for two deployments with same version number.

If you are looking for a way to do this while keeping the same version number, please check this post J

First we need add rolling update strategy to the deployment yaml.

Below is the required part to be added to the yaml file,

strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1 # this is limit to create extra pods while rolling update
      maxUnavailable: 1 # this is the limit that can unavailable during rolling update
   minReadySeconds: 25 # this is the minimum time to start your application

Below is a sample deployment yaml file with above strategy,

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  labels:
    app: test
spec:
  replicas: 2
  selector:
    matchLabels:
      app: test
   strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
   minReadySeconds: 25
  template:
    metadata:
      labels:
        app: test
        version: v1
    spec:
      imagePullSecrets:
      - name:
      containers:
      - name: test
        image: test:1.0.0  # different versioning number is a must to perform rolling update    
        ports:
          - name:
            containerPort: 8080

Now apply the deployment with –record flag.

$ kubectl.exe apply -f <your deployment name>.yml --record

Now you can run below command to start rolling update. You must mention a different version number here.

$ kubectl set image deployment test test=test:1.0.1 --record

Now you can check rollout status using below command,

$ kubectl.exe rollout status deployment <your deployment name>

Also you can check rollout history by using below command,

$ kubectl.exe rollout history deployment <your deployment name>

You can use below commands to undo roll outs,

Undo to previous deployment,

$ kubectl rollout undo deployment <your deployment name>

Undo to a specific roll out revision,

$ kubectl rollout undo deployment <deployment> --to-revision=<revision Number that you get from rollout history command (1,2,…)>

References,


2 comments:

  1. I feel SQL and other aspects really help one provide more and more complex operations and solutions.There is a base to look for more and more utilities.

    SQL Server Load Soap Api

    ReplyDelete