Lesson 4 / 410 minfundamentals, api

Everything is an object

Kubernetes has almost no verbs. You write down the state you want, and loops make it true.

There is no Kubernetes command for “deploy my app”. There is not really one for scaling up, restarting, or rolling back either (we’ll come back on that later).

There is one operation, and it is writing down what you want.

An object is a record

The unit you write down is an object. It has a kind, a name, and usually a spec or similar used to describe the state you are asking for:

kind: Deployment
metadata:
  name: web
spec:
  replicas: 3

Submitting that starts nothing. No container is created by the act of writing it down, and nothing about the file reaches a machine. It is a record, the record says three, and that is the whole of its contribution.

A loop reads the record, counts what actually exists, and bridges the differences. Remember? Yeah, you’ve been that loop.

Spec and status

Most objects have a second half that you do not write:

spec:
  replicas: 3
status:
  replicas: 2

The spec is desired state. You own it, and nothing in the cluster edits it behind your back.

The status is actual state, and it belongs to the loop that looks after that kind of object rather than to you or to the cluster at large. It is a report rather than a request. Setting status.replicas to three does not create anything, in the same way that writing a different number on a thermometer does not change the room’s temperature.

Where both halves exist, the gap between them is the only thing any loop in the system ever acts on. The panels you were reading by hand in lesson two are these two fields.

The same file, whatever the situation

Because the object is a description rather than an instruction, the same file works whether the thing exists yet or not. Send it at an empty cluster and three copies get created. Send it at a cluster already running three and nothing happens at all. Change the number to five and send the same file again, and two more appear.

That is what declarative means in practice, and a file describing an object is a manifest. You are never picking between create and update, because that distinction lives in the system rather than in you.

It also means sending the same thing twice is safe, which matters more than it sounds. A retry after a timeout is not a second deployment.

What this takes away

There is no restart button, because a restart is not a state. Nothing you can write down says “off and then on again”.

So every operation you might want turns into the same operation, done to the record:

What you wantWhat you actually do
Scale upChange a number
Roll out a new versionChange the image
Roll backPut the old record back
RestartChange something, anything, so the record differs

That last row is the one that feels wrong at first. The system has no memory of your intent, only of your record. If the record has not changed, there is nothing for a loop to do, and asking twice is the same as asking once. So the usual move is to edit some metadata so the record differs. Nothing meaningful changed, but the record did, and the record is all the loop looks at.

The kinds you will meet

You do not need these yet. They are here so the names are familiar when their lessons arrive:

KindWhat it is
PodA set of containers, run together
ReplicaSetA set of identical pods
DeploymentRollouts, on top of a ReplicaSet
ServiceOne stable name for a changing set of pods
ConfigMapSome data
SecretSome data, treated as sensitive

The first three are stacked up. A Deployment is not a bigger Pod. It manages ReplicaSets, a ReplicaSet manages pods, and a pod manages containers, and each layer only knows about the one directly beneath it. It’s simply abstractions built on other abstractions.

The word is borrowed, by the way: a pod is… a group of whales. Containers, whales, it clearly made sense to somebody… right ?

ConfigMap and Secret are by default pretty much the same object. A Secret is base64-encoded rather than encrypted (btw, encoding is NOT protection), and it is stored much like a ConfigMap is. A cluster can be set up to encrypt them at rest, but that is not the default.

This exists only to separate the concerns of both kinds. It allows for a finer permission system that we’ll talk about in a future lesson.

Here is a system, described the way somebody would describe it to you. Work out what you would write down for each part of it.

Four requirements, for each one, pick what you would write down.

Names live in a namespace

Objects sit in a namespace, which scopes their names. Two namespaces can each hold a Deployment called web without colliding, which is what lets one cluster carry a team per namespace, or staging beside production, without anyone agreeing on naming.

Not everything is scoped this way. A node is a property of the whole cluster rather than of anyone’s namespace, and there are a handful of others like it.

So there are two kinds of object: cluster-wide and namespaced.

Where this goes next

Objects are the note from your list in lesson one, and now they have a shape.

The next two lessons will follow one of them: where it goes when you submit it, and what happens afterwards.