ASSOCIATE-CLOUD-ENGINEER practice question 19 of 35

You created a Kubernetes deployment by running kubectl run nginx image=nginx replicas=1. After a few days, you decided you no longer want this…

Full set: 332 questions
You created a Kubernetes deployment by running kubectl run nginx image=nginx replicas=1. After a few days, you decided you no longer want this deployment. You identified the pod and deleted it by running kubectl delete pod. You noticed the pod got recreated. $ kubectl get pods NAME READY STATUS RESTARTS AGE nginx-84748895c4-nqqmt 1/1 Running 0 9m41s $ kubectl delete pod nginx-84748895c4-nqqmt pod nginx-84748895c4-nqqmt deleted $ kubectl get pods NAME READY STATUS RESTARTS AGE nginx-84748895c4-k6bzl 1/1 Running 0 25s What should you do to delete the deployment and avoid pod getting recreated?
Answer options
A: kubectl delete deployment nginx Correct answer
B: kubectl delete –deployment=nginx
C: kubectl delete pod nginx-84748895c4-k6bzl –no-restart 2
D: kubectl delete inginx
Correct Answer:
A. kubectl delete deployment nginx
Explanation

A Kubernetes Deployment is a controller that manages the lifecycle of Pods via a ReplicaSet. The Deployment's primary responsibility is to ensure that the actual state of the cluster matches the desired state defined in its configuration (e.g., replicas=1). When you manually delete a Pod managed by a Deployment, the ReplicaSet detects the deviation from the desired state and automatically creates a new Pod to replace it. To permanently remove the application and stop the Pods from being recreated, you must delete the controlling object, which is the Deployment itself. The command kubectl delete deployment nginx correctly targets and deletes the nginx Deployment, which then cascades the deletion to its underlying ReplicaSet and Pods.

Why Incorrect

B. kubectl delete –deployment=nginx is syntactically incorrect. The kubectl delete command expects the resource type and name as arguments, not as a flag.
C. kubectl delete pod nginx-84748895c4-k6bzl –no-restart 2 is syntactically invalid. The kubectl delete pod command has no --no-restart flag, and deleting the pod is the wrong approach anyway.
D. kubectl delete inginx is incorrect due to a typo (inginx instead of nginx) and because it omits the mandatory resource type (e.g., deployment, pod).

References

1. Kubernetes Documentation

"Deployments": "A Deployment provides declarative updates for Pods and ReplicaSets... When you delete a Deployment

it cleans up the ReplicaSets and Pods it created. You can delete a Deployment by using kubectl delete." This is demonstrated with the example: kubectl delete deployment nginx-deployment.

Source: Kubernetes Documentation - Deployments

2. Kubernetes Documentation

kubectl Cheat Sheet: The syntax for deleting resources is shown as kubectl delete ([-f FILENAME] | TYPE [(NAME | -l label | --all)]). This confirms that kubectl delete deployment nginx is the correct format

where deployment is the TYPE and nginx is the NAME.

Source: Kubernetes Documentation - kubectl Cheat Sheet

3. Google Cloud Documentation

"Deploying a containerized web application": In the "Cleaning up" section of this tutorial

the command to remove the deployment is kubectl delete deployment hello-web

reinforcing that the deployment object must be the target of the delete operation.

Source: Google Cloud Documentation - Deploying a containerized web application

Scroll to Top