⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Kubernetes Interview Questions Scenario 159 of 207 in Kubernetes
Senior DevOps / SRE [L2] Kubernetes Additional Kubernetes Scenarios (Q101-Q200) Production Scenario [L2]
🎯 Target Role / Context: Kubernetes Scenario #149 (L2) · Additional Kubernetes Scenarios (Q101-Q200)

Q: What is the significance of the `--dry-run=server` flag vs `--dry-run=client`?

kubectl --dry-run=server vs client comes down to where the request is processed: with client kubectl builds and prints the object locally and never contacts the API server for it, while with server the API server runs the full.

#Kubernetes #L2 #Container Orchestration #K8s #Comparisons
🎙️ Candidate Opening & Architectural Context
"<strong>kubectl --dry-run=server vs client</strong> comes down to where the request is processed: with <code>client</code> kubectl builds and prints the object locally and never contacts the API server for it, while with <code>server</code> the API server runs the full request path (authentication, authorization, admission, validation) and then stops before persisting. Interviewers use it to test whether you know why a manifest can pass a client dry-run and still be rejected on a real apply."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: <strong>kubectl --dry-run=server vs client</strong> comes down to where the request is processed: with <code>client</code> kubectl builds and prints the object locally and never contacts the API server for it, while with <code>server</code> the API server runs the full request path (authentication, authorization, admission, validation) and then stops before persisting. Interviewers use it to test whether you know why a manifest can pass a client dry-run and still be rejected on a real apply.

1️⃣

Mental model: three values, three behaviours

The flag accepts none (default), client and server. The old bare --dry-run and --dry-run=true forms are deprecated.

  • client: no object is sent; useful for generating YAML with -o yaml and basic schema validation.
  • server: request is sent with the dry-run flag; the object goes through admission and validation but is not stored.
  • Response: server mode returns the object as it would be stored, including defaults and webhook mutations.
  • Side effects: none persisted in either mode.
2️⃣

Hands-on: --dry-run=server vs client in practice

Use each mode for what it is good at.

# client: generate YAML locally
kubectl create deployment my-app --image=registry.example.com/my-app:1.4.0 \
  --dry-run=client -o yaml > deploy.yaml

# server: run through admission without persisting
kubectl apply -f deploy.yaml -n prod --dry-run=server -o yaml | head -n 30
# deployment.apps/my-app created (server dry run)
  • Scaffold manifests: kubectl create deploy ... --dry-run=client -o yaml prints YAML with no cluster needed beyond discovery.
  • Validate for real: kubectl apply -f x.yaml --dry-run=server hits admission and policy.
  • See defaults: add -o yaml to inspect the object the server would store.
  • Strict schema: --validate=strict rejects unknown or duplicate fields on current kubectl versions.
Advertisement
3️⃣

Verify what each mode catches

A concrete comparison shows the significance.

kubectl apply -f privileged-pod.yaml -n restricted-ns --dry-run=client
# pod/priv created (dry run)

kubectl apply -f privileged-pod.yaml -n restricted-ns --dry-run=server
# Error from server (Forbidden): pods "priv" is forbidden: violates PodSecurity "restricted:latest"
  • Client misses: missing namespace, name conflicts with immutable fields, ResourceQuota or LimitRange violations, Pod Security admission, validating webhooks, RBAC denial.
  • Server catches: all of the above because they run in the API server.
  • Test: apply a Pod that violates a Pod Security restricted namespace; client passes, server rejects.
  • Output marker: messages end with (dry run) or (server dry run).
4️⃣

Failure modes and caveats

Server dry-run is accurate but not free of constraints.

  • Webhooks: admission webhooks with sideEffects other than None/NoneOnDryRun are rejected for dry-run requests.
  • Permissions: the caller needs the real verb (create, patch) on the resource, so read-only CI users fail.
  • Dependencies: a namespace or CRD that is itself only in the same manifest set does not exist yet, so later objects fail validation.
  • Not runtime: a passing dry-run does not guarantee scheduling success, image pulls or probe health.
  • Generated names: generateName objects show placeholder results in dry-run.
5️⃣

Production practice: layered validation in CI

Combine cheap and authoritative checks.

  • Stage 1: offline schema checks (kubeconform, --dry-run=client) on every commit.
  • Stage 2: --dry-run=server against a staging or preview cluster before merge.
  • Stage 3: kubectl diff to show reviewers the change.
  • Policy: admission policy (Kyverno, Gatekeeper, ValidatingAdmissionPolicy) is only exercised by server dry-run.
Pro Tip: Use client dry-run to generate, server dry-run to validate. Only the server answers 'will my cluster accept this?'.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: A green <code>--dry-run=client</code> proves only syntax; make <code>--dry-run=server</code> against a real cluster your CI gate so admission webhooks, quota and Pod Security are tested."
⚡ 60-Second Elevator Pitch Talking Points
  • Client dry-run builds the object locally; server dry-run sends it through the API server's admission and validation but does not persist it.
  • I verify by running server dry-run in a namespace with real policies and quota, and by comparing the printed object with <code>-o yaml</code>.
  • I automate it as a CI step after offline schema checks, followed by <code>kubectl diff</code>.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Trusting --dry-run=client to validate policy Client mode never reaches admission, so Pod Security, quota and validating webhooks are not evaluated.
  2. Using the deprecated bare --dry-run flag It is ambiguous and removed in newer kubectl versions; always specify <code>client</code> or <code>server</code>.
  3. Giving CI read-only credentials for server dry-run The request is authorized as a real write, so it fails with Forbidden.
  4. Assuming dry-run proves the workload will start Image pull, scheduling and probe outcomes occur only at runtime.
Advertisement
📥 FREE DOWNLOAD · 101-PAGE COMPANION HANDBOOK
Studying for Kubernetes & SRE Technical Rounds?
Download the complete 100-question PDF field guide covering all 11 core modules with offline diagnostic runbooks.
📥 Download PDF (Free) Read Online Guide →
Want more Kubernetes scenarios?
Explore our complete collection of scenario-based Kubernetes interview runbooks.
Browse All Kubernetes Questions →