123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #!/bin/bash
- # Klimbim Software collection, A bag full of things
- # Copyright (C) 2011-2023 Johannes 'Banana' Keßler
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
- # 2019 http://www.bananas-playground.net
- # version 1.0
- # 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
- # needs kubectl to be installed
- if [ $# -lt 2 ]; then
- echo "You need to provide pod name and context";
- echo "kubeconnect pod-name context";
- exit 2;
- 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'";
- exit 1;
- fi
- else
- echo "Could not set context: '$CONTEXT'"
- exit 1;
- fi
- exit 0
|