| name | kubernetes |
| description | Use when working with Kubernetes — pods, deployments, services, kubectl commands, cluster debugging, or any K8s-related task |
| metadata | {"author":"apyatkin"} |
Kubernetes
Company Context
To get company-specific Kubernetes settings:
- Read
~/Library/hat/state.json to get active_company
- Read
~/Library/hat/companies/<active_company>/config.yaml
- Use
cloud.kubernetes section — reads kubeconfig, 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>
kubectl get pods -n <ns> -o wide
kubectl describe pod <pod> -n <ns>
kubectl logs -f <pod> -n <ns>
kubectl logs -f <pod> -n <ns> -c <container>
kubectl logs <pod> -n <ns> --previous
kubectl logs -l app=<name> -n <ns> --prefix
kubectl exec -it <pod> -n <ns> -- /bin/sh
kubectl delete pod <pod> -n <ns>
Deployments & Rollouts
kubectl get deployments -n <ns>
kubectl rollout status deployment/<name> -n <ns>
kubectl rollout history deployment/<name> -n <ns>
kubectl rollout undo deployment/<name> -n <ns>
kubectl scale deployment/<name> --replicas=<n> -n <ns>
Resources & Events
kubectl top pods -n <ns>
kubectl top nodes
kubectl get events -n <ns> --sort-by=.lastTimestamp
kubectl get all -n <ns>
Context
kubectl config get-contexts
kubectl config current-context
kubectl config use-context <name>
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
OOMKilled in describe
- 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 for OOMKilled in 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=1h to limit scope
Source: apyatkin/hatctl — distributed by TomeVault.