Search code examples
kubernetesgoogle-kubernetes-engineminikube

How to switch kubectl clusters between gcloud and minikube


I have Kubernetes operating 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 separately: 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 change 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?


Solution

  • 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.