Kubernetes
Company Context
To get company-specific Kubernetes settings:
- Read
~/Library/hat/state.jsonto getactive_company - Read
~/Library/hat/companies/<active_company>/config.yaml - Use
cloud.kubernetessection — readskubeconfig,refresh.provider,refresh.cluster
The KUBECONFIG env var should already be set by hat on. If not, set it from the config.
Commands
Pods
kubectl get pods -n <ns> # list pods
kubectl get pods -n <ns> -o wide # with node info
kubectl describe pod <pod> -n <ns> # full details
kubectl logs -f <pod> -n <ns> # follow logs
kubectl logs -f <pod> -n <ns> -c <container> # specific container
kubectl logs <pod> -n <ns> --previous # previous instance logs
kubectl logs -l app=<name> -n <ns> --prefix # logs across pods by label
kubectl exec -it <pod> -n <ns> -- /bin/sh # shell into pod
kubectl delete pod <pod> -n <ns> # delete pod (only when instructed)
Deployments & Rollouts
kubectl get deployments -n <ns>
kubectl rollout status deployment/<name> -n <ns> # watch rollout
kubectl rollout history deployment/<name> -n <ns> # revision history
kubectl rollout undo deployment/<name> -n <ns> # rollback (only when instructed)
kubectl scale deployment/<name> --replicas=<n> -n <ns> # scale (only when instructed)
Resources & Events
kubectl top pods -n <ns> # CPU/memory usage
kubectl top nodes # node resource usage
kubectl get events -n <ns> --sort-by=.lastTimestamp # recent events
kubectl get all -n <ns> # all resources
Context
kubectl config get-contexts # list contexts
kubectl config current-context # current context
kubectl config use-context <name> # switch (only when instructed)
Runbooks
Debug CrashLoopBackOff
- Describe the pod:
kubectl describe pod <pod> -n <ns> - Check events at the bottom for error messages
- Read previous instance logs:
kubectl logs <pod> -n <ns> --previous - Check resource limits — OOM kills show as
OOMKilledindescribe - Check if readiness/liveness probes are misconfigured
- If the container fails immediately, exec into a debug container or check the image
Investigate OOM Kill
- Confirm OOM:
kubectl describe pod <pod> -n <ns>— look forOOMKilledin container status - Check current usage:
kubectl top pods -n <ns> - Compare against limits in the deployment spec
- If limits are too low: increase memory limits in the deployment
- If there's a memory leak: check application logs, heap dumps
Drain Node Safely
- Cordon the node:
kubectl cordon <node>(only when instructed) - Drain:
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data(only when instructed) - Verify pods rescheduled:
kubectl get pods -o wide -A | grep <node> - When maintenance is done:
kubectl uncordon <node>(only when instructed)
View Logs Across Pods
- Find pods by label:
kubectl get pods -l app=<name> -n <ns> - Stream all at once:
kubectl logs -l app=<name> -n <ns> --prefix -f - For older logs or many pods, use
--since=1hto limit scope
Source: apyatkin/hatctl — distributed by TomeVault.