Courseiva
Application Deployment →easyMultiple Choice

CKAD Application Deployment Practice Question

You have a YAML file 'deploy.yaml' that defines a Deployment. Which command creates the Deployment if it does not exist, or updates it if it already exists?

⚠ Common exam trap

Many exam-takers confuse `kubectl create` (which only creates and errors on existing resources) with `kubectl apply` (which handles both create and update), or mistakenly think `kubectl replace` works like an upsert when it actually requires the resource to already exist.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

kubectl apply -f deploy.yaml

`kubectl apply -f deploy.yaml` uses declarative object configuration: it creates the Deployment if it doesn't exist, or performs a strategic merge patch to update it if it already exists. This is the standard command for managing Kubernetes resources with a desired-state file.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    kubectl replace -f deploy.yaml

    Why it's wrong here

    kubectl replace -f deploy.yaml performs a full object replacement: it sends the submitted YAML to the API server as a PUT request, overwriting the entire existing resource. If the Deployment does not already exist, replace fails with a NotFound error because it cannot replace a non-existent object. Even when the resource exists, replace is imperative and non-merge-aware, so any fields omitted from your YAML (e.g., annotations added by controllers) are dropped, unlike apply's three-way merge that preserves server-side defaults.

  • ✗

    kubectl patch -f deploy.yaml

    Why it's wrong here

    kubectl patch -f deploy.yaml is syntactically incomplete because kubectl patch expects a patch specification (JSON patch, merge patch, or strategic merge patch) as its argument, not a full Deployment manifest file. Even if you supplied a valid patch, this command would mutate the existing object in place based on the patch type, rather than reconciling the entire desired state defined in the YAML. Moreover, without a name and patch type (-p or --patch), the command would fail with an error, making it an incorrect, non-declarative choice for creating or updating a Deployment from a complete manifest.

  • ✗

    kubectl create -f deploy.yaml

    Why it's wrong here

    kubectl create -f deploy.yaml is an imperative command that submits a POST request to the API server to create a brand-new resource. If the Deployment already exists, the API server rejects the request with a Conflict error (409 AlreadyExists), so it cannot be used to update an existing Deployment. Even if the resource does not exist, create only establishes the initial resource and does not track or apply subsequent changes to the YAML file, so it does not provide the desired declarative update behavior.

  • ✓

    kubectl apply -f deploy.yaml

    Why this is correct

    kubectl apply -f deploy.yaml is the correct declarative command for this question. It sends a PATCH request using the apply semantics, which computes a three-way merge between the local YAML, the live object's current state, and the last-applied-configuration annotation (kubectl.kubernetes.io/last-applied-configuration). This creates the Deployment if it does not exist, or updates only the fields that differ from the desired state while preserving changes made by controllers or other actors. Because the question asks about a YAML deployment definition without any conditional like 'if it does not exist', apply is the idiomatic and safe way to ensure the desired state is enforced idempotently.

About these practice questions

One of 826 original CKAD practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This CKAD practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CKAD exam.