Run multiple multiple clusters with minikube

minikube multiple clusters profile

3 min read | by Jordi Prats

Whenever we need to test something on a Kubernetes clusters one of the easier (and cheaper) option is test it out using minikube. However, how do we test a feature that require multiple clusters?

To be able to have several minikube clusters we just need to start them using a profile:

$ minikube start --profile cluster1
😄  [cluster1] minikube v1.24.0 on Ubuntu 20.04
  Automatically selected the docker driver. Other choices: kvm2, none, ssh
👍  Starting control plane node cluster1 in cluster cluster1
🚜  Pulling base image ...
🔥  Creating docker container (CPUs=2, Memory=7900MB) ...
🐳  Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
     Generating certificates and keys ...
     Booting up control plane ...
     Configuring RBAC rules ...
🔎  Verifying Kubernetes components...
     Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Enabled addons: storage-provisioner, default-storageclass
🏄  Done! kubectl is now configured to use "cluster1" cluster and "default" namespace by default
$ minikube start --profile cluster2
😄  [cluster2] minikube v1.24.0 on Ubuntu 20.04
  Automatically selected the docker driver. Other choices: kvm2, none, ssh
👍  Starting control plane node cluster2 in cluster cluster2
🚜  Pulling base image ...
🔥  Creating docker container (CPUs=2, Memory=7900MB) ...
🐳  Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
     Generating certificates and keys ...
     Booting up control plane ...
     Configuring RBAC rules ...
🔎  Verifying Kubernetes components...
     Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Enabled addons: default-storageclass, storage-provisioner
🏄  Done! kubectl is now configured to use "cluster2" cluster and "default" namespace by default

Using kubectl config get-contexts we can see how it have registered both clusters:

$ kubectl config get-contexts
CURRENT   NAME       CLUSTER    AUTHINFO   NAMESPACE
          cluster1   cluster1   cluster1   default
*         cluster2   cluster2   cluster2   default

We can switch context using kubectl config use-context

$ kubectl config use-context cluster1
Switched to context "cluster1".

Finally, we can destroy the minikube clusters by specifying it's profile name:

$ minikube delete --profile cluster2
🔥  Deleting "cluster2" in docker ...
🔥  Deleting container "cluster2" ...
🔥  Removing /home/jprats/.minikube/machines/cluster2 ...
💀  Removed all traces of the "cluster2" cluster.
$ minikube delete --profile cluster1
🔥  Deleting "cluster1" in docker ...
🔥  Deleting container "cluster1" ...
🔥  Removing /home/jprats/.minikube/machines/cluster1 ...
💀  Removed all traces of the "cluster1" cluster.

Posted on 21/03/2022

Categories