kubernetes/delete-deployment

Delete Deployment

Remove a deployment and all its managed pods.

deployments
management

Command

kubectl delete deployment <deployment-name>

Explanation

The 'kubectl delete deployment' command removes the specified deployment from the cluster. By default, it also deletes the replica sets and pods managed by it (cascading deletion). This is commonly used during cleanup, redeployment, or version rollbacks. You can retain underlying pods or replica sets by disabling cascading deletion.

Common Use Cases

  • Clean up old or failed deployments
  • Remove outdated versions during redeployment
  • Reset deployment state before reapplying configuration

Best Practices

  • Always confirm namespace and deployment name before deleting
  • Use '--cascade=false' for advanced debugging of underlying replica sets

Common Mistakes to Avoid

  • Accidentally deleting live production deployments without confirmation
  • Forgetting to retain replica sets when troubleshooting rollout history

Troubleshooting

Problem: Deployment deletion hangs

Solution: Check for finalizers in the deployment spec; remove them if stuck in terminating state.

Examples

Delete a deployment and its pods

kubectl delete deployment nginx-deploy

Delete deployment but retain replica sets

kubectl delete deployment nginx-deploy --cascade=false