Skip to content

Instantly share code, notes, and snippets.

@nexus166
Created October 12, 2019 22:27
Show Gist options
  • Select an option

  • Save nexus166/3ed9afa0254c3cceacc06944a27e5558 to your computer and use it in GitHub Desktop.

Select an option

Save nexus166/3ed9afa0254c3cceacc06944a27e5558 to your computer and use it in GitHub Desktop.
clean one-time container run in kube
#!/usr/bin/env bash
function k8run() {
set -xu;
IMAGE="${1}";
PODNAME=$(basename "${IMAGE}" | tr ':' '-');
_ARGS=("${@:2}");
KUBE_ARGS=$(printf '"%s", ' "${_ARGS[@]}");
PRIVILEGED="${PRIVILEGED:-false}";
kubectl run "${PODNAME}-${USER}" --restart=Never -it --rm --attach --image overriden --overrides '
{
"spec": {
"containers": [
{
"name": "'"${PODNAME}"'",
"image": "'"${IMAGE}"'",
"command": [ '"${KUBE_ARGS%??}"' ],
"stdin": true,
"tty": true,
"securityContext": {
"privileged": '"${PRIVILEGED}"'
}
}
],
"tolerations": [
{
"effect": "NoSchedule",
"key": "node-role.kubernetes.io/master"
}
]
}
}';
set +xu
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment