kubectl
kubernetes.kubectl
Protects against destructive kubectl operations like delete namespace, drain, and mass deletion
- 19blocking rules
- 9safe patterns
- 7Critical
- 11High
- 1Medium
[packs]
enabled = ["kubernetes.kubectl"]Evaluated when a command contains kubectl, delete, drain, cordon, taint.
Recorded verdicts
kubectl delete namespace productionBlockedkubernetes.kubectl:delete-namespacekubectl get pods -n productionAllowed
Blocking rules
Each rule ID is kubernetes.kubectl:<name>. Use it in allowlists and [policy.rules].
Criticalapi-delete-namespaceDELETE to /api/v1/namespaces/<name> removes the namespace and ALL resources in it.
Explanation
This is `kubectl delete namespace` spelled as an API call, and it destroys everything inside the namespace: - All deployments, pods, services - All configmaps and secrets - All persistent volume claims (data may be lost) It is irreversible, and the API server applies it without the CLI's confirmation or dry-run affordances. Preview what would be deleted: kubectl get all -n <namespace>
Criticalapi-delete-persistent-storageDELETE to a PVC or PV path can permanently destroy the underlying storage.
Explanation
This is `kubectl delete pvc` / `kubectl delete pv` as an API call: - Cloud disks (EBS, GCE PD, Azure Disk) may be deleted - Data is not recoverable once the volume is released - Even with a Retain policy, deleting the PV may trigger cleanup Check what is bound to it first: kubectl get pvc -A
Criticaldelete-all-namespaceskubectl delete with -A/--all-namespaces affects ALL namespaces. Very dangerous!
Explanation
The -A/--all-namespaces flag expands deletion to EVERY namespace in the cluster. This can take down your entire cluster: - Production, staging, and dev environments affected - System namespaces (kube-system) may be impacted - Cross-namespace resources and dependencies break This is almost never what you want. Always specify a namespace: kubectl delete <resource> -n <namespace> Preview cluster-wide resources: kubectl get <resource> -A
Criticaldelete-forcekubectl delete --force --grace-period=0 immediately removes resources without graceful shutdown.
Explanation
Force deletion with zero grace period is dangerous: - Pods are killed immediately (no SIGTERM, just gone) - In-flight requests fail - Data corruption risk if writes in progress - Finalizers may be skipped (resource leak) Kubernetes warns against this. Use only for stuck pods that won't terminate. Try graceful deletion first: kubectl delete pod <name> # Default 30s grace kubectl delete pod <name> --grace-period=60 # Extended grace Check why pod is stuck: kubectl describe pod <name> | grep -A5 Status
Criticaldelete-namespacekubectl delete namespace removes the entire namespace and ALL resources within it.
Explanation
Deleting a namespace destroys EVERYTHING inside it: - All deployments, pods, services - All configmaps and secrets - All persistent volume claims (data may be lost) - All ingresses and network policies - All RBAC resources scoped to the namespace This is irreversible. Even if you recreate the namespace, all resources are gone. Preview what would be deleted: kubectl get all -n <namespace> kubectl get pvc -n <namespace> Safer approach: kubectl delete deployment <name> -n <namespace> # Delete specific resources
Criticaldelete-pvkubectl delete pv may permanently delete the underlying storage.
Explanation
Deleting a PersistentVolume can permanently destroy the underlying storage: - Cloud disks (EBS, GCE PD, Azure Disk) may be deleted - NFS mounts become orphaned - Local storage data is lost Even with Retain policy, deleting the PV may trigger storage cleanup. Check what's using the PV: kubectl get pvc -A | grep <pv-name> Check storage class policy: kubectl get storageclass <class> -o yaml Preview: kubectl delete pv <name> --dry-run=client
Criticaldelete-pvckubectl delete pvc may permanently delete data if ReclaimPolicy is Delete.
Explanation
Deleting a PVC can cause permanent data loss depending on the PV's reclaimPolicy: - Delete: Underlying storage is deleted (DATA LOST) - Retain: PV is kept but becomes 'Released' (manual recovery needed) - Recycle: Deprecated, data scrubbed Check the reclaim policy: kubectl get pv <pv-name> -o jsonpath='{.spec.persistentVolumeReclaimPolicy}' Backup first: kubectl exec <pod> -- tar czf - /data > backup.tar.gz Preview: kubectl delete pvc <name> --dry-run=client
Highapi-delete-collectionDELETE to a collection path removes every resource of that type in the namespace.
Explanation
A DELETE to a path that ends at the resource type, with no /<name> after it, is the API's deleteCollection — the equivalent of `kubectl delete <type> --all`: - .../pods kills every pod in the namespace - .../services removes all services (networking breaks) - .../persistentvolumeclaims may delete all persistent data Name the single resource instead, or use a label selector: kubectl delete <resource> -l app=myapp
Highapi-delete-workloadDELETE to a workload path removes the controller and the pods it manages.
Explanation
This is `kubectl delete deployment/statefulset/daemonset/replicaset` as an API call. The controller is removed and its pods terminate; anything not stored outside the pod is gone. Check what it manages first: kubectl get all -n <namespace> -l app=<name>
Highapply-forcekubectl apply --force deletes and recreates resources, causing downtime.
Explanation
kubectl apply --force deletes the resource and recreates it from the manifest. This causes: - Downtime as pods are terminated before new ones start - Loss of any runtime modifications - Potential data loss for stateful workloads - Disruption to in-flight requests Use this only when you cannot update resources normally due to immutable field changes. Preview changes first: kubectl diff -f <file> Try server-side apply for safer updates: kubectl apply --server-side -f <file>
Highapply-prunekubectl apply --prune deletes live resources that are missing from the applied manifests.
Explanation
With --prune, apply also DELETES objects in the selected scope that the manifests no longer contain. A partial manifest directory, a wrong -l selector, or --all can remove far more than intended, and deleted workloads, services and their data-bearing claims do not come back. Preview exactly what would be pruned: kubectl apply --prune --dry-run=server -f <dir> kubectl diff -f <dir>
Highdelete-allkubectl delete --all removes ALL resources of that type. Use --dry-run=client first.
Explanation
The --all flag deletes EVERY resource of the specified type in the namespace. For example: - kubectl delete pods --all: Kills all pods (services go down) - kubectl delete svc --all: Removes all services (networking breaks) - kubectl delete pvc --all: May delete all persistent data Always preview first: kubectl delete <resource> --all --dry-run=client Safer alternative: kubectl delete <resource> -l app=myapp # Use label selectors
Highdelete-from-directorykubectl delete -f with directories or --recursive deletes many resources at once.
Explanation
Deleting from a directory or recursively removes ALL resources defined in those files: - Multiple deployments, services, configmaps deleted at once - Hard to recover if wrong directory - No confirmation or preview by default Always preview first: kubectl diff -f <directory> ls -la <directory>/*.yaml Delete specific files instead: kubectl delete -f <specific-file.yaml>
Highdelete-from-stdinkubectl delete -f - deletes every resource described by stdin without a reviewable manifest path.
Explanation
Materialize the manifest, inspect it with kubectl diff, and run kubectl delete --dry-run=client before deleting the resources.
Highdelete-workloadkubectl delete deployment/statefulset/daemonset removes the workload. Use --dry-run first.
Explanation
Deleting a workload terminates all its pods: - Deployment: All replicas terminated, service goes down - StatefulSet: Ordered shutdown, PVCs may be orphaned - DaemonSet: Removed from all nodes - ReplicaSet: Pods terminated (usually managed by Deployment) Preview first: kubectl delete <type> <name> --dry-run=client kubectl get pods -l app=<name> # Check affected pods Consider scaling down first: kubectl scale deployment <name> --replicas=0
Highdrain-nodekubectl drain evicts all pods from a node. Ensure proper pod disruption budgets.
Explanation
kubectl drain evicts ALL pods from a node, typically for maintenance. This can cause service disruption: - All pods are evicted (respecting PodDisruptionBudgets) - DaemonSet pods remain unless --ignore-daemonsets is used - Pods with local storage fail unless --delete-emptydir-data is used - Without replicas elsewhere, services go down Before draining: kubectl get pods -o wide | grep <node> # Check what's running kubectl get pdb -A # Check disruption budgets Safer approach: kubectl cordon <node> # Prevent new pods first, then drain gradually
Highscale-to-zerokubectl scale --replicas=0 stops all pods for the workload.
Explanation
Scaling to zero replicas terminates ALL pods for the workload: - Service becomes unavailable - Endpoints are removed from Service - In-flight requests are dropped - StatefulSets: Ordered shutdown from highest ordinal This is often intentional but can cause outages if done accidentally. Check current replicas: kubectl get deployment <name> --replicas=0 To restore: kubectl scale deployment <name> --replicas=<N>
Hightaint-noexecutekubectl taint with NoExecute evicts existing pods that don't tolerate the taint.
Explanation
A NoExecute taint immediately evicts pods that don't have a matching toleration. This is more aggressive than NoSchedule: - Existing pods are evicted (not just new scheduling blocked) - Can cause immediate service disruption - Pods may not have time for graceful shutdown Check current taints: kubectl describe node <node> | grep Taints Consider NoSchedule first: kubectl taint nodes <node> key=value:NoSchedule Remove taint: kubectl taint nodes <node> key=value:NoExecute-
Mediumcordon-nodekubectl cordon marks a node unschedulable. Existing pods continue running.
Explanation
kubectl cordon marks a node as unschedulable. Existing pods continue running, but no new pods will be scheduled to this node. Use cases: - Preparing for maintenance - Investigating node issues - Gradual migration To reverse: kubectl uncordon <node> Check node status: kubectl get nodes kubectl describe node <node> | grep Taints
Safe patterns
Checked first. A command that matches one is never blocked by this pack.
kubectl-getkubectl-describekubectl-logskubectl-diffkubectl-explainkubectl-topkubectl-configkubectl-apikubectl-version