Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 78 ยท Getting Started

What Is Kubernetes?

Learn what Kubernetes is, which problems it solves, and why its desired-state model matters, with a runnable desired-versus-actual diff in Python.

Running one container is easy. Running two hundred of them across twenty machines, keeping them healthy, updating them without downtime and routing traffic to the right ones is a different job entirely. Kubernetes (often written K8s, because there are eight letters between the K and the s) is an open-source system that does this job for you. You tell it what you want to be running, and it keeps working until reality matches your wish.

If you have not met the idea of orchestration yet, read Why Orchestration? and the short Kubernetes overview in the Docker tutorial first. This course starts where those lessons end and goes much deeper: pods, deployments, networking, storage, security, packaging and operations.

What Kubernetes does for you

Scheduling Picks a machine with free capacity.
Self-healing Replaces what breaks.
Scaling More or fewer copies on demand.
Rollouts Updates a few copies at a time.

Four chores you would otherwise do by hand.

1 / 2

The problems it solves

Imagine you run a web shop. On one server you start containers with docker run, and that works. Then reality arrives.

  • A server dies at night. Who starts its containers somewhere else?
  • Traffic triples on Friday. Who starts more copies, and who tells the load balancer about them?
  • You ship version 2. Who replaces the old containers one by one so customers never see an error?
  • A container is alive but stuck. Who notices and restarts it?
  • Twelve teams share the same machines. Who stops one team from eating all the memory?

You could write scripts for each of these. Every company that grew large enough did exactly that, and the scripts became fragile programs of their own. Kubernetes grew out of Google's experience running such systems internally and was released as open source in 2014. Today it is maintained by the Cloud Native Computing Foundation and is available on every major cloud.

Monolith versus microservices

Kubernetes became popular alongside microservices, so the two ideas are worth separating. A monolith is one program that holds every feature of the shop (catalog, cart, payments, accounts) and is built, tested and deployed as a single unit. It is simple to start, simple to debug and fast inside (calls are plain function calls). Its limits show with size: a small change forces a redeploy of everything, one slow feature can drag down the rest, the parts must share one language and one release schedule, and you can only scale the whole program, not just the busy part.

In a microservice design the same shop is split into small services, each owning one job and its own data, talking over the network (HTTP, gRPC, queues). Teams can release independently, pick fitting technology and scale only the hot service. The cost moves from the code to the network: more moving parts, partial failures, distributed debugging and a lot more to deploy and watch.

Kubernetes does not require microservices, and a monolith runs very well in a Pod. But it is built for the problems microservices create: many small deployables, each needing replicas, a stable address, health checks, configuration and rolling updates. Starting with a well-structured monolith and splitting out services when a real need appears is a common and sensible path. See Microservices on Kubernetes for a worked example.

Desired state: the core idea

The most important idea in Kubernetes is declarative desired state. Compare two ways to get three copies of a web server running.

An imperative approach gives orders:

Terminal
docker run -d --name web1 shop-web:1.0
docker run -d --name web2 shop-web:1.0
docker run -d --name web3 shop-web:1.0

A declarative approach describes the result and leaves the steps to the system:

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

You do not need to understand every line yet; each one gets its own lesson. The point is what the file says: "I want three pods labelled app: web, each running this image." You store this wish in the cluster with kubectl apply -f web.yaml.

Now the clever part. A program inside Kubernetes (a controller) runs this loop forever:

  1. Read the desired state ("3 replicas").
  2. Observe the actual state ("2 pods are running, one node just died").
  3. Work out the difference ("1 pod is missing").
  4. Take the smallest action that closes the gap ("create one pod").
  5. Go back to step 1.

This is called a reconciliation loop. Because it compares states instead of replaying commands, it fixes problems you never anticipated. If a pod crashes, the count is two, and the loop creates a new one. If somebody deletes a pod by hand, the same thing happens. If you change replicas to 5, the loop starts two more. You will build several of these loops in later lessons; Controllers and the Reconcile Loop covers the theory in depth.

A reconcile loop you can run

Real Kubernetes cannot run inside this web page, so the examples in this course use small Python programs as stand-ins: they model the idea faithfully but are not the real implementation. Here the "cluster" is a dictionary, and the controller computes the difference between what you want and what exists.

Python Desired state versus actual state

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that the loop never says "start web3". It only knows the gap. Run it again with different numbers and it will still converge. That property, where the system aims for a target instead of following a script, is why Kubernetes can heal itself.

A second look: changing the wish

Now simulate what happens when the wish changes while the system is running. We change the desired state three times and let the loop catch up each time.

Python Changing the desired state

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The crash is handled by exactly the same code as a deliberate change. There is no special "recovery mode"; there is only a gap between two states.

What Kubernetes is and is not

Kubernetes is a container orchestration platform: it schedules, connects and supervises containers across a group of machines called a cluster. It gives you a common API, so the same manifest works on a laptop, in your data center and on any cloud.

It is not several things people sometimes expect:

  • Not a container runtime. It does not build images or run containers itself. On each machine a runtime such as containerd does that, and Kubernetes talks to it through an interface. Docker is not required.
  • Not a build system or CI/CD tool. You still need something to build images and run tests. Kubernetes only runs the results.
  • Not a database, message queue or logging stack. You can run those on top of it, but they are separate products.
  • Not simple. It solves hard problems and has many concepts. The price is learning curve and operations work; a single small app on one server rarely needs it. Cost, Reliability and Multi-Cluster returns to this question honestly.

Kubernetes does not make an application scalable by magic. Your application must tolerate being stopped, restarted and moved at any time, and it should keep important data outside the container. Designing for that is a theme of this whole course.

Where you will go from here

The course follows the order in which the ideas build on each other. First you learn the cluster's parts and the kubectl tool, then the pod (the smallest unit), then the workloads that manage pods, then networking, configuration, storage, scheduling, security, packaging and operations. Six projects at the end tie everything together. Most lessons contain read-only manifests and commands, because a cluster cannot run in the browser, plus runnable Python models that show how each mechanism works inside.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does it mean that Kubernetes is declarative?

    You store a description of the desired state, for example three replicas, and controllers compare it with the actual state and close the gap, again and again.
  2. 2. A pod crashes and the Deployment wants 3 replicas but only 2 exist. What happens?

    The reconcile loop treats a crash like any other difference between desired and actual state and creates a new pod to close it.
  3. 3. Which of these does Kubernetes NOT do by itself?

    Building images belongs to your CI system. Kubernetes schedules, heals, scales and updates containers that already exist as images.
  4. 4. Is Docker required on the nodes of a Kubernetes cluster?

    Kubernetes talks to a runtime through the Container Runtime Interface. containerd and CRI-O are the common choices, and Docker itself is not needed.

Summary

  • Kubernetes is an open-source orchestrator that schedules, heals, scales and updates containers across a cluster of machines.
  • You declare the desired state; controllers run reconcile loops that compare it with the actual state and take the smallest action that closes the gap.
  • The same loop handles deliberate changes and unplanned failures.
  • It is not a runtime, a CI system or a complete platform; it is a foundation you build on.
  • The Python stand-ins in this course model the ideas but are not the real implementation.

Next, look inside the machine: Cluster Architecture.