Useful debugging tools for kubernetes

Sometimes its useful to be able to run some ephemeral containers on kubernetes cluster in order to perform some debugging (i.e. dns resolution, pinging nodes, etc).

Sadly, most of the times, it can be tricky to remember all overrides so here is a small list

Run an ephemeral shell on a random node

1kubectl run -ti --restart=Never --rm debug --image=alekcander/network-diag -- sh

Run a container with specific service account

1kubectl run -ti --restart=Never --rm debug --image=alekcander/network-diag --overrides='{ "spec": { "serviceAccount": "terraform-runner" } }' -- sh

Run on a specific node

1kubectl run -ti --restart=Never --rm debug --image=alekcander/network-diag --overrides='{"spec": { "nodeName": "alekc-worker-01"}}' -- sh

Run based on specific selector (ie. amd64)

1kubectl run -ti --restart=Never --rm debug --image=alekcander/network-diag --overrides='{"apiVersion": "v1","spec": { "nodeSelector": {"kubernetes.io/arch": "amd64"}}}' -- sh

Specific host running with hostnetwork

1kubectl run -ti --restart=Never --rm debug --image=alekcander/network-diag --overrides='{"spec": { "nodeName": "alekc-worker-01", "hostNetwork": true, "dnsPolicy": "ClusterFirstWithHostNet"}}' -- sh

Copyright

Comments