Created
January 3, 2022 05:13
-
-
Save fionn/487c06fb068bcfb84d876490c53a0b43 to your computer and use it in GitHub Desktop.
Get a shell on a k8s pod
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
#!/usr/bin/env bash | |
# Usage: k8shell namespace/pod. | |
set -euo pipefail | |
mapfile -d "/" -t ns_pod <<< "$1" | |
if [ "${#ns_pod[@]}" == 2 ]; then | |
ns="${ns_pod[0]}" | |
pod="${ns_pod[1]%$'\n'}" | |
elif [ "${#ns_pod[@]}" == 1 ]; then | |
ns="default" | |
pod="${ns_pod[0]%$'\n'}" | |
else | |
echo "Pod required" 2>&1 | |
exit 1 | |
fi | |
kubectl exec -n "$ns" -it "$pod" -- /bin/bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment