Skip to content

Instantly share code, notes, and snippets.

@rca
Created January 25, 2019 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rca/4d56f29d0bdefe169569490c4a93f0f2 to your computer and use it in GitHub Desktop.
Save rca/4d56f29d0bdefe169569490c4a93f0f2 to your computer and use it in GitHub Desktop.
Execute a command within a container running in Rancher k8s
#!/bin/bash
set -e
set -x
SCRIPT_NAME=$(basename $0)
if [ -z "$4" ]; then
echo "${SCRIPT_NAME} <env> <namespace> <pod name> <command> [args]" 1>&2
exit 1
fi;
env=$1
shift
namespace=$1
shift
name=$1
shift
pod=$(compose-flow -e ${env} rancher kubectl get pods --namespace ${namespace} | \
grep "^${name}" | awk '{print $1}' | head -n1)
exec compose-flow -e ${env} rancher kubectl exec -ti --namespace ${namespace} $pod -- "$@"
@rca
Copy link
Author

rca commented Jan 25, 2019

One thing this is missing is the ability to specify a specific container in a multi-container pod.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment