Bird
Raised Fist0
Kubernetesdevops~10 mins

Deleting Pods in Kubernetes - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Deleting Pods
Identify Pod to delete
↓
Run kubectl delete pod <pod-name>
↓
API Server receives request
↓
Pod deletion process starts
↓
Pod status changes to Terminating
↓
Pod resources cleaned up
↓
Pod removed from cluster
↓
Done
This flow shows how a pod is deleted step-by-step from issuing the command to the pod being removed from the cluster.
Execution Sample
Kubernetes
kubectl delete pod my-pod
kubectl get pods
Deletes the pod named 'my-pod' and then lists all pods to confirm deletion.
Process Table
StepCommandActionPod StatusOutput
1kubectl delete pod my-podSend delete request to API servermy-pod: RunningDeletion request accepted
2API ServerMark pod as Terminatingmy-pod: TerminatingPod marked for deletion
3KubeletClean up pod resourcesmy-pod: TerminatingResources cleaned
4API ServerRemove pod from clustermy-pod: RemovedPod removed
5kubectl get podsList current podsmy-pod: Not foundNo pods named my-pod
💡 Pod 'my-pod' is deleted and no longer appears in pod list.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
Pod StatusRunningRunningTerminatingTerminatingRemovedRemoved
Key Moments - 2 Insights
Why does the pod status change to 'Terminating' instead of disappearing immediately?
The pod status changes to 'Terminating' (see execution_table step 2) because Kubernetes first cleans up resources and gracefully stops the pod before removing it completely.
What happens if you run 'kubectl get pods' immediately after deletion?
You may still see the pod in 'Terminating' status briefly (deletion is asynchronous and takes a moment to complete).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the pod status right after the delete command is sent?
ADeleted
BRunning
CTerminating
DPending
💡 Hint
Check the 'Pod Status' column at Step 1 in the execution_table.
At which step is the pod actually removed from the cluster?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look for the step where 'Pod removed' appears in the 'Output' column.
If the pod cleanup takes longer, which status will you see when running 'kubectl get pods'?
ATerminating
BRunning
CDeleted
DUnknown
💡 Hint
Refer to the 'Pod Status' during Steps 2 and 3 in the execution_table.
Concept Snapshot
Deleting Pods in Kubernetes:
- Use 'kubectl delete pod <pod-name>' to delete a pod.
- Pod status changes from Running to Terminating.
- Kubernetes cleans up resources before final removal.
- Pod disappears from 'kubectl get pods' after deletion completes.
- Deletion is asynchronous and may take a few seconds.
Full Transcript
Deleting a pod in Kubernetes starts by running the command 'kubectl delete pod <pod-name>'. This sends a request to the API server, which marks the pod as Terminating. The kubelet then cleans up the pod's resources. Once cleanup finishes, the pod is removed from the cluster and no longer appears in pod listings. The pod status changes step-by-step from Running to Terminating, then it is removed. This process is asynchronous, so the pod may still appear briefly after deletion is requested.

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

  1. Step 1: Understand the kubectl delete command

    The command kubectl delete is used to remove Kubernetes resources like pods.
  2. Step 2: Apply the command to a pod named my-pod

    Using kubectl delete pod my-pod deletes the pod named my-pod.
  3. Final Answer:

    kubectl delete pod my-pod -> Option A
  4. 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

  1. 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.
  2. Step 2: Form the correct command

    The correct command is kubectl delete pod -l app=frontend to delete pods matching the label.
  3. Final Answer:

    kubectl delete pod -l app=frontend -> Option C
  4. 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

  1. Step 1: Understand kubectl delete output

    When a pod is successfully deleted, kubectl outputs pod/POD_NAME deleted.
  2. Step 2: Apply to pod named my-pod

    Since the pod exists, the output will be pod/my-pod deleted.
  3. Final Answer:

    pod/my-pod deleted -> Option B
  4. Quick Check:

    Successful delete output = pod/POD_NAME deleted [OK]
Hint: Successful delete shows 'pod/POD_NAME deleted' message [OK]
Common Mistakes:
  • Expecting 'stopped' or 'removed' instead of 'deleted'
  • Confusing error message with success output
  • Missing the resource type prefix 'pod/'
4. You run kubectl delete pod my-pod but get an error: error: resource(s) not found. What is the most likely cause?
medium
A. The pod name is misspelled or does not exist
B. You need to use 'kubectl stop pod' instead
C. The pod is already deleted but command still runs
D. You forgot to add the namespace flag

Solution

  1. Step 1: Interpret the error message

    The error resource(s) not found means Kubernetes cannot find the pod with that name.
  2. Step 2: Identify common causes

    This usually happens if the pod name is wrong or the pod does not exist in the current namespace.
  3. Final Answer:

    The pod name is misspelled or does not exist -> Option A
  4. Quick Check:

    Resource not found = wrong pod name or missing pod [OK]
Hint: Check pod name spelling if 'resource not found' error appears [OK]
Common Mistakes:
  • Using 'stop' instead of 'delete' command
  • Assuming pod is deleted but error still shows
  • Ignoring namespace context when pod is in another namespace
5. You want to delete all pods in the namespace dev with label tier=backend. Which command correctly does this?
hard
A. kubectl delete pod -n dev --label tier=backend
B. kubectl delete pods --namespace=dev --label tier=backend
C. kubectl delete pod --namespace dev --selector tier backend
D. kubectl delete pod -n dev --selector tier=backend

Solution

  1. Step 1: Use correct flags for namespace and label selector

    The short flag for namespace is -n and for label selector is --selector or -l.
  2. Step 2: Form the correct command

    The correct command is kubectl delete pod -n dev --selector tier=backend.
  3. Step 3: Check other options for errors

    A uses invalid --label flag. B uses plural pods and invalid --label. C has invalid selector syntax --selector tier backend missing =.
  4. Final Answer:

    kubectl delete pod -n dev --selector tier=backend -> Option D
  5. Quick Check:

    Namespace and label selector flags combined correctly = kubectl delete pod -n dev --selector tier=backend [OK]
Hint: Use '-n' for namespace and '--selector' for labels to delete pods [OK]
Common Mistakes:
  • Using plural 'pods' instead of 'pod'
  • Wrong flag syntax like '--label' or missing '='
  • Mixing long and short flags incorrectly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard