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

Written against the versions above. 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

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