You are signed in. Close

You are signed out. Close

Thank you. Your subscription has started. Close

Thank you. You will get an email when a new comic comes out. Close

We could not confirm your payment. If you paid, use the link "Sign in" at the bottom of the page. Close

Something went wrong on our side. Please try again in a moment. Close

Previous episode Kubernetes cluster: the control plane decides, the nodes run your app

What happens when you run kubectl apply

Kubernetes manifest: you write what you want, never how

Most programs wait for orders. Then they follow the orders one step at a time. A Kubernetes manifest is the YAML file you give the cluster, and it holds no steps at all.

  1. 1 You start writing Kubernetes a list of orders, step by step. It grows long, and it never ends: what if a node stops at 3 in the morning?youmy orders1. pick a node2. fetch the image3. start a container4. again, 2 timesif a node stops?

    You start writing Kubernetes a list of orders, step by step. It grows long, and it never ends: what if a node stops at 3 in the morning?

  2. 2 The control plane offers a better deal. You say what you want in the end, and it finds the steps itself.youcontrol planeKeep your steps.Just tell me whatyou want in the end.

    The control plane offers a better deal. You say what you want in the end, and it finds the steps itself.

  3. 3 So your file holds only the result: 3 copies of your image, running. A file like this is called a manifest.youcafe-menu.yamlkind: Deploymentreplicas: 3image: cafe-menu:1.0manifest

    So your file holds only the result: 3 copies of your image, running. A file like this is called a manifest.

  4. 4 Kubernetes works from that result, your desired state. Finding the steps is its job now, again and again: when a node stops, the desired state still says 3.kind: Deploymentreplicas: 3image: cafe-menu:1.0desired statecontrol plane3 wanted.The steps aremy job.

    Kubernetes works from that result, your desired state. Finding the steps is its job now, again and again: when a node stops, the desired state still says 3.

  5. 5 Jump ahead a little: you send this file with that one line, and seconds later 3 containers run on nodes you never touched. Who did all of that?kubectl apply -f cafe-menu.yaml?nodes

    Jump ahead a little: you send this file with that one line, and seconds later 3 containers run on nodes you never touched. Who did all of that?

  6. Quick check

    Two lines for your next file.'Start a containeron node-1', or'3 containersrunning': which onefits a manifest?

    Two lines for your next file.

    Show the answer

    "3 containers running". A manifest names the result you want. Picking a node and starting a container are steps, and Kubernetes finds them itself.

  7. Go further

    The two ways of asking, and the way a manifest is written.imperativeyou give theoperations yourself,one by onedeclarativeyou give the result,and the operationsare found for youreplicas: 3YAMLthe way a manifestis written: a name,a colon, a value

    The two ways of asking, and the way a manifest is written.

Next episode Pods and Deployments: why you never ask Kubernetes for a container

Share this comic

More comics