Kubernetes: Cleanup & nodes
4 Kubernetes commands: Cleanup & nodes. Click a command to see what each part does.
Kubernetes: Cleanup & nodesIndex
- Whole sheet137
- Basics: cluster, namespaces & resources17
- Get & list resources23
- Context & namespace3
- Find resources9
- Debug: describe, events, logs8
- Exec, port-forward, copy4
- Deploy, roll out, roll back, scale7
- Cleanup & nodes4
- Services, DNS & networking checks6
- Environment, config & secrets of workloads9
- Create, generate & apply YAML10
- Patch, label, annotate & scale9
- Delete & force delete6
- Nodes, scheduling & access control11
- Productivity: aliases, contexts & output11
Cleanup & nodes4
kubectl delete pods -n <namespace> --field-selector=status.phase=FailedDelete failed / evicted podsDestructiveWhat each part does
delete podsdelete pods…--field-selector=status.phase=Failed…but only those in phase Failed (includes Evicted)
kubectl get pods -n <namespace> --no-headers | awk '/<pattern>/{print $1}' | xargs -r kubectl delete pod -n <namespace>Delete pods whose name matches a patternDestructiveWhat each part does
--no-headersdrop the header row so only data lines go throughawk '/<pattern>/{print $1}'for lines matching <pattern>, print column 1 (the pod name)xargs -r kubectl delete poddelete each name; -r: skip if nothing matched
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data; kubectl uncordon <node>Take a node out for maintenance and backCautionWhat each part does
drain <node>cordon the node and evict its pods--ignore-daemonsetsdon't fail on DaemonSet pods (they stay)--delete-emptydir-dataallow evicting pods that use emptyDir (that data is lost)uncordon <node>make it schedulable again
kubectl top node; kubectl describe node <node>Node usage and detailsWhat each part does
top nodeCPU/memory per nodedescribe nodecapacity, allocatable, conditions (DiskPressure, MemoryPressure) and pods on it
Nothing matches.
My DevOps Playbook by Angelo John Calleja