Kubernetes CKAD hands-on challenge #13 ReplicaSet without Downtime

#####################################
THIS CHALLENGE WON’T BE UPDATED HERE AND MOVED TO:
https://killercoda.com/killer-shell-ckad
######################################
Challenges:
- Creating Pods
- Namespaces, Deployments and Services
- CronJobs and Volumes
- Deployment Rollout Rollback
- Secrets and ConfigMaps
- NetworkPolicy
- Service Migration
- (moved to CKA challenge series)
- Logging Sidecar
- Deployment Hacking
- SecurityContexts
- Various Environment Variables
- ReplicaSet without Downtime
Rules!
- be fast, avoid creating yaml manually from scratch
- use only kubernetes.io/docs for help.
- check my solution after you did yours. You probably have a better one!
Notices
- This challenge was tested on k8s 1.18. Please let us know should you encounter any issues in the comments
- how to be fast with Kubectl ≥ 1.18
Scenario Setup
Run this pod in your cluster:
apiVersion: v1
kind: Pod
metadata:
name: pod-calc
spec:
containers:
- command:
- sh
- -c
- echo "important calculation"; sleep 1d
image: nginx
name: pod-calc
Todays Task: Handle Pod with ReplicaSet, without downtime!
This pod is important, it cannot be shutdown and re-created. But from today on, we need to ensure two insurances are always running!
- Create a ReplicaSet for the given pod YAML above with 2 replicas always assured.
- Make sure the ReplicaSet only creates one new pod and uses the existing and already running one as the second. NO DOWNTIME
Solution
At first, we add a label to our running pod:
use kubectl >= 1.18alias k=kubectlk label pod pod-calc id=calck get pod --show-labels
Now copy an ReplicaSet example yaml from the Kubernetes docs and alter it to fit the pod yaml from top:
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: rs1
spec:
replicas: 2
selector:
matchLabels:
id: calc
template:
# from here down its the pod template
metadata:
name: pod-calc
labels:
id: calc
spec:
containers:
- command:
- sh
- -c
- echo "important calculation"; sleep 1d
image: nginx
name: pod-calc
And apply it:
k -f rs.yaml create
We can see that our single pod is still running (NO DOWNTIME) and is now controlled by the ReplicaSet.

Though we see both Pods have different names. That’s because we gave the first one a specific one during its creation.
The second one got its name from the ReplicaSet. A ReplicaSet doesn’t care about the name though, it only cares about Pod labels.
More challenges on
