The CKAD Exam Question you haven’t seen!

Isidro Hernandez
4 min readMay 17, 2020

--

Containers CKAD Docker Kubernetes

Over the last 60 days, I’ve had so much fun preparing for the CKAD. During that time the kubectl version had changed in the exam. Upon taking the exam I noticed that I prepared for mostly version 1.17. I wanted to share with you something that I noticed I had not seen before.

I saw a lot of changes to the kubectl commands. A lot of simplification of the use of kubectl run vs kubectl create. However, in this article, I wanted to cover the question that has eluded most if not all CKAD training, paid OR free.

Introducing……

Deployment Rollout Strategy

kubectl explain deployment.spec.strategy.rollingUpdate

How does the API docs define it?

DESCRIPTION:The deployment strategy to use to replace existing pods with new ones.DeploymentStrategy describes how to replace existing pods with new ones.

Let us create a deployment that can help us visualize this.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: testing-rolling-updates
spec:
replicas: 8
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx-container
image: nginx

Create it with kubectl :

bash3$ kubectl create -f test.yaml
bash3$ kubectl get pods
NAME READY STATUS
testing-rolling-updates-5cdf4f57c7-24qqg 1/1 Running testing-rolling-updates-5cdf4f57c7-g292n 1/1 Running testing-rolling-updates-5cdf4f57c7-gmgpt 1/1 Running testing-rolling-updates-5cdf4f57c7-mwdnb 1/1 Running testing-rolling-updates-5cdf4f57c7-tm7vp 1/1 Running testing-rolling-updates-5cdf4f57c7-tzz7j 1/1 Running testing-rolling-updates-5cdf4f57c7-vb967 1/1 Running testing-rolling-updates-5cdf4f57c7-vhmfs 1/1 Running

Ok, now we have something to work with. Let's break down what a Rolling Update Strategy is:

FIELDS:maxSurge <string>The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).

The keyword for maxSurge is ABOVE. How many pods can we schedule ABOVE our desired pods (specified replicas)?

Values can be percentages or absolute numbers.

So if we have 8 replicas what is the most amount that we want to have if we update the replicas? If we set this value to 40% that means anytime we update this deployment it can create 140% of 8 pods during the rollout. A total of 11.2 or 11 when we round it. When the rollout has finished, the pods will return to a count of 8 with the new changes we applied.

Let's move to maxUnavailable :

maxUnavailable <string>
The maximum number of pods that can be unavailable during the
update. Value can be an absolute number (ex: 5) or a percentage
of desired pods (ex: 10%).

This time if we set maxUnavailble we are able to specify the minimum amount of pods that can be down during the rollout.

Avoid this:

What if I set maxUnavailable to 0 and the maxSurge to 0?

Well, this means that zero pods can be unavailable and that you cannot create more than 8 pods (remember maxSurge refers to the total pods allowed at once).

It can’t create extra pods(maxSurge=0) and it cant terminate a pod either(maxUnavailable=0) so this would make your deployment invalid!

Now that we got that out of the way. Let's try a working example.

Let's add a valid Deployment Rollout Strategy:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: testing-rolling-updates
spec:
replicas: 8
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx-container
image: nginx
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 40%
maxUnavailable: 4

This means we can have 140% of our specified replicas(maxSurge). maxUnavailable is set to 4 meaning we can have 4 pods down at once.

Here is what it would look like.

View of live updates occurring in a deployment.

Click here for the full recording.

You can see that we were able to increase the max amount of pods 140%(pending and running pods combined). While keeping the maxUnavaible pods at 4 or below.

Boom!

Now you have a new tool to help you ace the CKAD! Don’t forget about the little people when you do!

--

--