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.
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.
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 yamland 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.
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 yamlprints YAML with no cluster needed beyond discovery. - Validate for real:
kubectl apply -f x.yaml --dry-run=serverhits admission and policy. - See defaults: add
-o yamlto inspect the object the server would store. - Strict schema:
--validate=strictrejects unknown or duplicate fields on current kubectl versions.
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
restrictednamespace; client passes, server rejects. - Output marker: messages end with
(dry run)or(server dry run).
Failure modes and caveats
Server dry-run is accurate but not free of constraints.
- Webhooks: admission webhooks with
sideEffectsother thanNone/NoneOnDryRunare 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:
generateNameobjects show placeholder results in dry-run.
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=serveragainst a staging or preview cluster before merge. - Stage 3:
kubectl diffto show reviewers the change. - Policy: admission policy (Kyverno, Gatekeeper, ValidatingAdmissionPolicy) is only exercised by server dry-run.
- 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>.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Trusting --dry-run=client to validate policy Client mode never reaches admission, so Pod Security, quota and validating webhooks are not evaluated.
- 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>.
- Giving CI read-only credentials for server dry-run The request is authorized as a real write, so it fails with Forbidden.
- Assuming dry-run proves the workload will start Image pull, scheduling and probe outcomes occur only at runtime.