Skip to content

Helpful kubernetes commands

How to get the CPU and memory requests of a pod

Terminal window
kubectl get pod <POD> -n <NAMESPACE> \
-o=jsonpath='{range .spec.containers[*]}{.name}{"→ req="}{.resources.requests.cpu}{" mem="}{.resources.requests.memory}{"\n"}{end}'

How to debug a pod in a crashloopbackoff state

If a pod is in a CrashLoopBackOff state, you can patch it to run a different command, such as sleep infinity, to keep it running for debugging purposes.

How to generate json output for a patch with yq

Terminal window
yq -o=json <<EOF > patch.json
spec:
template:
spec:
containers:
- name: metastore
command: ["sleep", "infinity"]
EOF

How to patch a deployment/statefulset with a json file

Terminal window
kubectl patch deployment <DEPLOYMENT> -n <NAMESPACE> --patch "$(cat patch.json)"
kubectl patch sts <STATEFULSET> -n <NAMESPACE> --patch "$(cat patch.json)"

How to debug network issues in the cluster with netshoot

Terminal window
kubectl run tmp-shell --rm -i --tty --image nicolaka/netshoot