Knaph

The course as a book

Introduction to Kubernetes — Part 1

Deploy something first, understand it second. This course skips the architecture lecture and starts with a working app on your screen — then uses what breaks along the way to teach you what a Pod is, why Deployments exist, and how the pieces of a cluster work together.

First Contact

Setup: Get Your Cluster Running

Do this once — everything after this assumes it's already done.

Using our hosted environment? If you're working from the virtual machine provided through this site, skip this page entirely — minikube and kubectl are already installed and your cluster is already running. You're ready to start.

The instructions below are only for setting things up on your own machine.

If you're setting up locally and hit a snag, that's normal. Environment setup is the most boring part of any Kubernetes course, and also the part most likely to go sideways depending on your OS. Push through it once and you won't think about it again for the rest of the series.

Commands below are current as of this writing. Tools like these move fast — if something doesn't work, check minikube's own install page for your OS rather than assuming you did it wrong.

Checklist

 +--------------------------------------------------------+
 |              KUBERNETES SETUP CHECKLIST                |
 +--------------------------------------------------------+
                            |
               +------------+------------+
               | Using Hosted VM / Lab?  |
               +------------+------------+
                            |
              +-------------+-------------+
             YES                         NO
              |                           |
              v                           v
   +--------------------+     +-----------------------+
   |  SKIP THIS PAGE!   |     |  01. DOCKER CHECK     |
   |  Everything is     |     |      docker --version |
   |  already running!  |     +-----------+-----------+
   +----------+---------+                 |
              |                           v
              |               +-----------------------+
              |               |  02. INSTALL TOOLS    |
              |               |      minikube         |
              |               |      kubectl          |
              |               +-----------+-----------+
              |                           |
              |                           v
              |               +-----------------------+
              |               |  03. BOOT CLUSTER     |
              |               |      minikube start   |
              |               +-----------+-----------+
              |                           |
              +-------------+-------------+
                            |
                            v
               +-------------------------+
               |  04. SANITY CHECK       |
               |      kubectl get nodes  |
               +------------+------------+
                            |
              +-------------+-------------+
            READY                      NOT READY
              |                           |
              v                           v
    +------------------+        +-------------------+
    |     ALL SET!     |        |   TROUBLESHOOT:   |
    | Ready to deploy  |        | * Docker running? |
    | in 5 minutes!    |        | * minikube delete |
    +------------------+        | * minikube start  |
                                +-------------------+
  • Docker is installed and running This course assumes you already have this from your container background. Confirm it with:
  docker --version
Shell

If that fails, stop here and get Docker installed first — everything else depends on it.

  • Install minikube minikube runs a real (small) Kubernetes cluster locally, using Docker as its driver.

macOS (Homebrew)

  brew install minikube
Shell

Linux

  curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
  sudo install minikube-linux-amd64 /usr/local/bin/minikube
Shell

Windows (Chocolatey)

  choco install minikube
powershell

Whichever path you took, confirm it worked:

  minikube version
Shell
  • Install kubectl kubectl is how you'll talk to the cluster — it's the CLI you'll use for basically everything in this course.

macOS (Homebrew)

  brew install kubectl
Shell

Linux

  curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
  sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
Shell

Windows (Chocolatey)

  choco install kubernetes-cli
powershell

Confirm it's installed:

  kubectl version --client
Shell
  • Start your cluster
  minikube start
Shell

The first run will take a few minutes — it's downloading a small VM image and setting up the cluster underneath you. Don't worry about what's happening in there yet. That's the whole point of this course.

  • Confirm the cluster is alive
  kubectl get nodes
Shell

You should see one node, with a status of Ready. If you see that, your cluster is up and you're done.

Sanity check

If kubectl get nodes returns a Ready node, close this page and move on — you're deploying something in the next five minutes.

If it doesn't, the most common culprits are: Docker not running, minikube using the wrong driver, or a firewall blocking minikube's VM. Re-run minikube start, and if it still fails, minikube delete and try again clean before troubleshooting further — it's usually faster than debugging a half-started cluster.

Lesson page →

Getting Started

You're going to run something on a real Kubernetes cluster in the next five minutes, and you're going to do it before you know what half these words mean.

That's on purpose. You'll understand why it worked a lot better once you've seen that it worked.

lesson-01-doodle-01.png

Make sure your cluster is up

If you haven't already, confirm your cluster is running:

kubectl get nodes
Shell

You should see one node with a status of Ready. If you don't, go back to the setup page before continuing.

Deploy something

Run this:

kubectl create deployment hello-web --image=nginx
Shell

That's it. One line. Kubernetes just went and did a handful of things on your behalf — you'll find out exactly what, later. For now, check that it's actually running:

kubectl get pods
Shell

You should see something like:

NAME                          READY   STATUS    RESTARTS   AGE
hello-web-7d9f8c9d6b-x2k4p    1/1     Running   0          12s

Running is the word you want. If you see ContainerCreating, wait a few seconds and run the command again — it's still pulling the image.

See it with your own eyes

A running Pod isn't much to look at in a terminal. Let's make it visual. Forward a local port to it:

kubectl port-forward deployment/hello-web 8080:80
Shell

Leave that running, and open localhost:8080 in a browser.

You should see the nginx welcome page — the same one you'd get running docker run -p 8080:80 nginx locally. Except this isn't running locally. It's running inside a small virtual cluster that Kubernetes is managing for you, and you told it what you wanted, not how to get there.

When you're done looking at it, press Ctrl+C to stop the port-forward.

What you just did

You ran one command. Kubernetes:

  • Found somewhere to put your container
  • Started it
  • Kept it running

You didn't tell it where to run, or how to keep it running. You just said "I want nginx running," and it figured out the rest.

That gap — between the one line you typed and everything Kubernetes actually did to make it true — is where this course lives. Next, we'll pull that command apart and find out what actually got created when you ran it. (Hint: it's not what docker run would have created.)

Takeaways

  • kubectl create deployment <name> --image=<image> is enough to get a container running on a Kubernetes cluster — no config files needed yet.
  • kubectl get pods tells you whether it's actually running. Running is the status you want; ContainerCreating just means give it a moment.
  • kubectl port-forward lets you reach something running inside the cluster from your own machine, without exposing it to the outside world.
  • You told Kubernetes what you wanted, not how to do it. That one-line command hid a lot of decisions — where to run it, how to keep it running — that Kubernetes made for you. That's the gap the rest of this course fills in.

Lesson page →

What Actually Happened When You Ran That Command

lesson-02-doodle-01.png

You might think kubectl create deployment hello-web --image=nginx did roughly what docker run nginx does — start a container, hand you back something you can point at and say "that's my container." That's a completely reasonable guess. It's also not what happened. Kubernetes never runs a container directly. It always wraps it in something first — a Pod — and that Pod is the thing actually running, not the container itself.

If you went looking for "the container" in Kubernetes and kept finding this other word instead, you're not missing something. The container isn't the unit Kubernetes deals in. The Pod is.

See the chain for yourself

Go back to your terminal and ask Kubernetes what actually exists right now:

kubectl get all
Shell

You'll see more than you expected from one command. Something like:

NAME                             READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/hello-web        1/1     1            1           4m
 
NAME                                        DESIRED   CURRENT   READY   AGE
replicaset.apps/hello-web-7d9f8c9d6b        1         1         1       4m
 
NAME                                READY   STATUS    RESTARTS   AGE
pod/hello-web-7d9f8c9d6b-x2k4p      1/1     Running   0          4m

Three objects. You asked for one thing and got a chain:

  • A Deployment (hello-web) — the thing you actually created
  • A ReplicaSet (hello-web-7d9f8c9d6b) — created by the Deployment. We'll come back to what this does later; for now, just notice it exists and that you didn't create it directly.
  • A Pod (hello-web-7d9f8c9d6b-x2k4p) — created by the ReplicaSet. This is the thing that's actually running your container.

Notice the naming — the Pod's name is the ReplicaSet's name plus a random suffix, and the ReplicaSet's name is the Deployment's name plus a suffix. That's not decoration. It's a paper trail: each object tells you exactly who made it.

So what is a Pod?

A Pod is the smallest thing Kubernetes will run for you. Not a container — a Pod. Concretely, a Pod is a thin wrapper around one or more containers that guarantees a few things about them: they'll be scheduled onto the same machine together, they'll share a network address, and Kubernetes will manage their lifecycle as a single unit.

Most of the time, a Pod wraps exactly one container — which is exactly why it's easy to mentally collapse "Pod" and "container" into the same thing. Your hello-web Pod is a good example: one Pod, one nginx container, and functionally it feels like you just ran a container. The distinction only becomes visible the moment you ask Kubernetes to describe what it made — which is exactly what you just did.

Look inside the Pod

You can confirm the container is in there, not floating on its own:

kubectl describe pod hello-web-7d9f8c9d6b-x2k4p
Shell

(Use your own Pod's name from kubectl get pods — that random suffix will be different on your machine.)

Scroll to the Containers: section. You'll see your nginx container listed underneath the Pod — a resource inside a resource, not a peer to it.

Takeaways

  • Kubernetes doesn't run containers directly — it always wraps them in a Pod first.
  • One kubectl create deployment command created a chain of objects: Deployment → ReplicaSet → Pod, each one created by the one before it.
  • The Pod is the smallest unit Kubernetes actually schedules and runs. A container never exists on its own inside Kubernetes — it's always inside a Pod.
  • Most Pods wrap exactly one container, which is why the distinction is easy to miss — until you ask kubectl what's really there.

Lesson page →

The Pod

Why the Pod Had to Exist

lesson-03-doodle-01.png

You've already met the Pod — you saw one get created in the last lesson, wrapping your nginx container. But so far it's just looked like unnecessary paperwork: why wrap a container in something else at all? Why not just run containers and be done with it?

Here's the problem that made the Pod necessary.

Say you're running a web app, and you also want a small helper process next to it — something that ships its logs somewhere, or watches a file and reloads config when it changes. Nothing fancy. But these two processes need to be close: they need to talk to each other over localhost, and if one goes down, you want them to go down and come back together, not drift out of sync.

First attempt: cram both processes into one container. One image, one entrypoint script that starts both. It works, technically — but now you've got a container that violates basically every rule you just learned about containers. One process per container was the whole point. Now you can't update the logging helper without rebuilding and redeploying your entire app image. You can't scale them independently. Your "container" is really two programs wearing a trench coat.

So, second attempt: split them into two separate containers, and just hope the scheduler puts them on the same machine. This mostly works — until the one day it doesn't. Your cluster gets busier, the scheduler makes a different call, and your app container and your logging container end up on two different nodes. localhost doesn't mean the same machine anymore. The two processes that were supposed to be talking to each other are now separated by a network they don't know exists.

What was actually needed wasn't "please schedule these near each other" — that's a request, and requests get denied when the cluster's busy. What was needed was a guarantee: these containers are inseparable, scheduled together or not at all, sharing a network address so they can reach each other over localhost no matter what else is happening on the cluster.

That guarantee is the Pod. Not a fancier container — a promise the scheduler is willing to keep.

This wasn't a hypothetical

This isn't just a plausible-sounding story — it's roughly what happened. Kubernetes wasn't Google's first attempt at this problem. Years before Kubernetes existed, Google was running a system internally called Borg, and Borg had the same tightly-coupled-processes problem you just walked through. Its answer was a grouping called an "alloc" — short for resource allocation — which co-scheduled a handful of containers together for exactly the sidecar-logging, cache-warming kind of setup described above.

Brian Grant, who worked on Borg and later became Kubernetes' design lead, has written that the team debated something you might expect: whether to skip all this and just let each Pod hold exactly one container, the way a lot of container tooling at the time assumed you would. They decided against it — keeping the one-app-per-container discipline inside each container, while still letting a Pod hold more than one when the situation genuinely called for it, which is why your containers field is a list even though you've only ever put one thing in it.

The name itself is a small piece of that same thinking: a Pod, as in a pod of whales — a group that moves and survives together, not a single animal with a fancier name.

See the guarantee in your own Pod

Your hello-web Pod only has one container in it, so this guarantee is invisible right now — there's nothing else in there to keep a promise about. But the promise is built into the Pod's shape either way. Check it yourself:

kubectl get pod hello-web-7d9f8c9d6b-x2k4p -o yaml
Shell

Look for the containers: field in the output.

Output:

spec:
  containers:
  - image: nginx
    name: hello-web
    ...

Notice containers is plural, and its value is a list — even though you only put one thing in it. That's not an accident of the YAML format. A Pod's spec was built from day one to hold more than one container, sharing that same network address and being scheduled as one inseparable unit. You're just not using that capacity yet.

The formal shape

A Pod guarantees three things about everything inside it:

  • Co-scheduling — every container in a Pod lands on the same node, together, or the Pod doesn't run at all.
  • Shared network — every container in a Pod shares one IP address and can reach each other over localhost.
  • Shared lifecycle — the containers in a Pod start, stop, and restart as a unit, not independently.

Most Pods, like yours, only need that guarantee for one container — which is exactly why it's easy to forget the guarantee exists at all. It's only when you add a second container that you'd actually notice the difference between "these are running near each other" and "these are running together, guaranteed."

Takeaways

  • The Pod exists to solve a specific problem: tightly coupled containers need a guarantee that they'll be scheduled together and share a network — not just a hope that the scheduler happens to place them nearby.
  • A Pod's containers field is a list even when you only use one slot. The Pod was designed to hold more from the start.
  • Three guarantees define a Pod: containers inside it are co-scheduled, share a network address, and share a lifecycle.
  • This isn't a made-up scenario — Google's earlier system, Borg, solved the same problem with a grouping called an "alloc," and the team behind Kubernetes carried that lesson forward deliberately when they designed the Pod.

Lesson page →

The Pod Nobody's Watching

lesson-04-doodle-01.png

There's another command that creates something running on your cluster: kubectl run. It looks like a cousin of kubectl create deployment — similar syntax, same --image flag, same kind of result on screen. You might think it's just a shortcut for kubectl create deployment — fewer keystrokes, same result. That's a reasonable guess; both commands end with a Pod running your container, and both feel equally "correct" the first time you type them. But they don't create the same thing. kubectl create deployment creates a Deployment, which creates a ReplicaSet, which creates a Pod — the chain you saw back when you ran kubectl get all. kubectl run skips all of that and creates a bare Pod, directly, with nothing behind it.

That difference sounds small right now. It isn't. It's the difference between a Pod something is watching over, and a Pod that's entirely on its own.

Try it yourself

Create a second Pod, this time with kubectl run:

kubectl run lonely-pod --image=nginx
Shell

Now check what actually got created:

kubectl get all
Shell

Output:

NAME                             READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/hello-web        1/1     1            1           25m
 
NAME                                        DESIRED   CURRENT   READY   AGE
replicaset.apps/hello-web-7d9f8c9d6b        1         1         1       25m
 
NAME                                READY   STATUS    RESTARTS   AGE
pod/hello-web-7d9f8c9d6b-x2k4p      1/1     Running   0          25m
pod/lonely-pod                      1/1     Running   0          8s

Look closely at lonely-pod. Unlike hello-web-7d9f8c9d6b-x2k4p, its name has no random suffix tacked onto it — because nothing generated it from a template. There's no ReplicaSet above it, and no Deployment above that. It showed up in the Pod list and nowhere else. Compare that to the three-layer chain sitting right above it for hello-web, created by one call to kubectl create deployment back in the last lesson.

Same kind of object. Completely different amount of company.

Why this matters

A Deployment doesn't just create a Pod once and walk away — it keeps watching. If that Pod disappears, the Deployment (through its ReplicaSet) notices and creates a replacement. lonely-pod has no Deployment, so it has no one watching. If it disappears, it just… disappears. Nothing is checking whether it's supposed to still be there.

Right now, lonely-pod is sitting there running, indistinguishable from hello-web's Pod if you only look at kubectl get pods. Both say Running. Both look equally healthy.

Takeaways

  • kubectl run and kubectl create deployment both produce a running Pod, but they are not shortcuts for each other.
  • kubectl create deployment builds the full chain: Deployment → ReplicaSet → Pod. kubectl run creates a bare Pod with nothing above it.
  • A bare Pod looks identical to a Deployment-managed Pod in kubectl get pods — the difference only shows up in kubectl get all, where you can see what (if anything) owns it.
  • "Nothing owns this Pod" isn't a technicality. It determines what happens next if the Pod ever goes away.

Lesson page →

Some Pods Come Back. Some Don't.

lesson-05-doodle-01.png

You've got two Pods running right now: hello-web, created through a Deployment, and lonely-pod, created bare with kubectl run. Last lesson, they looked identical — both Running, both healthy, no visible difference between them.

You might think deleting a Pod is a simple, final thing: you delete it, it's gone, end of story. For one of these two Pods, that's exactly true. For the other, it isn't even close.

The command you'll use for this is kubectl delete pod <name> — it does exactly what it says, telling Kubernetes to remove a specific Pod. You'll pair it with kubectl get pods, which you've already used earlier in this course, to check what's left behind.

Delete the one nobody's watching

Start with lonely-pod:

kubectl delete pod lonely-pod
Shell

Check what's left:

kubectl get pods
Shell

Output:

NAME                             READY   STATUS    RESTARTS   AGE
hello-web-7d9f8c9d6b-x2k4p       1/1     Running   0          30m

lonely-pod is gone. Not restarting, not pending — just gone. Nothing in the output even hints that it ever existed.

Now delete the one Kubernetes is watching

Find your hello-web Pod's name and delete it:

kubectl delete pod hello-web-7d9f8c9d6b-x2k4p
Shell

Check again:

kubectl get pods
Shell

Output:

NAME                             READY   STATUS    RESTARTS   AGE
hello-web-7d9f8c9d6b-9m3qz       1/1     Running   0          6s

There's a Pod named hello-web again — but look at the suffix. It's different. 9m3qz, not x2k4p. This isn't the Pod you deleted, brought back to life. It's a brand new Pod, created from scratch, seconds after the old one disappeared. You didn't run any command to make that happen. You deleted a Pod, walked away for a moment, and came back to find a replacement already running.

Why one came back and the other didn't

Go back to what you saw in Lesson 2's kubectl get all: hello-web's Pod wasn't created directly — it was created by a ReplicaSet, which was created by a Deployment. That ReplicaSet has one job: make sure the number of running Pods matches the number it was told to maintain. It's not a one-time setup step. It keeps checking, continuously, for as long as it exists.

When you deleted hello-web's Pod, the ReplicaSet noticed the count had dropped below what it expected, and it did the only thing it knows how to do — it created a new Pod to bring the count back up. It didn't know or care that you deleted the old one on purpose. It just saw a gap between "how many Pods should exist" and "how many Pods actually exist," and closed it.

lonely-pod never had a ReplicaSet behind it. When it disappeared, there was no gap for anything to notice, because nothing was tracking whether it should exist in the first place.

This has a name: reconciliation

In plain English, to reconcile two things means to make them agree — to settle a difference between what should be true and what actually is true. You've probably heard the word from bank accounts: reconciling a statement means checking what your records say against what actually happened, and fixing any mismatch.

In Kubernetes, reconciliation means the same thing, just automated and constant. The ReplicaSet holds onto a desired number — how many Pods it's supposed to have. It compares that against the actual number — how many Pods currently exist. When those two numbers disagree, it takes action to make them agree again, by creating or removing Pods until the count matches.

That's exactly what you watched happen. Desired: 1. Actual dropped to 0 the moment you deleted the Pod. The ReplicaSet noticed the mismatch and reconciled it — bringing actual back up to 1 by creating a new Pod. This idea, comparing what's desired against what's real and correcting the gap, shows up constantly in Kubernetes. The ReplicaSet is just the first place you're seeing it.

Takeaways

  • Deleting a Pod doesn't always mean it's gone for good — it depends on whether something is managing it.
  • A ReplicaSet doesn't just create Pods once. It continuously checks the actual Pod count against the desired count, and creates new Pods whenever the two don't match. This constant checking-and-correcting is called reconciliation, and it shows up throughout Kubernetes, not just here.
  • The replacement Pod is not the same Pod restarted — it's a new one, with a new name. Kubernetes doesn't bring the old Pod back to life, it replaces it.
  • A bare Pod, created with kubectl run, has no ReplicaSet watching it — so once it's gone, nothing brings it back.

Lesson page →

What the Deployment Actually Does

lesson-06-doodle-01.png

You might think the Deployment was the thing that brought your Pod back to life during the delete experiment — it's the object you actually created, back when this all started, and "keeps things running" sounds exactly like a Deployment's job. It wasn't. That was the ReplicaSet, working entirely on its own, without the Deployment lifting a finger.

So if the ReplicaSet does the watching, and the ReplicaSet does the reconciling — what is the Deployment actually for?

The command you'll use to find out is kubectl scale — it tells Kubernetes to change how many replicas of something you want running. It's not exclusive to Deployments; you can point it at a few different kinds of objects. Here, you'll point it at your Deployment.

Watch the Deployment do something the ReplicaSet can't

Scale your Deployment up:

kubectl scale deployment hello-web --replicas=3
Shell

Check what happened:

kubectl get all
Shell

Output:

NAME                             READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/hello-web        3/3     3            3           40m
 
NAME                                        DESIRED   CURRENT   READY   AGE
replicaset.apps/hello-web-7d9f8c9d6b        3         3         3       40m
 
NAME                                READY   STATUS    RESTARTS   AGE
pod/hello-web-7d9f8c9d6b-9m3qz      1/1     Running   0          10m
pod/hello-web-7d9f8c9d6b-p7j2q      1/1     Running   0          8s
pod/hello-web-7d9f8c9d6b-rz4wn      1/1     Running   0          8s

Notice what stayed the same: it's still the same ReplicaSet as before, hello-web-7d9f8c9d6b. Its DESIRED count just changed, from 1 to 3, and it went and reconciled that new number the same way it reconciled the Pod you deleted earlier — by creating Pods until actual matched desired.

You didn't touch the ReplicaSet directly, and you definitely didn't touch any Pod directly. You told the Deployment what you wanted, and the Deployment updated the ReplicaSet's desired count on your behalf.

So what's the actual division of labor?

The ReplicaSet's job is narrow: keep the actual Pod count matching whatever desired count it's been given. That's it. It doesn't know anything about your intentions, your rollout history, or what image version you're supposed to be running. It just watches a number.

The Deployment's job is to manage that ReplicaSet on your behalf — updating its desired count when you scale, and, when you eventually change something bigger like the container image, creating a brand new ReplicaSet and shifting Pods over to it gradually rather than editing the old one in place. You won't do that part yet; it's a lesson of its own. For now, the important part is this: you talk to the Deployment. The Deployment talks to the ReplicaSet. The ReplicaSet talks to the Pods. Each layer only knows about the one directly below it.

Takeaways

  • The ReplicaSet handles reconciliation — matching actual Pods to a desired count. That's the same behavior you saw bring hello-web back after deleting it.
  • The Deployment doesn't reconcile Pods directly. It manages the ReplicaSet, and the ReplicaSet does the reconciling.
  • Scaling a Deployment doesn't create a new ReplicaSet — it just changes the desired count on the existing one, which then reconciles toward that new number.
  • Each layer only talks to the one below it: you talk to the Deployment, the Deployment talks to the ReplicaSet, the ReplicaSet talks to the Pods.

Lesson page →