YAML Skeleton (VERY IMPORTANT)

 🚀 Step 1 – First Understand the YAML Skeleton (VERY IMPORTANT)

Almost EVERY Kubernetes YAML looks like this:

apiVersion: kind: metadata: spec:

🧠 Golden Memory Rule

👉 AKMS

A → apiVersion K → kind M → metadata S → spec

If you remember ONLY this → you can reconstruct everything.



🔹 What goes under each section?


✅ 1️⃣ apiVersion → "Which API group/version?"

Tells Kubernetes which version of resource API to use

Common values

ResourceapiVersion
Podv1
Servicev1
ReplicaSetapps/v1
Deploymentapps/v1
StatefulSetapps/v1

🧠 Memory Tip

👉 Core = v1
👉 Controllers = apps/v1



✅ 2️⃣ kind → "What are we creating?"

Defines object type

Examples:

kind: Pod kind: ReplicaSet kind: Deployment kind: Service

🧠 Memory Tip

👉 Just the resource name



✅ 3️⃣ metadata → "Information ABOUT object"

Used for:

  • name

  • labels

  • namespace

  • annotations


Example

metadata: name: myapp labels: app: paytm

🧠 Memory Tip

👉 Metadata = Identity of object

(name, labels, namespace)



✅ 4️⃣ spec → "Actual configuration"

This is the MOST IMPORTANT block

Everything related to:

  • replicas

  • containers

  • image

  • ports

  • selector

  • template

comes under spec


🧠 Memory Tip

👉 Spec = Behavior/logic




🔥 Now Understand ReplicaSet Structure


🧠 How to Think (Process)

Ask:

✔ How many pods? → replicas
✔ Which pods belong to me? → selector
✔ How to create pods? → template
✔ What container? → containers
✔ Which image? → image



🔹 ReplicaSet Structure Visual Tree

spec ├─ replicas ├─ selector └─ template ├─ metadata (labels) └─ spec └─ containers ├─ name └─ image


🔹 Where to write what? (ReplicaSet)

ItemWhere to write
labelsmetadata + template.metadata
selectorspec.selector
replicasspec.replicas
containerstemplate.spec.containers
container namecontainers.name
imagecontainers.image


🔹 ReplicaSet YAML (Memory Version)

apiVersion: apps/v1 kind: ReplicaSet metadata: name: app spec: replicas: 3 selector: matchLabels: app: app template: metadata: labels: app: app spec: containers: - name: app image: nginx


🔥 Deployment Structure (VERY EASY)

Deployment = ReplicaSet + updates

So:

👉 Same YAML, just change kind



🔹 Deployment Tree

spec ├─ replicas ├─ selector ├─ template └─ strategy (extra feature)


🔹 What is extra in Deployment?

Additional features

FeatureExtra field
rolling updatestrategy
rollbackrollout history
versioningrevision
scalingreplicas


🔹 Deployment YAML

apiVersion: apps/v1 kind: Deployment metadata: name: app spec: replicas: 3 selector: matchLabels: app: app template: metadata: labels: app: app spec: containers: - name: app image: nginx:1.0


🔥 MEMORY TRICKS (Very useful for exams)


Trick 1 – SAME LABEL TWICE

selector.matchLabels template.metadata.labels

Must match exactly


Trick 2 – Just remember this order

👉 Workload formula:

replicas selector template containers image

That’s 90% YAML



🔥 BEST PART – Generate YAML automatically (NO manual writing)

YES ✅
You can generate YAML using command.

This is what real DevOps engineers do.



🔹 Generate Deployment YAML

kubectl create deployment myapp \ --image=nginx \ --replicas=3 \ --dry-run=client -o yaml > deploy.yml

🔹 Generate ReplicaSet YAML

kubectl create rs myapp \ --image=nginx \ --replicas=3 \ --dry-run=client -o yaml > rs.yml

🔹 Generate Pod YAML

kubectl run mypod \ --image=nginx \ --dry-run=client -o yaml > pod.yml

🔹 Generate Service YAML

kubectl expose deploy myapp \ --port=80 \ --target-port=80 \ --type=NodePort \ --dry-run=client -o yaml > svc.yml


🔥 Why this method is best?

Instead of:
❌ Writing 40 lines manually

Do:
✅ Generate → Edit → Apply

Flow:

kubectl create --dry-run → generate yaml vim file.yml → edit kubectl apply -f file.yml

This is industry standard practice 👍



🔥 Final Super Memory Summary

Just remember:

AKMS

apiVersion kind metadata spec

Workloads

replicas selector template containers image

Deployment = ReplicaSet + strategy



🎯 10-Second Brain Hack

If blank in exam:

Write:

Deployment → replicas → selector → template → containers → image

You’ll reconstruct everything 😄

Comments

Popular posts from this blog

Managing Amazon EBS Volumes and Snapshots Across Regions

Git for Beginners: Complete Guide from Installation to First Push on GitHub

AWS - Amazon Web Services