How to run multiple Kubernetes clusters with Minikube
In this tutorial, we will install Minikube and run multiple Kubernetes clusters.
Prerequisites
You can do this tutorial on a Linux, Mac, or Windows workstation.
Outline
- Install Minikube
- Start the first Minikube Kubernetes cluster
- Start the second cluster
- Selecting clusters
- Stop a Kubernetes cluster
- Create more clusters
- Delete clusters
- Create a cluster with a specific Kubernetes version
- Wrapping up
Minikube is one of the easiest options to run a Kubernetes cluster on your laptop. But, often one Kubernetes cluster is not enough.
To test an application in different Kubernetes versions or to test different Kubernetes configurations we need access to multiple Kubernetes clusters. We can easily run multiple Kubernetes clusters on our development workstation with Minikube.
Install Minikube
Install Minikube by following the instructions for your platform.
Start the first Minikube Kubernetes cluster
Start the first Kubernetes cluster.
$ minikube start
This command will take several minutes to complete. Once it’s completed you will have a single-node Kubernetes cluster running on your workstation.
Minikube includes the Kubernetes client kubectl
. To use the kubectl
installed with Minikube, you must use the command minikube kubectl --
List the nodes in the cluster.
minikube kubectl -- get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 3h48m v1.28.3
Start the second cluster
In Minikube, a Kubernetes cluster is called a profile.
List profiles (Kubernetes )
minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| minikube | docker | docker | 192.168.76.2 | 8443 | v1.28.3 | Running | 1 | * |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
Create a new cluster. Use -p
option to create a new profile (cluster).
A profile
in Minikube is equivalent to a Kubernetes cluster.
minikube start -p k8s-10
List the clusters.
minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| k8s-10 | docker | docker | 192.168.49.2 | 8443 | v1.28.3 | Running | 1 | |
| minikube | docker | docker | 192.168.76.2 | 8443 | v1.28.3 | Running | 1 | * |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
Now, we have two Kubernetes clusters running.
Selecting clusters
The commands issued using minikube kubectl --
will be received by the Active
cluster indicated by a *
in the Active
column in the table above.
List the nodes in the cluster.
minikube kubectl -- get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 3h48m v1.28.3
This command lists the nodes in the minikube
cluster as it is the currently Active
cluster.
Select the other cluster.
minikube profile k8s-10
✅ minikube profile was successfully set to k8s-10
List the clusters.
minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| k8s-10 | docker | docker | 192.168.49.2 | 8443 | v1.28.3 | Running | 1 | * |
| minikube | docker | docker | 192.168.76.2 | 8443 | v1.28.3 | Running | 1 | |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
Now, the k8s-10
cluster is selected so the commands will be received by the k8s-10
cluster.
List the nodes in k8s-10
cluster.
minikube kubectl -- get nodes
NAME STATUS ROLES AGE VERSION
k8s-10 Ready control-plane 7m14s v1.28.3
Stop a Kubernetes cluster
To stop a cluster, we must select the cluster (profile) first.
Let’s stop the minikube
cluster.
minikube profile minikube
✅ minikube profile was successfully set to minikube
minikube stop
✋ Stopping node "minikube" ...
🛑 Powering off "minikube" via SSH ...
🛑 1 node stopped.
List the clusters.
minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| k8s-10 | docker | docker | 192.168.49.2 | 8443 | v1.28.3 | Running | 1 | |
| minikube | docker | docker | 192.168.76.2 | 8443 | v1.28.3 | Stopped | 1 | * |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
The cluster minikube
is stopped but k8s-10
is still running.
Create more clusters
Minikube is not limited to single-node clusters.
Create a new Kubernetes cluster with two nodes.
minikube start -n=2 -p k8s-20
List the clusters
minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| k8s-10 | docker | docker | 192.168.49.2 | 8443 | v1.28.3 | Running | 1 | |
| k8s-20 | docker | docker | 192.168.67.2 | 8443 | v1.28.3 | Running | 2 | |
| minikube | docker | docker | 192.168.76.2 | 8443 | v1.28.3 | Stopped | 1 | * |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
We have two running clusters - k8s-10
with one node and k8s-20
with two nodes.
Delete clusters
Let’s delete the cluster k8s-10
as we no longer need it.
To delete a cluster, we must first select the profile.
minikube profile k8s-10
Stop the cluster.
minikube stop
Delete the cluster.
minikube delete
List the clusters.
minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| k8s-20 | docker | docker | 192.168.67.2 | 8443 | v1.28.3 | Running | 2 | |
| minikube | docker | docker | 192.168.76.2 | 8443 | v1.28.3 | Stopped | 1 | * |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
The cluster k8s-10
is deleted.
Create a cluster with a specific Kubernetes version
By default, Minikube creates the cluster with the latest Kubernetes version. We can create a cluster with a specific version by using --kubernetes-version
option in minikube start
.
Create a cluster with Kubernetes 1.27.1
.
minikube start -p k8s-30 --kubernetes-version='1.27.1'
List the clusters.
minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| k8s-30 | docker | docker | 192.168.49.2 | 8443 | v1.27.1 | Running | 1 | |
| k8s20 | docker | docker | 192.168.67.2 | 8443 | v1.28.3 | Running | 2 | * |
| minikube | docker | docker | 192.168.76.2 | 8443 | v1.28.3 | Stopped | 1 | |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
Wrapping up
Minikube is easy to get started and is also lenient on computing resources. But, it’s a powerful tool for running Kubernetes on your laptop.
You can easily run 3 single-node clusters in a laptop with 6GB of memory and 4 CPU cores.
With more memory and CPU cores you can create sophisticated Kubernetes test labs right on your laptop.