The most dangerous `kubectl` command


The most dangerous kubectl
command is often considered to be:
`kubectl delete all --all --namespace=<namespace>`
Why It's Dangerous:
1. Mass Deletion: The all
keyword targets multiple resource types (e.g., pods, deployments, services) but does not include all resources (e.g., secrets, persistent volumes). This can still delete critical components in a namespace, causing application downtime or data loss.
2. Namespace Scope: If run in a namespace like default
or kube-system
(for clusters with lax RBAC), it can cripple applications or even the cluster itself.
3. Ease of Use: The command is short and memorable, increasing the risk of accidental execution.
Honorable Mentions:
- `kubectl delete namespace kube-system`: Deletes Kubernetes system components, destroying the cluster. Requires elevated privileges but is catastrophic if executed.
- `kubectl apply -f malicious-config.yaml`: Applies destructive configurations (e.g., deleting resources, deploying privileged pods).
- `kubectl drain --force --ignore-daemonsets`: Forcefully removes pods from nodes, risking data loss if volumes are mishandled.
Mitigation:
- Use RBAC to limit destructive permissions.
- Always double-check namespaces and commands.
- Avoid wildcards (`--all`) in production.
- Use tools like kubectl diff
or dry-run (`--dry-run=client`) before applying changes.
In short, `kubectl delete all --all` is notorious for its balance of simplicity and destructiveness, making it a top candidate for the most dangerous command.
Subscribe to my newsletter
Read articles from ADevOpsGirl directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
