CertGrid CertGrid
Hands-on Lab·Certified Kubernetes Administrator

Declarative Versus Imperative Object Management

Create the same Deployment twice, once with a command and once with a file, then look at what each left behind on the object. One remembers what you asked for; the other does not. That difference is why apply can diff and create cannot.

Foundations Guide 5 of 103 Beginner

Temporary paths and timestamps in the diff output are from this run and will differ on yours.

Any cluster does. The output below is from the four-node lab.
Server NameIP AddressOSRolesCPURAMHDD
CKA1001192.168.0.175Ubuntu 26.04 LTSControl Plane Node2 Core4 GB50 GB
CKA1001-NODE01192.168.0.176Ubuntu 26.04 LTSWorker Node2 Core4 GB50 GB
CKA1001-NODE02192.168.0.177Ubuntu 26.04 LTSWorker Node2 Core4 GB50 GB
CKA1001-NODE03192.168.0.178Ubuntu 26.04 LTSWorker Node2 Core4 GB50 GB

This guide includes

Use this when you are choosing between kubectl create and kubectl apply, or when a later apply overwrites something you set by hand. This matters because only one of them records what you asked for, and that record is what makes diffs and safe re-applies possible.

Before you start

  1. The imperative shortcut, and how to make it write YAML for you

  2. Run it for real, then ask what it remembered

  3. The declarative form, and the annotation it leaves behind

  4. Why that annotation matters: kubectl diff

  5. Which to use, and the trap in mixing them

Official sources