-
-
Save robyoung/25ebf46129e085411cef4f802abff650 to your computer and use it in GitHub Desktop.
kg run kubectl commands against a name pattern
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 | |
# | |
# Kubectl grep | |
# | |
# Kubectl that replaces the target with a grep search | |
COMMAND=$1 | |
shift | |
if [ "$COMMAND" = "logs" -o "$COMMAND" = "exec" ]; then | |
RESOURCE="pods" | |
else | |
RESOURCE=$1 | |
COMMAND="$COMMAND $RESOURCE" | |
shift | |
fi | |
TARGET=$1 | |
shift | |
kubectl $COMMAND $(kubectl get $RESOURCE | grep $TARGET | awk '{ print $1 }') "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment