Kubernetes

Install Minikube in WSL 2 with Kubectl and Helm

Install Minikube in WSL 2 with Kubectl and Helm. A step-by-step of how to get Kubernetes running in WSL2 with minikube, kubectl, and helm

I have covered Kubernetes home lab environments in a few past posts, including the links to follow. However, I realized an environment that I have left out that is certainly a great tool for learning is Minikube and WSL 2. Both of these can be used to spin up a Kubernetes test playground that is easily accessible. Let’s look at how to install Minikube in WSL2 with Kubectl and Helm and see the steps involved.

Why Minikube for Kubernetes?

The below explanation is taken directly from the official Kubernetes documentation:

Like kindminikube is a tool that lets you run Kubernetes locally. minikube runs a single-node Kubernetes cluster on your personal computer (including Windows, macOS, and Linux PCs) so that you can try out Kubernetes, or for daily development work.

All you need is Docker (or similarly compatible) container or a Virtual Machine environment, and Kubernetes is a single command away: minikube start

Install Minikube in WSL 2 with Kubectl and Helm

We will cover the following step-by-step to install Minikube in WSL 2 with Kubectl and Helm:

  1. Install Docker in WSL 2
  2. Install Minikube prerequisites
  3. Install Minikube
  4. Install kubectl and set context to Minikube
  5. Install Helm
  6. Start the Minikube Kubernetes cluster

1. Install Docker in WSL 2

The steps to install Docker in WSL 2 include:

  1. Install prerequisites
sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

2. Download and add the official Docker PGP key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

3. Add the stable channel repository

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

4. Update the package list

sudo apt-get update -y

5. Install the latest Docker CE

sudo apt-get install -y docker-ce

6. Add your user to access the Docker CLI without root user permissions

sudo usermod -aG docker $USER && newgrp docker
Install Docker in WSL 2
Install Docker in WSL 2

2. Install Minikube prerequisites

There are a couple of prerequisites that blogs around the web detail as needed for installation of Minikube in WSL. These include:

  1. systemctl
  2. conntrack
  1. Install systemctl

To install systemctl, there is a github script you need to pull down.

git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ubuntu-wsl2-systemd-script.sh
Installing systemctl for installing Minikube with WSL 2
Installing systemctl for installing Minikube with WSL 2

Restart the LxssManager in Windows to initialize systemctl with WSL 2.

Restart LxssManager in Windows
Restart LxssManager in Windows

2. Install Conntrack

sudo apt install -y conntrack
Install conntrack in WSL 2
Install conntrack in WSL 2

3. Install Minikube

After installing the prerequisites, installing Minikube is quite easy. You just pull down the latest Minikube using the following:

# Download the latest Minikube
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

# Make it executable
chmod +x ./minikube

# Move it to your user's executable PATH
sudo mv ./minikube /usr/local/bin/

#Set the driver version to Docker
minikube config set driver docker
Download and install the latest minikube
Download and install the latest minikube

4. Install Kubectl and set context to Minikube

Kubectl is the defacto standard tool for working with Kubernetes in general. It is great to get it installed and set the context for Kubectl to Minikube.

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
Installing kubectl for use with Minikube
Installing kubectl for use with Minikube

Below is the command to set the context to Minikube:

kubectl config use-context minikube
Set the Kubectl context to Minikube
Set the Kubectl context to Minikube

5. Install Helm to work with Minikube

The process to install helm involves the following steps:

curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh 
chmod 700 get_helm.sh 
./get_helm.sh
Installing helm and initializing the helm installation
Installing helm and initializing the helm installation

6. Start the Minikube Kubernetes Cluster

After running the command to start the minikube cluster, which is:

minikube start

You can see the single cluster node running using the kubectl command:

kubectl get nodes -o wide
Minikube Kubernetes cluster running in WSL 2
Minikube Kubernetes cluster running in WSL 2

Wrapping Up

Using WSL 2 and Minikube is a great way to start playing around with Kubernetes clusters without the need for standing up VMs and other lab environment prerequisites. WSL2 has its quirks, however, using the process listed above, you should be able to get a Minikube Kubernetes cluster up and running fairly quickly.

Kubectl and Helm are additional components that aren’t absolutely required to work with Minikube. However, they allow using the same tools you will use in production to interact with your Kubernetes clusters.

Subscribe to VirtualizationHowto via Email ๐Ÿ””

Enter your email address to subscribe to this blog and receive notifications of new posts by email.



Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com, and a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

Related Articles

10 Comments

  1. This just does not work. After applying command “bash ubuntu-wsl2-systemd-script” WSL stops to work. Crashing all the time after its start. Tested on Ubuntu 20.04

    1. Found solution.

      Bash ubuntu-wsl2-systemd-script.sh –force
      Need to use FORCE parameter, otherwise it will not be installed.

  2. Anyone running into the “nsenter: cannot open /proc/7424/ns/time: No such file or directory” issue after running the bash script?

  3. I used this procedure and I lost ssh connection. Anyone had the same issue?

    Regards

  4. I get this error

    kubectl config use-context minikube
    error: no context exists with the name: “minikube”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.