Last active
January 31, 2021 14:10
-
-
Save kenichi-shibata/83dc82a3f608392ba76d63f7b71e534e to your computer and use it in GitHub Desktop.
gke command line tool for setting up kubeconfig automatically on your google account
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 characters
#https://unix.stackexchange.com/questions/276471/piping-a-command-through-a-color-filter | |
# more info using man terminfo | |
function black() { tput setaf 0; cat; tput sgr0; } | |
function red() { tput setaf 1; cat; tput sgr0; } | |
function green() { tput setaf 2; cat; tput sgr0; } | |
function yellow() { tput setaf 3; cat; tput sgr0; } | |
function blue() { tput setaf 4; cat; tput sgr0; } | |
function magenta() { tput setaf 5; cat; tput sgr0; } | |
function cyan() { tput setaf 6; cat; tput sgr0; } | |
function white() { tput setaf 7; cat; tput sgr0; } | |
function errcolor() { tput setaf 0; tput smul; tput setab 1; cat; tput rmul; tput sgr0; } | |
function errcolorbold() { tput bold; tput setaf 0; tput setab 1; cat; tput sgr0; } | |
function superwhite() { tput setaf 7; tput smso; cat; tput sgr0; tput rmso; } | |
function warncolor() { tput setaf 4; tput setab 3; cat; tput sgr0; } | |
# advanced tput http://linuxcommand.org/lc3_adv_tput.php | |
function gke() { | |
# get me another kubeconfig file for gke | |
# get the default project | |
echo -e "Make sure you ran gcloud init beforehand" | cyan | |
echo "========================================" | cyan | |
unset KUBECONFIG | |
echo -e "$(gcloud config list)" | white | |
PROJECT=$(gcloud config get-value project) | |
KUBECONFIG=$HOME/.kube/config-$PROJECT | |
touch $KUBECONFIG | |
echo "========================================" | white | |
echo "Available clusters" | cyan | |
echo -e $(gcloud container clusters list --format yaml --flatten name) | cyan | |
echo "========================================" | white | |
echo "The Kubeconfig is now generated at $KUBECONFIG" | green | |
echo "gcloud container clusters get-credentials <cluster-name> --zone=<zone-name> --project <project-name>" | superwhite | |
export KUBECONFIG=$KUBECONFIG | |
echo | |
} | |
# Save this file and source it our save it on your bashrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment