55
66---
77
8+ ## Pro Tips & Time Savers
9+
10+ ### Multiple Solution Approaches
11+ - ** Fast path (Imperative)** : Use ` kubectl run ` , ` kubectl create ` for quick creation
12+ - ** Flexible path (Declarative)** : Use YAML files for complex configs, can reuse across environments
13+ - ** Cost** : Declarative takes 2-3 minutes longer but reduces errors on complex Deployments
14+
15+ ### Debugging Checklist
16+ When tasks fail, use this sequence:
17+ 1 . ` kubectl get <resource> -n <namespace> ` — Status check
18+ 2 . ` kubectl describe pod <name> -n <ns> ` — See Events section for root cause
19+ 3 . ` kubectl logs pod <name> -n <ns> ` — Check container logs
20+ 4 . ` kubectl logs pod <name> -n <ns> --previous ` — Check crashed container logs
21+ 5 . ` kubectl get <resource> -o yaml ` — Inspect full spec for typos
22+
23+ ### Common Exam Mistakes (Avoid These!)
24+ - ❌ Forgetting ` -n <namespace> ` in commands (defaults to ` default ` )
25+ - ❌ Typos in label selectors (e.g., ` app=web ` vs ` app: web ` in YAML)
26+ - ❌ Not setting ` restartPolicy: Never ` for Jobs/CronJobs
27+ - ❌ Missing ` selector ` field in Deployment YAML (required in v1, not v1beta1)
28+ - ❌ Using ` docker build ` instead of ` podman build ` (exam uses Podman)
29+ - ❌ Pod ` serviceAccountName ` is immutable — must delete & recreate if wrong
30+
31+ ### Time Management Tips
32+ - Flag difficult questions (5+ min) and return later
33+ - Use ` kubectl explain <resource> ` to verify schema (faster than docs)
34+ - Copy working YAML blocks and modify rather than typing from scratch
35+ - Save common templates as local files for paste-and-edit
36+
37+ ---
38+
839## Question 1 — Pod with Resources and Labels [ 3%]
940
10- ** Solution: **
41+ ### ✅ Fast Approach (Imperative — 30 seconds)
1142
1243``` bash
1344kubectl run web-pod --image=nginx:1.25 \
@@ -17,13 +48,18 @@ kubectl run web-pod --image=nginx:1.25 \
1748 -n default
1849```
1950
20- Or via YAML:
51+ ** Why choose this** : Fastest if you already know all parameters. No YAML editing needed.
52+
53+ ### ✅ Flexible Approach (Declarative — 1.5 minutes)
54+
55+ Create ` web-pod.yaml ` :
2156
2257``` yaml
2358apiVersion : v1
2459kind : Pod
2560metadata :
2661 name : web-pod
62+ namespace : default
2763 labels :
2864 app : web
2965spec :
@@ -39,10 +75,15 @@ spec:
3975 memory : 256Mi
4076` ` `
4177
42- **Verification:**
78+ Then apply: ` kubectl apply -f web-pod.yaml`
79+
80+ **Why choose this**: If unsure about parameters, YAML is self-documenting. Can also export and reuse.
81+
82+ # ## 🔍 Verification
83+
4384` ` ` bash
4485kubectl get pod web-pod -o yaml | grep -A 5 "resources\| labels"
45- # Should show :
86+ # Expected output :
4687# labels:
4788# app: web
4889# resources:
@@ -54,6 +95,27 @@ kubectl get pod web-pod -o yaml | grep -A 5 "resources\|labels"
5495# memory: 128Mi
5596` ` `
5697
98+ Or more detailed :
99+ ` ` ` bash
100+ kubectl describe pod web-pod
101+ # Look for "Limits" and "Requests" sections
102+ ` ` `
103+
104+ # ## ⚠️ Common Pitfalls & How to Avoid
105+
106+ | Mistake | What Happens | Fix |
107+ |---------|--------------|-----|
108+ | Forget `-n default` | Goes to `default` namespace (usually OK) but get habit | Always explicit : ` -n default` |
109+ | Typo in labels `app=web vs app : web` | In YAML only `:` works; CLI uses `=` | CLI: `key=value`, YAML: `key: value` |
110+ | Set limits lower than requests | Pod creation fails | Always : requests ≤ limits |
111+ | Image doesn't exist | Pod stuck in `ImagePullBackOff` | Verify image exists in registry first |
112+
113+ # ## 📝 Exam Notes
114+
115+ - **Score criteria**: Full marks if Pod created with all specs, any approach (imperative/declarative)
116+ - **Partial credit**: Missing label → -1 point, Resource mismatch → -1 point
117+ - **Typical time**: 2-3 minutes (including verification)
118+
57119---
58120
59121# # Question 2 — Multi-Container Pod [4%]
@@ -703,6 +765,105 @@ kubectl get pvc -n advanced
703765
704766---
705767
768+ # # Bonus: Question 16B — Debugging Pod Image Pull Error [Debugging Skill]
769+
770+ # ## Problem Diagnosis
771+
772+ When you see `ImagePullBackOff`, the Pod spec has an invalid or inaccessible image. Check events :
773+
774+ ` ` ` bash
775+ kubectl describe pod image-test -n broken-apps
776+ # Look for Events section:
777+ # - Type: Warning | Reason: Failed | Message: Error response from daemon...
778+ ` ` `
779+
780+ # ## Solution
781+
782+ **Approach 1: Patch (Fastest — 30 seconds)**
783+
784+ ` ` ` bash
785+ kubectl patch pod image-test -n broken-apps -p \
786+ '{"spec":{"containers":[{"name":"app","image":"nginx:1.25"}]}}'
787+
788+ kubectl get pod image-test -n broken-apps
789+ # Status should change: ImagePullBackOff → Running
790+ ` ` `
791+
792+ **Approach 2: Export, Edit, Recreate** (safer for complex changes)
793+
794+ ` ` ` bash
795+ kubectl get pod image-test -n broken-apps -o yaml > image-test.yaml
796+ # Edit: image: private-registry/app:v2.0 → image: nginx:1.25
797+ kubectl delete pod image-test -n broken-apps
798+ kubectl apply -f image-test.yaml
799+ ` ` `
800+
801+ # ## Verification
802+
803+ ` ` ` bash
804+ kubectl logs image-test -n broken-apps
805+ # No "image not found" errors
806+ ` ` `
807+
808+ ⚠️ **Common pitfalls** : Misspelled image names, private registry without secrets
809+
810+ ---
811+
812+ # # Bonus: Question 17B — Debugging ConfigMap Key Mismatch [Debugging Skill]
813+
814+ # ## Problem Diagnosis
815+
816+ App logs show : ` "ConfigMap key DATABASE_URL not found"` → Mismatch between Pod spec and actual ConfigMap keys.
817+
818+ **Step 1: Check actual ConfigMap**
819+
820+ ` ` ` bash
821+ kubectl get configmap app-config -n app-errors -o yaml
822+ # data:
823+ # DB_URL: "postgres://..." # Key exists, not DATABASE_URL!
824+ ` ` `
825+
826+ **Step 2: Find the Deployment using it**
827+
828+ ` ` ` bash
829+ kubectl describe deployment data-processor -n app-errors | grep -A 5 "env:\| valueFrom"
830+ ` ` `
831+
832+ # ## Solution
833+
834+ **Edit Deployment → Fix Key Name**
835+
836+ ` ` ` bash
837+ kubectl edit deployment data-processor -n app-errors
838+ ` ` `
839+
840+ Change :
841+ ` ` ` yaml
842+ # FROM:
843+ env:
844+ - name: DATABASE_URL
845+ valueFrom:
846+ configMapKeyRef:
847+ key: DATABASE_URL # ❌ Doesn't exist
848+
849+ # TO:
850+ env:
851+ - name: DATABASE_URL
852+ valueFrom:
853+ configMapKeyRef:
854+ key: DB_URL # ✅ Matches ConfigMap
855+ ` ` `
856+
857+ # ## Verification
858+
859+ ` ` ` bash
860+ kubectl rollout restart deployment/data-processor -n app-errors
861+ kubectl logs deployment/data-processor -n app-errors
862+ # Check: No "key not found" errors
863+ ` ` `
864+
865+ ---
866+
706867# # Weak Area Review
707868
708869If you scored below 50% in any domain, review :
0 commit comments