Skip to content

Instantly share code, notes, and snippets.

@robyoung
Created July 9, 2019 09:10
Show Gist options
  • Save robyoung/25ebf46129e085411cef4f802abff650 to your computer and use it in GitHub Desktop.
Save robyoung/25ebf46129e085411cef4f802abff650 to your computer and use it in GitHub Desktop.
kg run kubectl commands against a name pattern
#!/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