Kubernetes Mastering Guide - Part 1
Before we deep dive into it we have to know every concept, why we need kubernetes, and so on.
1. What Problem is Kubernetes Even Solving?
imagine you built an app. if you want to run it, you need to actually execute code 24/7 for however many people are using it
The old way: you rent one server, install your app on it, and hope it never crashes. If it crashes at 3am, nobody restarts it until a human wakes up. If traffic spikes, that one server just... struggles.
The problem gets worse at scale: now imageine you have hundreds of different apps (services), each needing to run on multiple servers for realibility, each needing updates without downtime, each needing to talk to each other, each needing to scale up and down with traffic. Manually managing this across hundred of servers is a full-time job for an army of people, and mistakes are constant.
so here's why kubernetes exist you only tell it within writing "I want this app running with 3 copies, using this much memory, talking to that other app," and Kubernetes continuously makes that true, forever, automatically. If a server dies, it moves your app elsewhere. If a copy crashes, it restarts it. If you say "make it 10 copies now," it does that in seconds.
π‘ One sentence summary:
Kubernetes is a system that keeps your applications running the way
you described, across a group of computers,
without you manually babysitting them.
2. The Restaurant Analogy (Keep This In Your Head Forever)
This single analogy explains almost every term you'll meet:
| Real World | Kubernetes |
|---|---|
| A recipe card describing a dish | A YAML file (your instructions to Kubernetes) |
| The restaurant manager who reads recipe cards and makes sure the kitchen is producing them | The Kubernetes control plane (the brain) |
| A cook actually making the dish | A container (your app, actually running) |
| A plate carrying one (or a few) dishes together | A Pod (the smallest unit Kubernetes manages) |
| A kitchen station where a cook works | A Node (an actual physical/virtual computer) |
| The whole restaurant (kitchen + dining room + all stations) | The Cluster (the whole group of computers Kubernetes manages) |
| Sticky notes on plates saying "vegan," "spicy," "table 5" | Labels (tags you attach to things so they can be found/grouped) |
| The manager's promise: "there will always be 3 pasta dishes ready" | A Deployment (a promise to keep N copies running) |
| Separate function rooms in the same building, so a "wedding" event and a "birthday" event don't interfere | Namespaces (isolated areas within one cluster) |
You never talk to the cook (container) directly. You talk to the manager (control plane), and the manager makes reality match your recipe card (YAML).
Let's Play this Game to keep understanding of this concept with this link
3. Containers: The Absolute Foundation
Before Kubernetes even enters the picture, you need to understand containers.
The problem containers solve: "it works on my machine, but not on the server," because your machine has different software versions, settings, dependencies installed than the server does.
A container is: your application PLUS everything it needs to run (code, libraries, settings), all packaged together into one bundle that behaves identically no matter where you run it. Think of it like a fully self-contained meal kit: everything needed is inside the box, nothing depends on what's already in your kitchen.
A container image is the "recipe/blueprint" for a container: a frozen snapshot of that bundle. When you "run" an image, you get a live, running container from it. Same relationship as a cake recipe (image) vs. an actual baked cake (running container). You can bake many cakes from one recipe.
- Docker is the most famous tool for building/running containers (though Kubernetes doesn't require Docker specifically anymore, it uses "container runtimes" more generally).
nginx:1.21is an example of an image reference:nginxis the image name (repository),1.21is the tag (specific version). This exact naming shows up constantly in the game; get it wrong (typo, non-existent tag) and you getImagePullBackOff.
π‘ Without Kubernetes, containers already solve "it works everywhere the same way." Kubernetes' job is managing many containers, across many machines, reliably.
4. YAML: The Language You "Talk" to Kubernetes In
Every single thing you do in Kubernetes is done by writing a YAML file (a plain text file with a specific structure) and telling Kubernetes "make this true."
Here's the smallest possible real example, annotated line by line:
apiVersion: v1 # which "version" of Kubernetes' API we're using for this type of thing
kind: Pod # WHAT kind of thing are we creating? (a Pod, in this case)
metadata: # information ABOUT this thing (not its behavior)
name: my-first-pod # the name we're giving it
namespace: default # which "room" (namespace) it lives in
spec: # the actual DESIRED STATE: what we actually want
containers:
- name: web
image: nginx:1.21 # which container image to run
Break down the four sections you'll see in almost every file:
apiVersion: tells Kubernetes which version/family of functionality this belongs to (e.g.v1for core basics,apps/v1for Deployments,networking.k8s.io/v1for networking things). You don't need to memorize these; you'll absorb them by pattern-matching over time.kind: this is the single most important word to understand.kindanswers: "what TYPE of object am I creating?" Is it aPod? ADeployment? AService? ANamespace? Every single thing in Kubernetes has akind. When you see "Level 19: used a Deployment instead of a StatefulSet," that's literally a wrongkindchosen for the job.metadata: the "label on the box": name, namespace, tags (labels). Identity information, not behavior.spec: short for "specification." This is the actual instructions: what you actually want to happen. Everything about desired state lives here.
maybe some of you confuse when we have to use any kind of kind ?
πworkload kinds - "How should my app run?"
| Kind | Use When |
|---|---|
| Pod | Almost never directly: it's the atomic unit everything else creates |
| Deployment | Your default choice: stateless apps (web servers, APIs) that need N copies, self-healing, rolling updates |
| StatefulSet | Databases, message queues: anything needing stable identity + its own dedicated storage per replica |
| DaemonSet | You want exactly one copy on every single Node: log collectors, monitoring agents, network plugins. Not "N copies," but "one everywhere" |
| Job | Run something once, to completion, then stop: a database migration, a one-time data import |
| CronJob | Run a Job on a schedule: nightly backups, hourly report generation. It's a Job with a cron timer wrapped around it |
| ReplicaSet | You rarely create this directly: Deployments manage it for you |
ποΈ Config & Storage Kinds: "What data does my app need?"
| Kind | Use When |
|---|---|
| ConfigMap | Non-sensitive config: feature flags, app settings, URLs, anything you'd normally put in a .env file that isn't secret |
| Secret | Sensitive data: passwords, API keys, tokens (remember: base64-encoded, not encrypted, by default) |
| PersistentVolumeClaim (PVC) | Your app needs storage that survives restarts |
| PersistentVolume (PV) | The actual storage resource (usually created automatically via a StorageClass, rarely by hand) |
| StorageClass | Defines how dynamic storage gets provisioned: you reference it by name from a PVC |
π Networking Kinds: "How does traffic reach my app?"
| Kind | Use When |
|---|---|
| Service | Give a stable address to a group of Pods |
| Ingress | Route external HTTP(S) traffic to different Services based on hostname/path (/api β backend, / β frontend) |
| NetworkPolicy | Restrict which Pods can talk to which other Pods (zero-trust segmentation) |
π Security & Access Kinds: "Who's allowed to do what?"
| Kind | Use When |
|---|---|
| ServiceAccount | An identity a Pod uses to talk to the Kubernetes API itself (not for humans: for the app/process) |
| Role / ClusterRole | Define a set of permissions (Role = namespace-scoped, ClusterRole = cluster-wide) |
| RoleBinding / ClusterRoleBinding | Actually grant a Role/ClusterRole to a user or ServiceAccount |
π Scheduling & Policy Kinds: "Where/how should things run, and what limits apply?"
| Kind | Use When |
|---|---|
| Namespace | Isolate groups of resources from each other |
| ResourceQuota | Cap total CPU/memory/object-count a namespace can consume |
| LimitRange | Set default resource requests/limits so pods without explicit values don't run unbounded |
| HorizontalPodAutoscaler (HPA) | Automatically scale replica count based on CPU/memory metrics |
| PodDisruptionBudget (PDB) | Protect availability during voluntary disruptions (node drains, upgrades) |
| PriorityClass | Signal which pods matter more when the scheduler must evict something under pressure |
π‘ You will write dozens of these files. The pattern (apiVersion / kind / metadata / spec) never changes: only the contents of spec change depending on what kind you picked.
5. "Resources": Kubernetes' Word for "Things"
This word confuses almost everyone at first because it means two completely different things depending on context:
Meaning #1: A "Resource" = a type of object Kubernetes manages
When someone says "Kubernetes resources," they usually mean: Pods, Deployments, Services, Namespaces, ConfigMaps, Secrets, PersistentVolumeClaims: literally every kind of thing you can create is called "a resource" in this sense. kubectl get <resource>: here "resource" just means "which type of object do you want to list."
Meaning #2: "Resources" = CPU and memory (compute capacity)
Separately, inside a Pod's spec, you'll see a section literally called resources:: this is specifically about how much CPU and memory a container is allowed to use:
resources:
requests: # "I need AT LEAST this much to run properly"
cpu: "100m" # 100 millicores = 0.1 of one CPU core
memory: "128Mi" # 128 mebibytes of RAM
limits: # "Never let me use MORE than this"
cpu: "200m"
memory: "256Mi"
This second meaning is what caused Level 4's Pending pod (requested 999 CPUs, no computer has that much) and comes back constantly in scheduling and quota levels.
π‘ When you see "resource" alone, think "a type of object." When you see "resources:" as a YAML field, think "CPU and memory."
6. Pod - The Smallest Thing Kubernetes Runs
A Pod is the smallest unit Kubernetes actually manages. It's almost always one container, though occasionally it's a small group of tightly-coupled containers that need to live and die together (like the sidecar pattern in Level 7).
Why not just manage containers directly? Because Kubernetes needed a slightly bigger unit that can share things, like one shared network address and shared storage, between a small group of containers that truly belong together (a main app + a helper that reads its logs, for example).
Key facts about Pods you'll use constantly:
- Pods are ephemeral: temporary. They're not meant to live forever; when something needs to change, the old Pod is thrown away and a new one is created (this is why most Pod fields can't be edited live).
- Pods get their own IP address inside the cluster.
- You almost never create a Pod directly in real production work: you create a Deployment, and it creates and manages Pods for you (see next section).
7. Deployment: "Keep N Copies of This Running, Forever"
A Deployment is a promise. You tell it: "I want 3 copies of this Pod, running this image, always." The Deployment then continuously works to make that true: if a Pod dies, it creates a replacement; if you change the image, it rolls out new Pods and retires old ones gradually.
Under the hood, a Deployment doesn't manage Pods directly: it creates a ReplicaSet, and the ReplicaSet is the thing that actually counts and enforces the Pod number. Think of it as: Deployment = the plan, ReplicaSet = the enforcer, Pods = the actual result.
Deployment β creates/manages β ReplicaSet β creates/manages β Pods
(the plan) (the enforcer) (the workers)
You'll almost always use Deployments (or StatefulSets, for databases) instead of raw Pods or raw ReplicaSets: that's the whole lesson of World 2, Level 20.
8. Namespace: Separate Rooms in the Same Building
A Namespace is a way to divide one cluster into isolated sections, like separate function rooms inside one big restaurant. You could have a dev namespace, a staging namespace, and a production namespace, all in the same cluster, all kept logically separate.
Why it matters:
- Two Pods in different namespaces, by default, generally can't easily find each other by simple name (you learned this in Level 10 and again in Level 27): you need the fuller
service.namespaceaddress. - You can put access controls (RBAC), resource limits (ResourceQuota), and network rules (NetworkPolicy) on a per-namespace basis: enabling multiple teams to safely share one cluster.
- If you don't specify a namespace, Kubernetes uses a default one literally called
default: which is exactly why beginners "lose" their pods (they land indefaultinstead of the namespace they meant).
9. Service: The Stable Front Door to a Group of Pods
Here's a problem: Pods are ephemeral: they get created and destroyed constantly, and every time a new one appears, it gets a new IP address. If your other apps had to track individual Pod IPs to talk to something, everything would break constantly.
A Service solves this: it's a stable, unchanging address that automatically routes traffic to whichever Pods currently match a given set of labels: no matter how many times those Pods get replaced underneath.
Client β talks to the Service's stable address β Service finds matching Pods (via labels) β routes traffic there
The Service never "knows" about specific Pods by name: it constantly re-checks which Pods currently have matching labels, and only routes to those. This label-matching mechanism is the single most common source of "networking" bugs in the whole game (Levels 5, 6, 17, 21), because the "networking problem" is almost always actually a "the labels don't match" problem.
10. Labels & Selectors: Sticky Notes That Connect Everything
Labels are simple key-value tags you attach to objects: app: frontend, env: production, version: v2. They don't do anything by themselves: they're just sticky notes.
Selectors are how one object says "I care about anything with THESE labels." A Service's selector is how it finds its Pods. This match is always exact: app: frontend will never match a Pod labeled app: Frontend or app: front-end.
This single mechanism (labels + selectors) is how nearly everything in Kubernetes finds and groups related things, without needing to know specific names in advance.
11. The Whole Vocabulary, One More Time, Fast
| Term | Plain-English Definition |
|---|---|
| Cluster | The whole group of computers Kubernetes manages together |
| Node | One computer (physical or virtual) that's part of the cluster |
| Control Plane | The "brain": the set of processes that make decisions and keep desired state = actual state |
| kubectl | The command-line tool you use to talk to Kubernetes ("kube control") |
| Container | Your app + everything it needs, packaged to run identically anywhere |
| Image | The frozen blueprint a container is created from |
| Pod | The smallest thing Kubernetes runs: usually one container, sometimes a small tightly-coupled group |
| Deployment | A promise to keep N copies of a Pod running, with safe rolling updates |
| ReplicaSet | The mechanism (created by a Deployment) that actually enforces the Pod count |
| StatefulSet | Like a Deployment, but for apps that need stable identity + their own dedicated storage (databases) |
| Namespace | An isolated "room" inside one cluster |
| Service | A stable address that routes to a changing set of Pods, via label matching |
| Label | A key-value tag attached to an object |
| Selector | A rule saying "match anything with these labels" |
| YAML | The text format you write all your instructions in |
kind | The field in YAML that says WHAT TYPE of object you're creating |
apiVersion | The field that says which version/family of Kubernetes functionality this belongs to |
metadata | The section with name, namespace, and labels: identity, not behavior |
spec | The section with your actual desired state: what you actually want |
| Resource (meaning 1) | Any type of object Kubernetes manages (a Pod is "a resource") |
| Resources (meaning 2) | CPU/memory allocation for a container (requests and limits) |
| Events | A log of what Kubernetes actually tried and what happened: your #1 debugging tool |
| ConfigMap | Non-secret configuration data, stored in the cluster, that Pods can read |
| Secret | Like a ConfigMap, but for sensitive data: though only base64-encoded, not encrypted, by default |
| PersistentVolume (PV) / PersistentVolumeClaim (PVC) | Actual storage, and a Pod's request for some storage |
Click to show love
Discussion
Configure NEXT_PUBLIC_GISCUS_* environment variables to enable comments.