Basics · Start here

Why Kubernetes Exists, Starting from a Single Container

Start here if Kubernetes is new to you. What a container is, in five minutes, then the problems that appear once you run many containers across many machines, and how Kubernetes solves them. Plus an honest look at when you don't need it.

Module: 01 of 20 Level: Basics · Start here Time: 10 min read Published:
All modules in this track (20)

In this module, you'll learn to:

  • Explain what an image, a container, and a registry are
  • Name the problems that appear when you run many containers on many machines
  • Describe what Kubernetes does about each one, and when you don't need it

Before you start: nothing. You only need to be comfortable typing commands into a terminal. Every other idea in this track is explained when it first comes up. If the Linux side is new to you, the Linux for DevOps track covers it, and its Containers from Scratch module shows what a container really is underneath.

Containers

The five-minute version

Kubernetes runs containers, so start there. A container is your application packaged together with everything it needs to run: the runtime (Python, Java, Node.js), libraries, and config files. Because it carries all of that with it, it runs the same way on your laptop, on a test server, and in production. "It works on my machine" stops being a problem.

Three words cover most of it:

  • Image: the package. A read-only snapshot of your app and its dependencies, built once from a recipe called a Dockerfile.
  • Container: a running copy of an image. You can start many containers from one image, and each is isolated from the others.
  • Registry: where images are stored and shared, such as Docker Hub or Amazon ECR. Servers pull images from a registry, the way a phone downloads an app from a store.
# A Dockerfile: the recipe for an image
# Start from an image that already has Python
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
# The app listens on port 8080
EXPOSE 8080
# What runs when the container starts
CMD ["python", "app.py"]
Scroll sideways to see the full diagram →
From source code to a running container
Dockerfile and codethe recipe and your application
docker build
Image orders-api:1.4a read-only package, built once
docker push
Registrystores the image so any machine can pull it
docker run, on any machine with a container runtime
Containera running, isolated copy of the image

If you've never run a container, install Docker Desktop (or Docker Engine on Linux). The Try it section at the end of this module runs a web server in one command, without installing the web server itself. That's the whole idea.

Problem

One container is easy, hundreds are not

Running one container on one machine is simple. Now imagine a real system: twenty services, each needing three copies for reliability, spread over ten servers. Suddenly you have questions that docker run doesn't answer:

  • Where should each container run? Which server has enough free CPU and memory right now?
  • What happens when one crashes, or a whole server dies at 3 a.m.? Who restarts it, and where?
  • How do services find each other when containers move between servers and change IP addresses?
  • How do you release a new version without taking the service down?
  • How do you handle more traffic? Who starts more copies, and stops them again later?
  • Where do passwords and settings go, without baking them into every image?

Answering these by hand, with scripts and spreadsheets of which container runs where, works for a while and then falls apart. A system that answers them for you is called a container orchestrator. Kubernetes is the one that won.

Solution

What Kubernetes does for you

Kubernetes turns a group of servers into one pool of capacity, called a cluster. You don't tell it which server to use. You describe what you want ("three copies of orders-api:1.4, reachable at the name orders-api"), and Kubernetes makes it happen and keeps it true.

ProblemWhat Kubernetes gives youWhere this track covers it
Where should it run?A scheduler that places each container on a server with roomHow a Cluster Works
It crashedAutomatic restarts and replacements, on another server if neededPods, Deployments & Rollouts
How do services find each other?Stable names and built-in load balancingServices & Cluster Networking
Releasing without downtimeRolling updates that stop if the new version is unhealthyPods, Deployments & Rollouts
More trafficAutoscaling of containers and of serversScaling & Cost
Settings and secretsConfig and secrets kept separate from imagesPods, Deployments & Rollouts
Who may change whatAccess control for people and programsNamespaces, RBAC & Service Accounts
Honest answer

When you don't need Kubernetes

Kubernetes is powerful, but it's also a platform you have to run and understand. It's not always the right choice:

  • One or two small services: a single virtual machine, or a simpler container service such as AWS App Runner or Amazon ECS, is less work.
  • Event-driven tasks that run for seconds at a time often fit serverless functions (AWS Lambda) better.
  • A small team with no one to own the platform may spend more time running Kubernetes than building the product.

It earns its place when you have many services, several teams, a need for consistent deploys across environments, or the scale where automation stops being optional. That's the situation the later parts of this track describe.

Vocabulary

Words you'll meet in the next modules

You don't need to memorise these. Each one gets its own explanation later; this is just so they look familiar.

TermOne-line meaning
ClusterA group of machines that Kubernetes manages as one
NodeOne machine in the cluster that runs containers
Control planeThe part of Kubernetes that makes decisions and stores the desired state
PodThe smallest thing Kubernetes runs: a wrapper around one (or a few) containers
DeploymentKeeps a set number of identical pods running, and updates them safely
ServiceA stable name and address in front of a group of pods
NamespaceA named section of a cluster, used to organise and separate things
kubectlThe command-line tool you use to talk to a cluster
ManifestA YAML file that describes an object you want to exist
Try it

Run, stop, and inspect a container

With Docker installed, these commands show the image, container, and registry ideas from the top of this module:

# Pull an image from Docker Hub (a registry) and run it as a container
docker run -d --name web -p 8080:80 nginx:1.27

# See running containers, and the images you have locally
docker ps
docker images

# Read the container's logs, then stop and remove it
docker logs web
docker stop web
docker rm web
Scroll sideways to see the full diagram →

Now picture doing that by hand for sixty containers across ten machines, every day. The next module gives you a real Kubernetes cluster to do it for you, on your own laptop, for free.

Implementation notes
  • Containers aren't small virtual machines. They share the host's operating system kernel, which is why they start in seconds and use far less memory than a VM.
  • Images are immutable. You never patch a running container; you build a new image and replace the container. Kubernetes is built entirely around that idea.
  • Kubernetes doesn't build images. It runs images that already exist in a registry. Building and publishing them is a separate step, covered in Container Delivery.
Recap

Key terms

  • Image: a read-only package of an app and everything it needs, built from a Dockerfile.
  • Container: a running, isolated copy of an image.
  • Registry: a store that machines pull images from, such as Docker Hub or Amazon ECR.
  • Container orchestrator: software that places, restarts, connects, and scales containers across many machines.
  • Cluster: a group of machines that Kubernetes manages as one pool of capacity.
Check yourself

Pop quiz

Five questions: three on the ideas in this module, and two scenarios where you apply them. The order changes every time you take it, and 4 out of 5 passes.

5 questions. Decide on your answer to each, then check it.

  1. Concept

    What's the difference between an image and a container?

    1. An image runs on a server; a container runs on a laptop
    2. An image is the read-only package; a container is a running copy of it
    3. A container is built from a Dockerfile; an image is pulled from a registry
    4. They're two names for the same thing
    Show answer

    An image is the read-only package; a container is a running copy of it

    You build an image once, from a Dockerfile, and start as many containers from it as you like. Each container is a running, isolated copy.

  2. Scenario

    A server running three copies of your API dies at 3 a.m. What does an orchestrator such as Kubernetes do?

    1. Pages the on-call engineer to restart the containers by hand
    2. Waits for the server to come back, then restarts them there
    3. Notices the missing copies and starts replacements on servers that have room
    4. Nothing until the next deploy
    Show answer

    Notices the missing copies and starts replacements on servers that have room

    You declared that three copies should exist. When reality no longer matches, Kubernetes starts new copies on healthy machines, without waking anyone up.

  3. Concept

    Where do servers get container images from?

    1. A registry, such as Docker Hub or Amazon ECR
    2. The Dockerfile, which they build on startup
    3. The Kubernetes control plane, which stores every image
    4. Each developer's laptop
    Show answer

    A registry, such as Docker Hub or Amazon ECR

    Images are pushed to a registry once, and every machine that needs one pulls it from there. Kubernetes runs images; it doesn't build or store them.

  4. Scenario

    Which situation is the weakest case for adopting Kubernetes?

    1. Thirty services owned by five teams, deployed to four environments
    2. A platform that needs the same deploy process across dev, test, and production
    3. One small web app run by a two-person team with no one to own a platform
    4. Workloads whose traffic swings widely during the day
    Show answer

    One small web app run by a two-person team with no one to own a platform

    Kubernetes pays off with many services, teams, and environments. For one small app, a VM or a simpler container service is usually less work.

  5. Concept

    How do you usually tell a Kubernetes cluster what to run?

    1. You choose a server and start the container on it with a script
    2. You describe the result you want, and Kubernetes works out how to get there
    3. You log in to each node and run docker run
    4. You upload the image directly to a node
    Show answer

    You describe the result you want, and Kubernetes works out how to get there

    You declare the desired state ("3 copies of this image") and Kubernetes decides where to run them and keeps them running. That idea runs through the whole track.

Questions about this learning path?

I'm happy to go into more detail on any of this: how the pieces fit together, ingress costs, RBAC design, or how I triage incidents.

anupojuprudhvi@gmail.com