📖 Scenario: You are managing a Kubernetes cluster where some pods are running. Sometimes, you need to delete pods manually to free resources or restart them.
🎯 Goal: Learn how to list pods, select a pod name, and delete that pod using kubectl commands.
📋 What You'll Learn
Use kubectl commands to interact with pods
List pods in the default namespace
Delete a specific pod by name
💡 Why This Matters
🌍 Real World
Deleting pods is a common task when you want to restart applications or clean up resources in a Kubernetes cluster.
💼 Career
Knowing how to manage pods with kubectl is essential for DevOps engineers and system administrators working with Kubernetes.
Progress0 / 4 steps
1
List all pods in the default namespace
Run the command kubectl get pods to list all pods in the default namespace.
Kubernetes
Hint
Use kubectl get pods to see all pods running.
2
Choose a pod name to delete
Assign the pod name my-app-pod-12345 to a variable called POD_NAME.
Kubernetes
Hint
Use POD_NAME=my-app-pod-12345 to store the pod name.
3
Delete the pod using the variable
Run the command kubectl delete pod $POD_NAME to delete the pod stored in the variable POD_NAME.
Kubernetes
Hint
Use kubectl delete pod $POD_NAME to delete the pod.
4
Confirm the pod is deleted
Run kubectl get pods again to confirm the pod my-app-pod-12345 is no longer listed.
Kubernetes
Hint
Run kubectl get pods to check the pod list after deletion.
Practice
(1/5)
1. What is the basic command to delete a pod named my-pod in Kubernetes?
easy
A. kubectl delete pod my-pod
B. kubectl remove pod my-pod
C. kubectl kill pod my-pod
D. kubectl stop pod my-pod
Solution
Step 1: Understand the kubectl delete command
The command kubectl delete is used to remove Kubernetes resources like pods.
Step 2: Apply the command to a pod named my-pod
Using kubectl delete pod my-pod deletes the pod named my-pod.
Final Answer:
kubectl delete pod my-pod -> Option A
Quick Check:
Delete pod command = kubectl delete pod POD_NAME [OK]
Hint: Use 'kubectl delete pod POD_NAME' to remove pods fast [OK]
Common Mistakes:
Using 'remove' instead of 'delete'
Trying 'kill' or 'stop' which are invalid kubectl commands
Omitting the resource type 'pod'
2. Which of the following is the correct syntax to delete all pods with the label app=frontend?
easy
A. kubectl delete pods --label app=frontend
B. kubectl delete pod --label app=frontend
C. kubectl delete pod -l app=frontend
D. kubectl remove pod -l app=frontend
Solution
Step 1: Use the correct resource type and label flag
The resource type for pods is pod (singular) and the label selector flag is -l.
Step 2: Form the correct command
The correct command is kubectl delete pod -l app=frontend to delete pods matching the label.
Final Answer:
kubectl delete pod -l app=frontend -> Option C
Quick Check:
Delete pods by label = kubectl delete pod -l LABEL [OK]
Hint: Use '-l' flag with 'kubectl delete pod' to delete by label [OK]
Common Mistakes:
Using plural 'pods' instead of 'pod'
Using '--label' instead of '-l'
Using 'remove' instead of 'delete'
3. What will be the output after running the command kubectl delete pod my-pod if the pod my-pod exists?
medium
A. Error: pod my-pod not found
B. pod/my-pod deleted
C. pod my-pod stopped
D. pod my-pod removed
Solution
Step 1: Understand kubectl delete output
When a pod is successfully deleted, kubectl outputs pod/POD_NAME deleted.
Step 2: Apply to pod named my-pod
Since the pod exists, the output will be pod/my-pod deleted.