βΈοΈ Day 8: Imperative vs Declarative + YAML + Pod Manifest
Video Overview
This note covers:
- Imperative vs Declarative approaches
- YAML fundamentals (VERY IMPORTANT)
- Pod manifest creation
- kubectl commands for pods
π YAML + Declarative = Core of Kubernetes
demo
βοΈ Concept 1: Imperative vs Declarative
Important
Two ways to configure any system (including Kubernetes)
β‘ Imperative Approach
Info
Tell the system HOW to do something
kubectl run mypod --image=nginx- Step-by-step instructions
- Quick tasks
- Not scalable
π Declarative Approach
Info
Tell the system WHAT you want
kubectl apply -f pod.yaml- Define desired state
- Kubernetes ensures it
π§ Key Difference
| Approach | Focus | Use Case |
|---|---|---|
| Imperative | How | Quick tasks |
| Declarative | What | Production setups |
π Why Declarative is Preferred
Success
1οΈβ£ Idempotency
- Apply same file multiple times β same result
2οΈβ£ Version Control
- Store configs in Git
- Track changes
- Team collaboration
3οΈβ£ Simplicity
- Human-readable configs
- Easy to understand
π Concept 2: What is YAML?
Important
YAML = Human-readable data format used in Kubernetes
π§ Key Features:
- Easy to read & write
- Uses indentation (spaces β)
- Less verbose than JSON/XML
β οΈ Rules:
- β No tabs (only spaces)
- Maintain consistent indentation
- Key-value structure
π§© Concept 3: YAML Data Types
πΉ 1. Scalar (Basic Values)
Example
name: "Prakash"
age: 21
height: 5.9
isEngineer: true
paymentDue: null- String, Integer, Float, Boolean, Null
πΉ 2. Dictionary (Map)
Example
address:
flat: "X001"
city: "Mumbai"
country: "India"- Collection of key-value pairs
πΉ 3. List (Array)
Example
hobbies:
- singing
- dancing
- travelingπ₯ Advanced YAML Concepts
π Nested Dictionary
contact:
phone: "123456"
email: "test@example.com"π Nested List
sports:
- cricket
- footballπ§ List with Dictionary
education:
degrees:
- degree: "Bachelors"
field: "Computer Science"
- degree: "Masters"
field: "Data Science"πΌ List + Nested Dictionary
work:
- company: "ABC Corp"
role: "DevOps Engineer"
- company: "XYZ Inc"
role: "Consultant"π§ Golden Rule
Quote
YAML = Key : Value β Everything is built from this
π¦ Concept 4: Kubernetes Pod Manifest
Important
Every K8s object has 4 main fields:
π§ KAMS Trick
- A β apiVersion
- K β kind
- M β metadata
- S β spec
π§Ύ Example Pod YAML
Example
apiVersion: v1
kind: Pod
metadata:
name: mypod-2
labels:
app: nginx
env: dev
spec:
containers:
- name: nginx-container
image: nginx
ports:
- containerPort: 80
- name: sidecar-container
image: busybox
args: ["sleep", "3600"]π§ Understanding Structure
Important
specβ Dictionarycontainersβ List- Each container β Dictionary
portsβ Listargsβ List
π YAML Separator
Info
---- Used to separate multiple objects in one file
βοΈ Concept 5: kubectl Commands
π Create Pod (Imperative)
kubectl run mypod --image=nginxπ Apply YAML (Declarative)
kubectl apply -f pod.yamlπ Get Pods
kubectl get pods
kubectl get pods -o wideπ Describe Pod
kubectl describe pod mypod-2π Logs
kubectl logs mypod-2
kubectl logs mypod-2 -c sidecar-containerπ Execute Command
kubectl exec mypod-2 -- ls
kubectl exec -it mypod-2 -- bashπ Delete Pod
kubectl delete pod mypod-2β οΈ Important Observations
Warning
- Multiple containers β
2/2READY - Single container β
1/1READY
π§ Behind the Scenes
Info
- Scheduler assigns node
- Kubelet:
- Pulls image
- Starts container
- Configures networking
π§ Final Takeaways
Summary
- Declarative > Imperative
- YAML = backbone of Kubernetes
- Pod = smallest unit
- kubectl = interaction tool
π One-Line Summary
Quote
Write YAML β Apply β Kubernetes handles everything βΈοΈ