Skip to content

Room 11

REPLICASETS


The Clone Factory

  • A critical application needs to run exactly 3 replicas. The ReplicaSet ensures pods are always at the desired count.
  • One of the replicas has a secret annotation - find it.

📜 Mission Briefing

  1. Apply replicaset.yaml to create a ReplicaSet with 3 replicas.
  2. Verify 3 pods are running: kubectl get pods -l app=cloned-app.
  3. Delete one pod manually - watch the ReplicaSet recreate it.
  4. Scale the ReplicaSet to 5: kubectl scale rs cloned-app --replicas=5.
  5. Each pod has an annotation fragment with a letter. Collect all 5 fragments and sort by pod name.
  6. The concatenated letters (sorted by pod name alphabetically) spell replica3x.

Key Commands
Command Purpose
kubectl get rs List ReplicaSets
kubectl describe rs NAME ReplicaSet details
kubectl scale rs NAME --replicas=N Scale replicas
kubectl get pods -l app=NAME Pods by label selector
kubectl get pods -o jsonpath='{.items[*].metadata.annotations}' Pod annotations

How ReplicaSets Work
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: my-replicaset
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app          # Must match template labels
  template:
    metadata:
      labels:
        app: my-app        # Must match selector
    spec:
      containers:
        - name: app
          image: nginx:alpine
# ReplicaSets ensure N pods are always running
# They use label selectors to identify their pods

# Create and manage ReplicaSets
kubectl apply -f replicaset.yaml
kubectl get rs
kubectl describe rs my-replicaset

# Scale up/down
kubectl scale rs my-replicaset --replicas=5

# Delete a pod - RS creates a new one
kubectl delete pod <pod-name>

# Note: Deployments are preferred over bare ReplicaSets
# because Deployments manage ReplicaSets and add rollout capabilities

Hints

Hint 1

List the pods and their annotations:

kubectl get pods -l app=cloned-app -o custom-columns=NAME:.metadata.name,FRAG:.metadata.annotations.fragment

Hint 2

Sort by name and concatenate:

kubectl get pods -l app=cloned-app --sort-by=.metadata.name \
  -o jsonpath='{.items[*].metadata.annotations.fragment}'

Hint 3

The password is replica3x.


🔓 Unlock Room 12

openssl enc -aes-256-cbc -d -a -pbkdf2 \
        -in ../room_12/README             \
        -out ../room_12/README.txt        \
        -pass pass:PASSWORD
cat ../room_12/README.txt