Hands-On LabBeginner

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.

40 minEstimated time
4Guided steps
AutoVerification
IsolatedSandbox
Imperative vs Declarative Pod Creation Side by Side

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 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

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.

[CHECK] validation_activelive
Inspecting deployed resources...
Verifying configuration state...
✓ Step requirements satisfied

More labs like this

Related reading

PremiumIncluded in Premium
Duration
40 min
Steps
4

Environment

Dedicated VM IDE

Every lab includes

  • Real environment, pre-credentialed
  • Automated checks on every step
  • Isolated sandbox, auto cleanup
  • AI-recommended next steps

Lab curriculum

  1. 01

    Getting Started with Kubernetes IDE

    1 automated check

  2. 02

    Create Your First Pod Imperatively with kubectl run

    1 automated check

  3. 03

    Bootstrap a Pod Manifest with the dry-run Client Flag

    1 automated check

  4. 04

    Author a Pod Manifest from Scratch and Compare apply Against create

    1 automated check

Skills validated

Kubernetes

Not the lab you were looking for?

Browse 150+ hands-on labs across AWS, Azure, Kubernetes, Docker, and cloud security.

Explore the catalog