Created
September 8, 2022 12:28
-
-
Save weibeld/020b8ffdd1c2f9bf72bf6a53728e2f95 to your computer and use it in GitHub Desktop.
Check user of all containers in a Kubernetes cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
kubectl get pods --all-namespaces -o 'custom-columns=:.metadata.namespace,:.metadata.name,:.spec.initContainers[*].name' | | |
while read line; do | |
namespace=$(awk '{print $1}' <<<"$line") | |
pod=$(awk '{print $2}' <<<"$line") | |
containers=($(awk '{print $3}' <<<"$line" | tr , ' ')) | |
for container in "${containers[@]}"; do | |
echo -n "$namespace | $pod | $container: " | |
kubectl exec "$pod" -n "$namespace" -c "$container" -- whoami 2>/dev/null || echo "<unknown>" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment