]> 91.132.146.200 Git - klimbim.git/commitdiff
some small kubectl helper script to get a shell in a pod by searching for it by given...
authorBanana <banana@starscream.de>
Fri, 15 Nov 2019 14:21:54 +0000 (15:21 +0100)
committerBanana <banana@starscream.de>
Fri, 15 Nov 2019 14:21:54 +0000 (15:21 +0100)
README
kubernetes/README [new file with mode: 0644]
kubernetes/kubeconnect [new file with mode: 0755]

diff --git a/README b/README
index b02e938a3e100c2dba36dcc57cc99ebd4e35024d..821a174349c7b21d536396635c57859b86fc07aa 100644 (file)
--- 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 (file)
index 0000000..4b52eec
--- /dev/null
@@ -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 (executable)
index 0000000..d205804
--- /dev/null
@@ -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
+