Courseiva
Kubernetes Fundamentals →mediumMultiple Choice

KCNA Kubernetes Fundamentals Practice Question

A developer needs to update a running Deployment's container image from 'nginx:1.21' to 'nginx:1.23' with minimal downtime and the ability to roll back if the new version fails. Which kubectl command should be used?

⚠ Common exam trap

This question tests the misconception that any imperative command (like `edit` or `patch`) is equivalent for updating images, but the trap here is that `kubectl set image` is the simplest, most reliable imperative command specifically designed for this task, while other options introduce unnecessary complexity or risk of configuration drift.

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 set image deployment/my-deployment nginx=nginx:1.23

`kubectl set image` directly updates the container image of a running Deployment, triggering a rolling update that replaces pods gradually to minimize downtime. This command also preserves the Deployment's rollout history, enabling a simple `kubectl rollout undo` to roll back if the new image fails.

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 edit deployment my-deployment

    Why it's wrong here

    This opens an editor and is less efficient for a simple image update.

  • ✗

    kubectl apply -f updated-deployment.yaml

    Why it's wrong here

    This also works but requires a YAML file; the set image command is more direct.

  • ✗

    kubectl patch deployment my-deployment -p '{"spec":{"template":{"spec":{"containers":[{"name":"nginx","image":"nginx:1.23"}]}}}}'

    Why it's wrong here

    While this works, it is not the simplest or most common approach.

  • ✓

    kubectl set image deployment/my-deployment nginx=nginx:1.23

    Why this is correct

    The `kubectl set image` command triggers a rolling update of the Deployment, which incrementally replaces Pods running `nginx:1.21` with `nginx:1.23` while keeping the ReplicaSet available. This satisfies the minimal-downtime requirement because the controller maintains at least the desired number of healthy Pods during the transition. Additionally, the previous ReplicaSet is retained, enabling a rollback via `kubectl rollout undo` if the new image fails.

About these practice questions

This KCNA question is part of Courseiva's 930-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

4 more ways this is tested on KCNA

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. You need to update a Deployment's container image from nginx:1.14 to nginx:1.16 and ensure zero downtime. Which kubectl command should you use?

medium
  • ✓ A.kubectl set image deployment/my-deployment nginx=nginx:1.16
  • B.kubectl patch deployment my-deployment -p '{"spec":{"template":{"spec":{"containers":[{"name":"nginx","image":"nginx:1.16"}]}}}}'
  • C.kubectl edit deployment my-deployment --image=nginx:1.16
  • D.kubectl update deployment my-deployment --image=nginx:1.16

Why A: `kubectl set image` directly updates the container image in the Deployment's pod template, triggering a rolling update. Kubernetes Deployments handle zero-downtime updates by default via a rolling update strategy, which gradually replaces old pods with new ones while keeping the service available.

Variation 2. You want to update a Deployment's container image from 'nginx:1.20' to 'nginx:1.21' and record the change. Which kubectl command should you use?

medium
  • A.kubectl edit deployment nginx
  • B.kubectl apply -f deployment.yaml
  • ✓ C.kubectl set image deployment/nginx nginx=nginx:1.21 --record
  • D.kubectl set image deployment/nginx nginx=nginx:1.21

Why C: The `kubectl set image` command directly updates the container image of a specified deployment, and the `--record` flag annotates the change in the rollout history, allowing you to track the change for auditing or rollback purposes. This is the most efficient way to update the image and record the change without editing the full deployment manifest or reapplying a file.

Variation 3. You need to update a running Deployment to use a new container image. Which kubectl command should you use?

medium
  • A.kubectl replace -f deployment.yaml
  • ✓ B.kubectl set image deployment/<name> <container>=<new-image>
  • C.kubectl edit deployment <name>
  • D.kubectl patch deployment <name> -p '{"spec":{"template":{"spec":{"containers":[{"name":"<container>","image":"<new-image>"}]}}}}'

Why B: `kubectl set image` is the dedicated command for updating the container image of a running Deployment without modifying the entire manifest. It directly updates the Deployment's pod template spec, triggering a rolling update to replace pods with the new image.

Variation 4. You want to update a Deployment's container image to v2 and perform a rolling update using the simplest imperative command. Which kubectl command achieves this?

medium
  • A.kubectl update deployment my-deployment --image=myapp:v2
  • B.kubectl replace -f updated-deployment.yaml
  • C.kubectl patch deployment my-deployment -p '{"spec":{"template":{"spec":{"containers":[{"name":"my-container","image":"myapp:v2"}]}}}}'
  • ✓ D.kubectl set image deployment/my-deployment my-container=myapp:v2 --record

Why D: The `kubectl set image` command is the standard imperative way to update a container image in a Deployment, and it automatically triggers a rolling update. Option A is invalid; `kubectl update` is not a real command. Option B, `kubectl replace`, requires a full YAML file and is a declarative replacement operation, not a simple image update command. Option C, `kubectl patch`, can be used but is overly complex and error-prone for a simple image update. The question asks for the simplest imperative command, making D the best answer.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This KCNA 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 KCNA exam.