Bird
0
0

You ran kubectl create -f service.yaml but got an error saying the service already exists. What should you do to update the service instead?

medium📝 Troubleshoot Q14 of 15
Kubernetes - kubectl Essential Commands
You ran kubectl create -f service.yaml but got an error saying the service already exists. What should you do to update the service instead?
AUse <code>kubectl replace -f service.yaml</code> to update the service.
BDelete the service first, then run <code>kubectl create -f service.yaml</code> again.
CUse <code>kubectl apply -f service.yaml</code> to update the existing service.
DRun <code>kubectl create -f service.yaml</code> with a different name.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the error cause

    kubectl create fails if the resource exists, so the error means the service is already present.
  2. Step 2: Choose the correct update method

    kubectl apply safely updates existing resources without deleting them, so use kubectl apply -f service.yaml.
  3. Final Answer:

    Use kubectl apply -f service.yaml to update the existing service. -> Option C
  4. Quick Check:

    apply updates existing resources safely [OK]
Quick Trick: Use apply to update existing resources, not create [OK]
Common Mistakes:
  • Trying to create again without deleting
  • Deleting resources unnecessarily
  • Using replace without understanding its effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes