kubectl helper
Common one-liners with placeholders pre-filled from the inputs below.
Fill in the four fields and copy the command for the action you need. All commands use vendor-neutral placeholders — replace the taint key node.example.com/repair with whatever your operator uses (commonly node.kubernetes.io/repair or a vendor-prefixed label). Drain commands are conservative by default; remove --ignore-daemonsets at your own risk.
Switch context
Set the active kubectl context.
kubectl config use-context cluster-a
Set default namespace
Pin the current context to a namespace so you can drop -n.
kubectl config set-context --current --namespace=tenant-foo
Cordon node
Stop the scheduler from placing new pods on the node.
kubectl cordon gpu-01
Uncordon node
Re-enable scheduling.
kubectl uncordon gpu-01
Add repair taint
Mark node as unschedulable for everything except tolerating workloads.
kubectl taint nodes gpu-01 node.example.com/repair=true:NoSchedule
Remove repair taint
Clears the taint added above.
kubectl taint nodes gpu-01 node.example.com/repair-
Drain node (respect PDBs)
Evict pods, skip DaemonSets, leave local-storage pods alone.
kubectl drain gpu-01 --ignore-daemonsets --delete-emptydir-data
Check cordon + taints
Quick verify after cordon/taint.
kubectl describe node gpu-01 | egrep "Taints|Unschedulable"
List pods on a node
Find what is currently scheduled there.
kubectl get pods --all-namespaces --field-selector spec.nodeName=gpu-01 -n tenant-foo
Tail logs (current container)
Live logs from a single container in a pod.
kubectl logs -f -n tenant-foo gpu-job-0
Previous container logs (after a restart)
Logs from the previous incarnation — useful after CrashLoopBackOff.
kubectl logs -n tenant-foo gpu-job-0 --previous
Exec into pod
Open an interactive shell.
kubectl exec -it -n tenant-foo gpu-job-0 -- bash
Ephemeral debug container
Attach a debug image alongside an existing container.
kubectl debug -n tenant-foo gpu-job-0 -it --image=nicolaka/netshoot --target=<container>
Force-delete stuck pod
When kubelet is down on the node and the pod is stuck terminating.
kubectl delete pod gpu-job-0 -n tenant-foo --grace-period=0 --force
Get events scoped to a pod
Most useful single command for "why is this pod broken".
kubectl events -n tenant-foo --for pod/gpu-job-0 --watch
Port-forward to a pod
Forward local 8080 to pod port 8080.
kubectl port-forward -n tenant-foo gpu-job-0 8080:8080
Copy file out of a pod
Pull /tmp/foo from the pod to a local path.
kubectl cp -n tenant-foo gpu-job-0:/tmp/foo ./foo