Apply, drift and three patch types

  • 12 min
  • 7 steps
  • The API and the loop

Steps

0 of 7 done

Create a Deployment declaratively, drift it by hand, preview and undo the drift with apply, patch it three ways, and watch the three-way merge decide which changes survive.

  1. Step 1 of 7

    web.yaml in the current directory describes a three-replica Deployment. Create it declaratively, so that later applies can merge against it.

    Checked against the cluster as it changes.

  2. Step 2, not started: Play the on-call engineer: change web to 5 replicas with an imperative command, without touching web.yaml.

  3. Step 3, not started: Before applying again, preview what web.yaml would change on the live Deployment, and find the replica count in the output.

  4. Step 4, not started: Bring web back to what the file says.

  5. Step 5, not started: Change the container image to nginx:1.31 with a JSON patch (--type=json) that replaces only that one field.

  6. Step 6, not started: Add the environment variable LOG_LEVEL=debug to the container named web with a patch that names the container but does not restate its image.

  7. Step 7, not started: Apply web.yaml once more. The image goes back to nginx:1.30, but LOG_LEVEL stays. Confirm both on the live Deployment, and work out from the three-way merge rules why only one of your patches was undone.

Lab terminal

Cluster time 30 seconds
kind cluster kx, Kubernetes 1.37.
Each step is checked as you work.
​
Tab completes. Up and Down recall.
Type help for more.
Terminal keys

Enter runs the command. Tab completes, and the arrow keys recall earlier commands. Control C stops a watch. On an empty line, or after Escape, Tab moves focus out of the terminal.