From: Banana Date: Fri, 15 Nov 2019 14:21:54 +0000 (+0100) Subject: some small kubectl helper script to get a shell in a pod by searching for it by given... X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=db07d307a35bc9b9dfd1fab666b93c81a9757404;p=klimbim.git some small kubectl helper script to get a shell in a pod by searching for it by given string --- diff --git a/README b/README index b02e938..821a174 100644 --- a/README +++ b/README @@ -5,7 +5,7 @@ # COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 # along with this program. If not, see http://www.sun.com/cddl/cddl.html -# 2018 http://www.bananas-playground.net +# 2011-2019 http://www.bananas-playground.net A bag full of things diff --git a/kubernetes/README b/kubernetes/README new file mode 100644 index 0000000..4b52eec --- /dev/null +++ b/kubernetes/README @@ -0,0 +1,10 @@ +# This program is free software: you can redistribute it and/or modify +# it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE + +# You should have received a copy of the +# COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 +# along with this program. If not, see http://www.sun.com/cddl/cddl.html + +# 2019 http://www.bananas-playground.net + +Stuff while using kubernetes and some of its cli. Nothing special. diff --git a/kubernetes/kubeconnect b/kubernetes/kubeconnect new file mode 100755 index 0000000..d205804 --- /dev/null +++ b/kubernetes/kubeconnect @@ -0,0 +1,44 @@ +#!/bin/bash + +# get a shell in a pod +# kubeconect podname context +# +# podname = the string to find +# context = the context to use for kubectl +# +# uses the default container and /bin/bash as a shell + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE +# +# You should have received a copy of the +# COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 +# along with this program. If not, see http://www.sun.com/cddl/cddl.html + +# 2019 http://www.bananas-playground.net + +if [ $# -lt 2 ]; then + echo "You need to provide pod name and context"; + echo "kubeconnect pod-name context"; + exit 126; +fi; + +PODNAME="$1" +CONTEXT="$2" + +if kubectl config use-context "$CONTEXT" &> /dev/null +then + echo "Using context: "`kubectl config current-context`; + AMOUNT=$(kubectl get pods | grep $PODNAME | awk '{print $1}' | wc -l); + if [[ $AMOUNT -eq 1 ]]; + then + REALPODNAME=$(kubectl get pods | grep $PODNAME | awk '{print $1}'); + echo "Pod found: "$REALPODNAME; + kubectl exec -it $REALPODNAME -- /bin/bash + else + echo "ERROR: No such pod found. '$PODNAME'"; + fi +else + echo "Could not set context: '$CONTEXT'" +fi +