Last active
December 24, 2018 16:04
-
-
Save walkerjam/0fa51286af3cb29b996c359fd2e0cada to your computer and use it in GitHub Desktop.
Revisions
-
walkerjam revised this gist
Dec 24, 2018 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -109,4 +109,7 @@ if [[ $LIST_OBJECTS != 'n' ]]; then echo "----- $(tput setaf 6)Secrets$(tput sgr0) -----" kubectl get secrets echo echo "----- $(tput setaf 6)Config Maps$(tput sgr0) -----" kubectl get configmap echo fi -
walkerjam revised this gist
Dec 10, 2018 . 1 changed file with 10 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ # CONTEXT="$(kubectl config current-context)" CUR_NAMESPACE=$(kubectl config get-contexts | grep "*" | awk '{ print $5 }') NEW_NAMESPACE= LIST_OBJECTS= @@ -35,7 +35,15 @@ done if [ -z "$NEW_NAMESPACE" ]; then echo "Select a new namespace:" echo NAMESPACES=( ) kubectl get namespace 2>/dev/null >/dev/null if [ $? -eq 0 ]; then # Our account can list cluster namespaces NAMESPACES=( $(kubectl get namespace -o name | awk -F "/" '{ print $2 }' | sort) ) else # Our account can NOT list cluster namespaces - they must be configured in the kubeconfig NAMESPACES=( $(kubectl config get-contexts -o name | sort) ) fi NS_OPTS=() NS_LABELS=() for NS in "${NAMESPACES[@]}"; do -
walkerjam revised this gist
Jul 31, 2018 . 1 changed file with 17 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ #!/bin/bash # CONTEXT="$(kubectl config current-context)" CUR_NAMESPACE=$(kubectl config view -o jsonpath="{.contexts[0].context.namespace}") NEW_NAMESPACE= @@ -86,5 +85,20 @@ if [[ -z $LIST_OBJECTS ]]; then read -r LIST_OBJECTS fi if [[ $LIST_OBJECTS != 'n' ]]; then echo echo "----- $(tput setaf 6)Deployments$(tput sgr0) -----" kubectl get deployments echo echo "----- $(tput setaf 6)Pods$(tput sgr0) -----" kubectl get pods echo echo "----- $(tput setaf 6)Services$(tput sgr0) -----" kubectl get services echo echo "----- $(tput setaf 6)Ingress$(tput sgr0) -----" kubectl get ingress echo echo "----- $(tput setaf 6)Secrets$(tput sgr0) -----" kubectl get secrets echo fi -
walkerjam revised this gist
Jul 31, 2018 . 1 changed file with 80 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,90 @@ #!/bin/bash # # Some heavy use of https://stackoverflow.com/questions/42789273/bash-choose-default-from-case-when-enter-is-pressed-in-a-select-prompt # CONTEXT="$(kubectl config current-context)" CUR_NAMESPACE=$(kubectl config view -o jsonpath="{.contexts[0].context.namespace}") NEW_NAMESPACE= LIST_OBJECTS= while :; do case $1 in -h|-\?|--help) cat << EOF Usage: ${0##*/} [-h] [-l|--list] [NAMESPACE] Change current Kubernetes namespace, and optionally list objects. -h display this help and exit -l list objects after changing namespace EOF exit ;; -l|--list) LIST_OBJECTS=1 ;; *) if [[ -n "$1" ]]; then NEW_NAMESPACE="$1" fi esac shift if [[ -z $1 ]]; then break; fi done if [ -z "$NEW_NAMESPACE" ]; then echo "Select a new namespace:" echo NAMESPACES=( $(kubectl get namespace -o name | awk -F "/" '{ print $2 }' | sort) ) NS_OPTS=() NS_LABELS=() for NS in "${NAMESPACES[@]}"; do NS_OPTS+=("$NS") if [[ $NS == $CUR_NAMESPACE ]]; then NS_LABELS+=("$(tput setaf 6)$NS$(tput sgr0) (current)") else NS_LABELS+=("$NS") fi done I=0 for LABEL in "${NS_LABELS[@]}"; do printf '%s\n' "$((++I))) $LABEL" done >&2 NUM_ITEMS=${#NS_LABELS[@]} PS3="$(tput setaf 6) > Namespace: $(tput sgr0)" while :; do printf %s "${PS3}" >&2 read -r INDEX # Make sure that the input is either empty or that a valid index was entered. [[ -z $INDEX ]] && break # empty input (( INDEX >= 1 && INDEX <= NUM_ITEMS )) 2>/dev/null || { continue; } break done if [[ -n $INDEX ]]; then NEW_NAMESPACE="${NS_OPTS[$INDEX - 1]}" else NEW_NAMESPACE=$CUR_NAMESPACE fi fi if [[ -n $NEW_NAMESPACE ]]; then if [[ $CUR_NAMESPACE != $NEW_NAMESPACE ]]; then kubectl config set-context $CONTEXT --namespace=$NEW_NAMESPACE > /dev/null echo "Set namespace to $(tput setaf 6)$NEW_NAMESPACE$(tput sgr0)" else echo "Current namespace $(tput setaf 6)$CUR_NAMESPACE$(tput sgr0) (not changed)" fi echo fi if [[ -z $LIST_OBJECTS ]]; then printf %s "List objects? [Y/n]" >&2 read -r LIST_OBJECTS fi if [[ $LIST_OBJECTS != 'n' ]]; then kubectl get all fi -
walkerjam revised this gist
Jul 17, 2018 . 1 changed file with 10 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,15 @@ #!/bin/bash CONTEXT=$(kubectl config current-context) NAMESPACE=$(kubectl config view -o jsonpath="{.contexts[0].context.namespace}") echo "Current namespace: $(tput setaf 6)$NAMESPACE $(tput sgr0)" NEW_NAMESPACE="$1" if [ -z "$NEW_NAMESPACE" ]; then echo echo "Select a new namespace:" NAMESPACES=( $(kubectl get namespace -o name | awk -F "/" '{ print $2 }' | sort) ) PS3="$(tput setaf 6) > Namespace: $(tput sgr0)" select CHOICE in "${NAMESPACES[@]}"; do for NS in "${NAMESPACES[@]}"; do if [[ $NS == $CHOICE ]]; then @@ -13,6 +18,7 @@ if [ -z "$NEW_NAMESPACE" ]; then fi done done echo fi kubectl config set-context $CONTEXT --namespace=$NEW_NAMESPACE > /dev/null echo "Set namespace to $(tput setaf 6)$NEW_NAMESPACE $(tput sgr0)" -
walkerjam created this gist
Jul 17, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ #!/bin/bash NEW_NAMESPACE="$1" CONTEXT=$(kubectl config current-context) if [ -z "$NEW_NAMESPACE" ]; then NAMESPACES=( $(kubectl get namespace -o name | awk -F "/" '{ print $2 }' | sort) ) PS3="$(tput bold)$(tput setaf 6)Select namespace: $(tput sgr0)" select CHOICE in "${NAMESPACES[@]}"; do for NS in "${NAMESPACES[@]}"; do if [[ $NS == $CHOICE ]]; then NEW_NAMESPACE=$CHOICE break 2 fi done done fi kubectl config set-context $CONTEXT --namespace=$NEW_NAMESPACE echo "Set namespace to $NEW_NAMESPACE"