kubectl
komovo · website-7c8b549745-qfbjf
basics
bash# list all resources in a namespace
kubectl get all -n media
# list across all namespaces
kubectl get pods -A
# get with wide output (show node, IP)
kubectl get pods -o wide -A
# get with custom columns
kubectl get pods -o custom-columns=NAME:.metadata.name,STATUS:.status.phase
# watch
kubectl get pods -A -w
pods
bash# list by label
kubectl get pods -n media -l app=jellyfin
# show resource requests/limits
kubectl get pods -n media -o custom-columns=\
NAME:.metadata.name,CPU_REQ:.spec.containers[0].resources.requests.cpu
# describe (for debugging)
kubectl describe pod pod-name -n media
logs & exec
bash# tail logs
kubectl logs -l app=website -n www --tail=50 -f
# exec into pod
kubectl exec -it deploy/website -n www -- /bin/sh
# copy files
kubectl cp /tmp/file pod-name:/path -n ns
kubectl cp pod-name:/path /tmp/file -n ns
# previous instance logs (if restarted)
kubectl logs pod-name -n ns -p
deployments
bash# restart without downtime
kubectl rollout restart deployment/jellyfin -n media
# check rollout status
kubectl rollout status deployment/jellyfin -n media
# scale
kubectl scale deployment/jellyfin -n media --replicas=2
# view rollout history
kubectl rollout history deployment/jellyfin -n media
node
bash# node status
kubectl get node -o wide
# node details
kubectl describe node abyss
# top pods
kubectl top pod -A
# top node
kubectl top node
# cordon/drain for maintenance
kubectl cordon abyss
kubectl drain abyss --ignore-daemonsets --delete-emptydir-data
kubectl uncordon abyss