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
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
Verified against your live environment
An automated validation engine inspects your actual resources and configurations as you work. Completion means the task was performed — not multiple choice, real-world proficiency.
More labs like this
Inspect, Create, and Debug Your First Pod with kubectl
Author a Pod, watch its lifecycle, debug an ImagePullBackOff with describe, then prove a multi-container Pod shares localhost networking and an emptyDir volume.
Terraform Providers - Configure, Version, and Lock Dependencies
Configure the AWS Terraform provider with version constraints, explore the dependency lock file, and upgrade provider versions safely.
Deploy Azure Container Apps with Terraform
Use Terraform to define and deploy an Azure Container App with ingress, secrets, environment variables, and scaling rules.
Related reading
Environment
Every lab includes
- Real environment, pre-credentialed
- Automated checks on every step
- Isolated sandbox, auto cleanup
- AI-recommended next steps
Lab curriculum
- 01
Getting Started with Kubernetes IDE
1 automated check
- 02
Create Your First Pod Imperatively with kubectl run
1 automated check
- 03
Bootstrap a Pod Manifest with the dry-run Client Flag
1 automated check
- 04
Author a Pod Manifest from Scratch and Compare apply Against create
1 automated check
Skills validated
Not the lab you were looking for?
Browse 150+ hands-on labs across AWS, Azure, Kubernetes, Docker, and cloud security.