How to switch kubectl clusters between gcloud and minikube

Eric Broda picture Eric Broda · Apr 26, 2017 · Viewed 54.4k times · Source

I have Kubernetes working well in two different environments, namely in my local environment (MacBook running minikube) and as well as on Google's Container Engine (GCE, Kubernetes on Google Cloud). I use the MacBook/local environment to develop and test my YAML files and then, upon completion, try them on GCE.

Currently I need to work with each environment individually: I need to edit the YAML files in my local environment and, when ready, (git) clone them to a GCE environment and then use/deploy them. This is a somewhat cumbersome process.

Ideally, I would like to use kubectl from my Macbook to easily switch between the local minikube or GCE Kubernetes environments and to easily determine where the YAML files are used. Is there a simple way to switch contexts to do this?

Answer

Mark picture Mark · Apr 27, 2017

You can switch from local (minikube) to gcloud and back with:

kubectl config use-context CONTEXT_NAME

to list all contexts:

kubectl config get-contexts

You can create different enviroments for local and gcloud and put it in separate yaml files.