0
0
Kubernetesdevops~20 mins

kubectl apply vs create in Kubernetes - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kubectl Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Difference in behavior between kubectl create and kubectl apply

What happens if you run kubectl create on a resource that already exists in the cluster?

AIt updates the existing resource with new changes.
BIt deletes the old resource and creates a new one.
CIt ignores the command and does nothing.
DIt throws an error saying the resource already exists.
Attempts:
2 left
💡 Hint

Think about whether kubectl create is designed to add new resources or modify existing ones.

🧠 Conceptual
intermediate
2:00remaining
Effect of kubectl apply on existing resources

What does kubectl apply do when the resource already exists in the cluster?

AIt deletes the existing resource and creates a new one.
BIt throws an error saying the resource already exists.
CIt updates the existing resource with the changes from the configuration file.
DIt ignores the changes and leaves the resource as is.
Attempts:
2 left
💡 Hint

Consider how kubectl apply helps keep resources in sync with configuration files.

💻 Command Output
advanced
2:00remaining
Output of kubectl create on existing resource

What is the output when you run kubectl create -f pod.yaml if the pod already exists?

Kubernetes
kubectl create -f pod.yaml
Aerror: pods "mypod" already exists
Bpod/mypod created
Cpod/mypod configured
DWarning: pod/mypod already exists, skipping creation
Attempts:
2 left
💡 Hint

Remember that kubectl create does not update existing resources.

💻 Command Output
advanced
2:00remaining
Output of kubectl apply on existing resource

What is the output when you run kubectl apply -f deployment.yaml if the deployment already exists and is updated?

Kubernetes
kubectl apply -f deployment.yaml
Adeployment.apps/mydeployment configured
Bdeployment.apps/mydeployment unchanged
Cerror: deployment.apps "mydeployment" already exists
Ddeployment.apps/mydeployment created
Attempts:
2 left
💡 Hint

Think about how kubectl apply reports changes.

Best Practice
expert
3:00remaining
Choosing between kubectl create and apply in CI/CD pipelines

In a continuous deployment pipeline, which command is best to use to ensure the cluster matches the desired state defined in configuration files?

Akubectl get, to verify resources before deployment.
Bkubectl apply, because it can create or update resources to match the config files.
Ckubectl delete followed by kubectl create, to always start fresh.
Dkubectl create, because it ensures resources are only created once.
Attempts:
2 left
💡 Hint

Consider which command helps keep resources in sync with config files automatically.