Kubernetes Shell Exec All Containers

Written by Luke Arntz on January 27, 2022
[ k8s ] [ kubernetes ] [ pod ] [ shell ]

Contents

Kubernetes Shell Exec All Containers

fish script to loop through all pods

This is not great, but a start. Does not take into account pods with multiple containers, and probably other failure cases.

for n in (k get ns -o json | jq -r .items[].metadata.name)
  for p in (k get pods -n $n -o json | jq -r .items[].metadata.name)
    echo -n "$p: "; k exec $p -n $n -- ls /usr/bin/pkexec 2> /dev/null
    echo " "
  end
end

Related Articles

Top