Application Developer’s Guide to Setting Up Kubernetes with Minikube on Windows Home

How to set up a local Kubernetes cluster on Windows Home to test applications easily

Containerized applications offer many advantages over traditional deployments, from ease of management to scalability and isolation. Hence, combining containerized applications with a proper orchestration engine is the best way to manage modern applications in both staging and production environments.

As Windows Developers, we need a proper Kubernetes environment to test our applications. Windows Home handles most computing needs; Windows Pro offers more networking options and is more suited to small and medium sized businesses who need to manage multiple machines. If you’re a Windows Home user, you are still able to create the environment needed to set up and use Kubernetes clusters. This article focuses on setting up a local Kubernetes cluster that enables us to test our applications easily. To do this, we will cover

  1. Local Kubernetes options
  2. How to install minikube
  3. How to create a Kubernetes cluster using minikube
  4. How to create a multi-node Kubernetes cluster
  5. How to mount folders to Kubernetes clusters

Local Kubernetes Options

There are multiple options to create a local Kubernetes cluster on a Windows environment, such as:

  • Minikube- This is the most widely used feature-packed tool to implement local Kubernetes clusters on Windows, Linux, or Mac environments.
  • Docker Desktop- Docker Desktop for Windows is the simplest solution that comes bundled with the ability to spin up a local Kubernetes cluster.
  • kind- This is a tool to create Kubernetes clusters using docker containers as nodes. The primary focus of this tool is to test Kubernetes, while it can also be used for other purposes such as application deployments, testing, etc.

However, I prefer minikube over others as it is a standalone solution with a lot of features useful for managing a local Kubernetes cluster.

How to Install Minikube

Minikube depends on a container or a virtual machine manager to deploy a Kubernetes cluster. Some of the virtual machine managers it supports are Docker, Hyper kit, Hyper-V, KVM, Parallels, Podman, VirtualBox, and VMWare. Most Windows 10 Pro will use Hyper-V since it is built in but since we are using Windows 10 Home, we will need to install a third-party hypervisor. This walkthrough will use VirtualBox, but first let’s install minikube itself.

For installation, Minikube offers multiple options such as a simple executable, using the Windows Package Manager, or the Chocolatey Package Manager.

You can use any of the options mentioned above to install minikube. I will be using the Windows Package Manager in this tutorial. Run the winget install minikube command from powershell to install minikube.

Even with minikube, we need the kubernetes-cli (kubectl) installed locally to connect and communicate with the Kubernetes cluster. Kubernetes offers two methods to install kubectl.

  1. Download the kubectl binary and add it manually to the windows path
  2. Use a package manager like Chocolatey or Scoop to install the kubectl and get it added to the path automatically. (Currently, Winget does not support installing kubectl)

Chocolaty kubernetes-cli installation command

text
1choco install kubernetes-cli

Once the installation is completed, we can verify if it is successfully installed by checking the kubectl client version. For that, run the following command;

text
1kubectl version --client

RESULT

If you don’t have it installed already, you should download and install VirtualBox. Click the link on the download page for Windows hosts under platform packages and follow the installation instructions of the setup wizard.

Create a Kubernetes Cluster using Minikube

After the installation, we can simply use the start command to spin up a single-node Kubernetes cluster. This will create a Kubernetes cluster with the default values. Minikube automatically detects and selects a driver that is installed on your system. You can configure your preferred driver using the --driver flag or set the default driver using minikube config set driver <driver>. You can check the driver configuration options for your preferred driver. In this doc we will use VirtualBox.

Starting Minikube with Custom Options

We need to specify some custom options to match the Kubernetes cluster with the local Windows environment. The most commonly specified options are resource usage and network connectivity.

text
1minikube start --driver=virtualbox --cpus=2 --memory=2000m --disk-size="20000mb"

In the above startup string, we are explicitly providing the following options when creating the Kubernetes cluster.

  • --driver=virtualbox - Enforce VirtualBox as the driver
  • --cpus=2 - Limit the CPU count
  • --memory=2000m - Limit the memory to 2GB
  • --disk-size=”20000mb” - Define a disk size of 30GB

This will create a single-node Kubernetes cluster with the user-configured options. You can customize the Kubernetes cluster further using the startup options offered by minikube.

If we look at the Virtual Box manager, we can see that a single minikube instance has been created.

Verify the Kubernetes Cluster configuration

We can simply run the kubectl to get the system pods of the Kubernetes cluster and thereby identify a successful configuration.

text
1kubectl get pods -n kube-system

RESULT

Create a Multi-Node Kubernetes Cluster

We can use the --nodes option to create a multi-node cluster if we need to simulate a multi-node Kubernetes installation. There, the only consideration is the availability of resources in the local machine.

text
1minikube start --cpus=2 --memory=2000m --disk-size=20000mb --nodes=3

The above command will create a Kubernetes cluster with three nodes.

We can see that three separate minikube nodes are created in the VirtualBox manager.

With kubectl we can see the three nodes are present in the cluster:
kubectl get nodes

Mounting Folders to Kubernetes Cluster

Since we are using a hypervisor (Hyper-V), the Kubernetes nodes do not have access to the host machine. minikube provides users with the mount option to map a host directory to the Kubernetes cluster.

In the following example we are mounting the C:/data directory to the Kubernetes cluster as /data/user_data/

text
1minikube mount C:/data:/data/user_data

The above command will prompt users with a message from the Windows Firewall to allow access to minikube through the firewall. Here, you have to Allow the access, or otherwise, the mount will fail. (Grant permissions according to the network configuration)

In the end, minikube will notify a successful mount. However, this mount is not permanent, and the user needs to keep the PowerShell window open (process running) to maintain the mount.

Verifying Firewall Rules

We can identify the firewall rules created by running the following command through Powershell.

text
1Get-NetFirewallRule | Where-Object { $_.Name -match "minikube" }

RESULT

Verifying the Mounted Directory

To verify the mount, run minikube ssh command on a PowerShell window. It will establish an ssh connection to minikube. Next, view the directory listing with the ls command.

text
1minikube ssh
2ls -al /data/user_data/

A successful mount will show the files in the host machine within the minikube directory.

Conclusion

Tools like minikube can be used to simplify local Kubernetes configurations. Additionally, developers using Windows Home can utilize minikube with Windows-based tools and technologies like Winget, Chocolatey, and Virtual Box to natively support Kubernetes and have optimal performance. It also eliminates configuration issues that may arise with third-party tools.

We can easily tailor the Kubernetes deployment to meet our exact needs using some custom configurations. This ease of use enables us to create, test and deploy containerized applications in Kubernetes easily.

More Learning

The best way to learn anything is to dive in and try it yourself. The Summer of Kubernetes offers hands-on learning activities to learn Kubernetes, whether you’re a complete novice or an experienced professional looking to brush up on your skills. The program is divided into three modules, teaching you to code, ship, and run your Kubernetes services. Not only is the challenge free, there are also plenty of opportunities to win fun prizes and learn as part of a community of developers like you! Getting started is easy:

If you'd prefer to learn independently and on your own time, you can also check out our local development environments learning journey. This learning journey walks you through the primary concepts and hands-on activities required to create an effective local development environment with Kubernetes, which includes everything from the containerization of code to real-time local testing of distributed services.