Course contentsShow
← Cloud and Infrastructure
Lesson 1136 of 2,98922. Kubernetes ArchitectureFree lesson

Deleting Resources with kubectl delete

Methods for removing resources by name, selector, or file, including graceful termination options.

Deleting Resources with kubectl delete

You'll learn how to cleanly remove Kubernetes resources using multiple deletion strategies and graceful termination options.

What Is Resource Deletion?

Just as you created resources with kubectl create and kubectl apply, you need a way to remove them when they're no longer needed. The kubectl delete command is your cleanup tool—it tells the Kubernetes API server to remove resources from the cluster, triggering a controlled shutdown process.

Think of it like closing applications on your computer: you don't just kill the process abruptly; you click "X" and let the app save its work first. Kubernetes does the same with graceful termination.

Deletion Methods

By Name: Remove specific resources directly:

kubectl delete pod my-pod
kubectl delete service my-service

By File: Delete everything defined in a YAML file (reverses kubectl apply):

kubectl delete -f deployment.yaml

By Selector: Remove multiple resources matching labels:

kubectl delete pods -l app=nginx

Graceful Termination

When you delete a Pod, Kubernetes doesn't immediately kill it. It sends a termination signal (SIGTERM) and waits a grace period (default 30 seconds) for the container to shut down cleanly. You can adjust this:

kubectl delete pod my-pod --grace-period=60

For immediate deletion (not recommended in production):

kubectl delete pod my-pod --grace-period=0 --force

Why It Matters

Proper deletion ensures applications save data, close connections, and release resources properly. Using selectors lets you clean up entire deployments efficiently, while file-based deletion keeps your infrastructure-as-code workflow consistent.

Key Takeaway: kubectl delete removes resources by name, file, or label selector, with built-in graceful termination to ensure clean shutdowns—avoid forcing immediate deletion unless absolutely necessary.