Reader — Kubernetes Command Cheat Sheet

A clean and practical reference for managing and troubleshooting Kubernetes clusters.
These are the commands I use most often.

📦 Pods (Inspect, Logs, Exec, Manage)

🔍 List & Inspect Pods

kubectl get pods
kubectl get pods -n <namespace>
kubectl get pods --all-namespaces
kubectl describe pod <pod-name>

Pods on a specific node

kubectl get pods -A -o wide | grep <node>

Pod resource requests

kubectl get pods -n <ns> -o json | jq -r '.items[] |
  "\(.metadata.name)\tCPU:\(.spec.containers[0].resources.requests.cpu)\tMEM:\(.spec.containers[0].resources.requests.memory)"'

Pod tolerations

kubectl get pods -n <ns> -o json | jq -r '.items[] |
  "\(.metadata.name)\t\(.spec.tolerations | map(.key) | join(","))"'

Pod events

kubectl describe pod <pod> -n <ns> | grep -A 10 "Events:"

Pod resource usage (metrics-server)

kubectl top pods -n <ns>

🪵 Logs

kubectl logs <pod>
kubectl logs <pod> -c <container>
kubectl logs -f <pod>
kubectl logs -l app=<label>

one-liner sample to load with a key-word

kubectl logs -n name_space "$(kubectl get pods -n name_space --no-headers | awk '/prod/ {print $1; exit}')"

💻 Exec / Shell Access

kubectl exec -it <pod> -- /bin/bash
kubectl exec -it <pod> -- /bin/sh
kubectl exec -it <pod> -c <container> -- /bin/bash

🧹 Pod Management

kubectl delete pod <pod> -n <ns>
kubectl delete pod <pod> -n <ns> --force --grace-period=0
kubectl delete pod --all -n <ns>
kubectl delete pod -n <ns> -l key=value

🌐 Services

kubectl get services
kubectl get services -n <namespace>
kubectl get services --all-namespaces

🧠 Nodes (Inspect, Usage, Manage)

🔍 Node Info

kubectl get nodes
kubectl get nodes -o wide
kubectl describe node <node>

Node labels, taints, instance type

kubectl get node <node> -o json | jq '.metadata.labels'
kubectl describe node <node> | grep Taints
kubectl get node <node> -o json | jq -r '.metadata.labels."node.kubernetes.io/instance-type"'

📊 Node Resource Usage

kubectl describe node <node> | grep -A 5 "Allocated resources"
kubectl top nodes

🛠 Node Management (Cordon / Drain / Delete)

🔹 Cordon — stop scheduling new pods

kubectl cordon <node>

🔹 Drain — evict workloads safely

kubectl drain <node> --ignore-daemonsets --delete-emptydir-data --force

🔹 Delete — remove node from Kubernetes

kubectl delete node <node> --force --grace-period=0

📘 Quick Comparison

Action Stops New Pods? Evicts Pods? Removes Node? Use Case
cordon ✔️ Prepare for maintenance
drain ✔️ ✔️ Safely remove workloads
delete ✔️ ✔️ (node gone) ✔️ Node is broken or gone

🧱 Storage (PVC)

List PVCs

kubectl get pvc -A
kubectl get pvc -n <namespace>

Describe a PVC

kubectl describe pvc <pvc-name> -n <namespace>

Check volume affinity issues

kubectl describe pod <pod> -n <ns> | grep -i volume

⛑ Pod Disruption Budgets (PDB)

kubectl get pdb -A
kubectl get pdb -n <namespace>
kubectl describe pdb <pdb> -n <namespace>

🔧 Useful Commands

Count pods on a node

kubectl get pods -A -o wide | grep <node> | wc -l

Count pods by namespace

kubectl get pods -A --no-headers | awk '{print $1}' | sort | uniq -c

List instance types in the cluster

kubectl get nodes -o json | jq -r \
'.items[].metadata.labels."node.kubernetes.io/instance-type"' | sort | uniq

Node → workload mapping

kubectl get nodes -o json | jq -r '.items[] |
  "\(.metadata.name)\t\(.metadata.labels.workload // "none")\t\(.metadata.labels."node.kubernetes.io/instance-type")"'