Created
October 29, 2018 14:03
-
-
Save tanelmae/b638ba113bd394702038954dd2010da6 to your computer and use it in GitHub Desktop.
Get GKE context by name
This file contains 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
# Assumes unique cluster names | |
function get-context() { | |
local CLUSTER_NAME=${1} | |
[ -z ${CLUSTER_NAME} ] && echo "Give cluster name" && return 1 | |
local CURRENT_PROJECT=$(gcloud config get-value project) | |
local CLUSTER_ZONE=$(gcloud container clusters list --filter=name:${CLUSTER_NAME} --format='value(zone)') | |
[ -z ${CLUSTER_ZONE} ] && return 1 | |
gcloud container clusters get-credentials ${CLUSTER_NAME} --zone=${CLUSTER_ZONE} | |
kubectl config rename-context "gke_${CURRENT_PROJECT}_${CLUSTER_ZONE}_${CLUSTER_NAME}" ${CLUSTER_NAME} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment