Knaph

What is Kubernetes?

Kubernetes is a system for running containers on a cluster of machines, reliably, without you having to babysit them by hand.

The problem it solves

Say you have a container image for your app and you want it running in production. On its own, that's easy — docker run and you're done. The hard part shows up once you have more than one:

  • What happens when the machine it's running on dies?
  • How do you run 5 copies of it, spread across different machines, and load-balance between them?
  • How do you roll out a new version without downtime?
  • How does one service find another service's network address?

You could solve each of these by hand with scripts and cron jobs. Kubernetes is what happens when that gets standardized into one system.

The core idea: desired state

Instead of telling Kubernetes how to do something step by step, you tell it what you want to be true, and it continuously works to make reality match that.

For example, this manifest says "I want 3 copies of this container running, always":

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
        - name: hello-world
          image: nginxdemos/hello
          ports:
            - containerPort: 80

Apply it with:

kubectl apply -f deployment.yaml

If a machine running one of those 3 pods dies, Kubernetes notices the actual state (2 pods) no longer matches the desired state (3 pods) and starts a new one elsewhere. You never told it to do that specifically — it falls out of "make reality match what I described."

That loop — watch actual state, compare to desired state, reconcile the difference — is the idea that basically everything else in Kubernetes is built on top of.

What's next

The next lessons build on this one piece at a time: what a Pod actually is (and why you rarely create one directly), how Services give you a stable network identity for a moving set of Pods, and how to actually get a cluster running locally so you can try this yourself.

Sign in to track your progress through this course.