Imperative vs Declarative Pod Creation Side by Side

Beginner
AutoVerification
IsolatedSandbox
40 mDuration

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 run and 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 with kubectl apply -f
  • Author a Pod manifest from scratch in the IDE, applying minimal apiVersion, kind, metadata, and spec fields
  • Demonstrate the idempotency of kubectl apply by running it twice and observing the unchanged response
  • Contrast kubectl apply -f against kubectl create -f on the same manifest and explain the AlreadyExists error

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.

[SYSTEM] VALIDATION_ACTIVEv2.4.0
Checking resource: vpc-ingress-01...
Scanning security policy: allow-ssh...
Modules
4
Duration
40 m

Lab Curriculum

01

Getting Started with Kubernetes IDE

02

Create Your First Pod Imperatively with kubectl run

03

Bootstrap a Pod Manifest with the dry-run Client Flag

04

Author a Pod Manifest from Scratch and Compare apply Against create