How to switch kubectl clusters between gcloud and minikube
If you're looking for a GUI-based solution for Mac and have the Docker Desktop installed, you can use the Docker Menu Bar icon. Here you can find "Kubernetes" menu with all the contexts you have in your kubeconfig and easily switch between them.
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.
List contexts
kubectl config get-contexts
Switch contexts
kubectl config set current-context MY-CONTEXT
A faster shortcut to the standard kubectl commands is to use kubectx:
- List contexts:
kubectx
- Equivalent to
kubectl config get-contexts
- Equivalent to
- Switch context (to foo):
kubectx foo
- Equivalent to
kubectl config use-context foo
- Equivalent to
To install on macOS: brew install kubectx
The kubectx package also includes a similar tool for switching namespaces called kubens
.
These two are super convenient if you work in multiple contexts and namespaces regularly.
More info: https://ahmet.im/blog/kubectx/