Does Kubernetes need a minimum number of replicas in order to carry out a rolling deployment?

4/22/2020

Nearly 3 years ago, Kubernetes would not carry out a rolling deployment if you had a single replica (Kubernetes deployment does not perform a rolling update when using a single replica).

Is this still the case? Is there any additional configuration required for this to work?

-- Chris Stryczynski
kubernetes

1 Answer

4/22/2020

You are not required to have a minimum number of replicas to rollout an update using Kubernetes Rolling Update anymore.

I tested it on my lab (v1.17.4) and it worked like a charm having only one replica.

You can test it yourself using this Katakoda Lab: Interactive Tutorial - Updating Your App

This lab is setup to create a deployment with 3 replicas. Before starting the lab, edit the deployment and change the number of replicas to one and follow the lab steps.

I created a lab using different example similar to your previous scenario. Here is my deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template: 
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx-container 
        image: nginx:1.16.1
        ports:
        - containerPort: 80

Deployment is running with one replica only:

kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-6c4699c59c-w8clt   1/1     Running   0          5s

Here I edited my nginx-deployment.yaml and changed the version of nginx to nginx:latest and rolled out my deployment running replace:

$ kubectl replace -f nginx-deployment.yaml 
deployment.apps/nginx-deployment replaced

Another option is to change the nginx version using the kubectl set image command:

kubectl set image deployment/nginx-deployment nginx-container=nginx:latest --record
$ kubectl get pods
NAME                                READY   STATUS              RESTARTS   AGE
nginx-deployment-566d9f6dfc-hmlf2   0/1     ContainerCreating   0          3s
nginx-deployment-6c4699c59c-w8clt   1/1     Running             0          48s

$ kubectl get pods
NAME                                READY   STATUS        RESTARTS   AGE
nginx-deployment-566d9f6dfc-hmlf2   1/1     Running       0          6s
nginx-deployment-6c4699c59c-w8clt   0/1     Terminating   0          51s

$ kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-566d9f6dfc-hmlf2   1/1     Running   0          13s

As you can see, everything worked normally with only one replica.

In the latest version of the documentation we can read:

Deployment ensures that only a certain number of Pods are down while they are being updated. By default, it ensures that at least 75% of the desired number of Pods are up (25% max unavailable).

Deployment also ensures that only a certain number of Pods are created above the desired number of Pods. By default, it ensures that at most 125% of the desired number of Pods are up (25% max surge).

-- mWatney
Source: StackOverflow