Kubernetes CKAD hands-on challenge #13 ReplicaSet without Downtime

Kim Wuestkamp
codeburst
Published in
3 min readOct 29, 2019

--

CKS Exam Series | CKA Exam Series | CKAD Exam Series

#####################################

THIS CHALLENGE WON’T BE UPDATED HERE AND MOVED TO:

https://killercoda.com/killer-shell-ckad

######################################

Challenges:

Overview and Tips

  1. Creating Pods
  2. Namespaces, Deployments and Services
  3. CronJobs and Volumes
  4. Deployment Rollout Rollback
  5. Secrets and ConfigMaps
  6. NetworkPolicy
  7. Service Migration
  8. (moved to CKA challenge series)
  9. Logging Sidecar
  10. Deployment Hacking
  11. SecurityContexts
  12. Various Environment Variables
  13. ReplicaSet without Downtime

Rules!

  1. be fast, avoid creating yaml manually from scratch
  2. use only kubernetes.io/docs for help.
  3. check my solution after you did yours. You probably have a better one!

Notices

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!

  1. Create a ReplicaSet for the given pod YAML above with 2 replicas always assured.
  2. 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.

ALL CHALLENGES AND TIPS

More challenges on

https://killer.sh

--

--

killercoda.com | killer.sh (CKS CKA CKAD Simulator) | Software Engineer, Infrastructure Architect, Certified Kubernetes