From de794dddcc401e2f86c508da84376262dae1c476 Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Mon, 8 Jan 2018 10:38:03 +0100 Subject: [PATCH] Add toolbox script for kubernetes --- bin/ktoolbox | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 bin/ktoolbox diff --git a/bin/ktoolbox b/bin/ktoolbox new file mode 100755 index 0000000..4136447 --- /dev/null +++ b/bin/ktoolbox @@ -0,0 +1,20 @@ +#!/bin/bash +# set -ex +name=toolbox-${USER} +image='dlneintr/toolbox:latest' +labels="app=toolbox,owner=${USER},cookie=0xdeadbeef" + +existing=$(kubectl get pod -l ${labels} --output='jsonpath={.items..metadata.name}') + +if [ "${existing}" == "" ]; then + kubectl run --image=${image} --image-pull-policy=Always --labels=${labels} ${name} +fi + +for i in {1..10}; do + ready=$(kubectl get pod --field-selector=status.phase=Running -l ${labels} --output='jsonpath={.items..metadata.name}') + if [ "${ready}" != "" ]; then + exec kubectl exec -it ${ready} /bin/sh + fi + echo "Waiting for pod to be ready" + sleep 1 +done