-
-
Save qrkourier/a4f72086530e43fd85f5d7b988a64c8b to your computer and use it in GitHub Desktop.
run any command in any container image in any Kubernetes namespace
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
# krun busybox whoami | |
krun(){ | |
local NAMESPACE=default | |
local PRIVILEGED=false | |
while getopts 'n:pu:' OPT; do | |
case $OPT in | |
n) NAMESPACE=$OPTARG | |
;; | |
p) PRIVILEGED=true | |
;; | |
u) RUNAS=$OPTARG | |
;; | |
esac | |
done | |
shift $(( OPTIND -1 )) | |
local IMAGE=$1; shift; | |
eval kubectl -n "$NAMESPACE" run \ | |
--privileged "${PRIVILEGED}" \ | |
--image "$IMAGE" \ | |
"${RUNAS:+ --as $RUNAS}" \ | |
--tty --stdin --rm \ | |
--restart=Never \ | |
"krun-${IMAGE//[:\/.]/-}" \ | |
--command -- \ | |
"${@}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment