DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

CKA HANDS-ON LABS

πŸ“˜

Topic Coverage:

  • Startup / Readiness / Liveness Probes
  • ConfigMaps
  • Secrets
  • Configuration mistakes & fixes

Environment:

  • Minikube
  • kubectl
  • Local machine (Mac / Linux / Windows)

LAB 0 β€” Environment Check (MANDATORY)

minikube start
kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

Expected:

STATUS: Ready
Enter fullscreen mode Exit fullscreen mode

πŸ§ͺ LAB 1 β€” STARTUP PROBE (CrashLoopBackOff ISSUE)

🎯 Goal

Understand why slow apps restart endlessly and how startup probe fixes it.


Step 1 β€” Deploy a slow application (BROKEN)

# lab1-broken.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: slow-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: slow
  template:
    metadata:
      labels:
        app: slow
    spec:
      containers:
      - name: app
        image: busybox
        command: ["sh", "-c"]
        args:
          - sleep 30; echo STARTED; sleep 3600
        livenessProbe:
          exec:
            command: ["sh", "-c", "echo ok"]
          initialDelaySeconds: 5
          periodSeconds: 5
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f lab1-broken.yaml
kubectl get pods
Enter fullscreen mode Exit fullscreen mode

❌ What breaks

  • Pod enters CrashLoopBackOff
  • Liveness probe runs before app finishes startup

Check:

kubectl describe pod
Enter fullscreen mode Exit fullscreen mode

Step 2 β€” FIX using startup probe

# lab1-fixed.yaml
startupProbe:
  exec:
    command: ["sh", "-c", "echo ok"]
  failureThreshold: 40
  periodSeconds: 1
Enter fullscreen mode Exit fullscreen mode

Add this under the container spec.

Apply:

kubectl apply -f lab1-fixed.yaml
kubectl get pods
Enter fullscreen mode Exit fullscreen mode

βœ… Expected Result

  • Pod starts successfully
  • No restarts

πŸ’‘ CKA LESSON

  • Startup probe blocks liveness
  • Mandatory for slow apps (Java, DB, migrations)

πŸ§ͺ LAB 2 β€” READINESS PROBE (TRAFFIC ISSUE)

🎯 Goal

Stop traffic to unhealthy pods without restarting them


Step 1 β€” Deploy app WITHOUT readiness

# lab2-broken.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ready-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ready
  template:
    metadata:
      labels:
        app: ready
    spec:
      containers:
      - name: app
        image: hashicorp/http-echo:0.2.3
        args:
          - "-listen=:8080"
          - "-text=HELLO"
        ports:
        - containerPort: 8080
Enter fullscreen mode Exit fullscreen mode

Service:

apiVersion: v1
kind: Service
metadata:
  name: ready-svc
spec:
  selector:
    app: ready
  ports:
  - port: 80
    targetPort: 8080
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f lab2-broken.yaml
kubectl apply -f service.yaml
Enter fullscreen mode Exit fullscreen mode

❌ What breaks

  • Pod always receives traffic
  • No way to stop traffic during issues

Check:

kubectl get endpoints ready-svc
Enter fullscreen mode Exit fullscreen mode

Step 2 β€” FIX using readiness probe

readinessProbe:
  tcpSocket:
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 3
Enter fullscreen mode Exit fullscreen mode

Apply fix.


βœ… Expected Result

  • When readiness fails β†’ pod removed from endpoints
  • Pod still Running

πŸ’‘ CKA LESSON

  • Readiness controls traffic
  • Required for zero downtime

πŸ§ͺ LAB 3 β€” LIVENESS PROBE (HUNG APP)

🎯 Goal

Restart stuck containers automatically


Step 1 β€” Deploy app WITHOUT liveness

# lab3-broken.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hang-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hang
  template:
    metadata:
      labels:
        app: hang
    spec:
      containers:
      - name: app
        image: nginx
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f lab3-broken.yaml
Enter fullscreen mode Exit fullscreen mode

❌ Simulate hang

kubectl exec -it pod-name -- kill 1
kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Result:

  • Pod stays Running
  • App is dead

Step 2 β€” FIX using liveness probe

livenessProbe:
  httpGet:
    path: /
    port: 80
  initialDelaySeconds: 10
  periodSeconds: 5
Enter fullscreen mode Exit fullscreen mode

Apply fix.


βœ… Expected Result

  • Pod restarts automatically

πŸ’‘ CKA LESSON

  • Liveness = self-healing
  • Without it, Kubernetes does nothing

πŸ§ͺ LAB 4 β€” CONFIGMAP (CONFIG NOT APPLIED ISSUE)

🎯 Goal

Understand why config changes don’t apply automatically


Step 1 β€” Create ConfigMap

kubectl create configmap app-config \
  --from-literal=APP_COLOR=blue
Enter fullscreen mode Exit fullscreen mode

Step 2 β€” Inject via env (BROKEN EXPECTATION)

env:
- name: APP_COLOR
  valueFrom:
    configMapKeyRef:
      name: app-config
      key: APP_COLOR
Enter fullscreen mode Exit fullscreen mode

Apply deployment.


❌ What breaks

kubectl edit configmap app-config
Enter fullscreen mode Exit fullscreen mode

Change value β†’ app does NOT change.


Step 3 β€” FIX

kubectl rollout restart deployment app
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ CKA LESSON

  • Env vars are immutable
  • Restart required

πŸ§ͺ LAB 5 β€” CONFIGMAP AS FILE (RELOAD CONFUSION)

🎯 Goal

Understand mounted config behavior


Step 1 β€” Mount ConfigMap

volumes:
- name: config
  configMap:
    name: app-config

volumeMounts:
- name: config
  mountPath: /etc/config
Enter fullscreen mode Exit fullscreen mode

Step 2 β€” Update ConfigMap

kubectl edit configmap app-config
Enter fullscreen mode Exit fullscreen mode

❌ Observation

  • File updates
  • App behavior does NOT change

πŸ’‘ CKA LESSON

  • Kubernetes updates file
  • App must reload manually

πŸ§ͺ LAB 6 β€” SECRETS (SECURITY TRAP)

🎯 Goal

Handle secrets correctly


Step 1 β€” Create Secret

kubectl create secret generic db-secret \
  --from-literal=DB_PASS=secret123
Enter fullscreen mode Exit fullscreen mode

Step 2 β€” Inject as env

env:
- name: DB_PASS
  valueFrom:
    secretKeyRef:
      name: db-secret
      key: DB_PASS
Enter fullscreen mode Exit fullscreen mode

❌ Common mistake

kubectl describe pod
Enter fullscreen mode Exit fullscreen mode

Secrets visible in plain text.


πŸ’‘ CKA LESSON

  • Secrets are base64
  • RBAC is mandatory
  • Never commit secrets

βœ… FINAL CHECKLIST

βœ” Startup vs readiness vs liveness
βœ” ConfigMap injection methods
βœ” Why config updates fail
βœ” Secret handling risks
βœ” Rollout restarts
βœ” Debug using describe, logs, exec

Top comments (0)