Imperative vs Declarative Pod Creation Side by Side
Create the same Pod three ways and see how kubectl run, dry-run YAML, and hand-written manifests all converge on apply.
Lab Overview & Objectives
Every Kubernetes object lives somewhere on a spectrum from imperative to declarative. On one end sits kubectl run, a single shell command that produces a running Pod with no file to save and no history to track. On the other end sits a hand-written YAML manifest committed to Git and reconciled into the cluster with kubectl apply -f. Production teams converge on the declarative end because YAML manifests are reviewable, version-controlled, and idempotent, but most beginners discover this the slow way after months of confusing create with apply and re-typing the same long flag list at every shell prompt.
The trick most courses skip is that the two ends of the spectrum are actually connected by one flag: --dry-run=client -o yaml. That flag turns any imperative kubectl run or kubectl create into a manifest generator, giving you the speed of typing on the command line and the durability of a YAML file in the same step. In this lab, you will create the same nginx:alpine Pod three ways back to back, diff the resulting objects, watch kubectl apply -f return unchanged on a second run while kubectl create -f errors out, and inspect the kubectl.kubernetes.io/last-applied-configuration annotation that powers declarative diffing under the hood.
Objectives
Upon completion of this beginner level lab, you will be able to:
- Create a Pod imperatively with
kubectl runand inspect the live object that the server generates - Generate a Pod manifest with
kubectl run --dry-run=client -o yaml, save it to a file, and recreate the Pod withkubectl apply -f - Author a Pod manifest from scratch in the IDE, applying minimal
apiVersion,kind,metadata, andspecfields - Demonstrate the idempotency of
kubectl applyby running it twice and observing theunchangedresponse - Contrast
kubectl apply -fagainstkubectl create -fon the same manifest and explain theAlreadyExistserror
Who is this lab for?
This lab is designed for:
- Beginner Kubernetes learners who have completed the W1L1 kubectl read-only verbs lab
- CKAD candidates who want to internalize the imperative-to-declarative bridge
- Engineers writing their first YAML manifests for production clusters
Real-Time Validation
Our platform uses an automated validation engine to verify your configurations as you work through the lab modules. No multiple choice—just real-world proficiency.