howtos

gcloud setup

First run gcloud init and add all of your clusters. Then you can use the following Bash script to change between your clusters:

#!/bin/bash

kubectl config unset current-context

gcloud config set account ""
gcloud config configurations activate 

gcloud config set core/account ""
gcloud config set core/project 
gcloud config set compute/region 
gcloud config set compute/zone 

kubectl config use-context 

exit 0

Some useful commands which can show you necessary data for above script:

gcloud auth list
gcloud projects list
gcloud config list
gcloud config configurations list

kubectl config get-contexts
kubectl config rename-context old-ctx-name new-ctx-name

Initial config create, for working with a k8s cluster:

gcloud config configurations create NEW_CONFIG_NAME
gcloud auth login
gcloud config set core/project PROJECT_NAME && \
  gcloud config set compute/region europe-west3 && \
  gcloud config set compute/zone europe-west3-a && \
  gcloud container clusters get-credentials CLUSTER_NAME && \
  kubectl config rename-context OLD_CTX_NAME NEW_CTX_NAME && \
  kubectl config get-contexts

about these howtos

This howto is part of a larger collection of howtos maintained by the author (mostly for his own reference). The source code for the current howto in plain Markdown is available on GitHub. If you have a GitHub account, you can jump straight in, and suggest edits or improvements via the link at the bottom of the page (Improve this page).

made with ❤ by Valera Rozuvan