Install Minikube in WSL 2 with 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.
- Install Kubernetes in Windows using Tanzu Community Edition
- VMware vSphere with Tanzu Kubernetes Home Lab
- Kubernetes LXC Containers Configuration – Lab Setup
- Kubernetes Home Lab Setup Step-by-Step
Why Minikube for Kubernetes?
The below explanation is taken directly from the official Kubernetes documentation:
Like kind
, minikube
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:
- Install Docker in WSL 2
- Install Minikube prerequisites
- Install Minikube
- Install kubectl and set context to Minikube
- Install Helm
- Start the Minikube Kubernetes cluster
1. Install Docker in WSL 2
The steps to install Docker in WSL 2 include:
- 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
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:
- systemctl
- conntrack
- 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
Restart the LxssManager in Windows to initialize systemctl with WSL 2.
2. Install Conntrack
sudo apt install -y conntrack
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
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"
Below is the command to set the context to Minikube:
kubectl config use-context 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
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
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.
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
Found solution.
Bash ubuntu-wsl2-systemd-script.sh –force
Need to use FORCE parameter, otherwise it will not be installed.
Anyone running into the “nsenter: cannot open /proc/7424/ns/time: No such file or directory” issue after running the bash script?
Yes, and reading more closely I now see that the git repository, https://github.com/DamionGans/ubuntu-wsl2-systemd-script, says “[Does not work anymore!]”.
Here’s a fix: https://github.com/DamionGans/ubuntu-wsl2-systemd-script/issues/37#issuecomment-835727166.
Also, wsl2 now has systemd working so the script is not needed.
I used this procedure and I lost ssh connection. Anyone had the same issue?
Regards
Andres,
Were you able to establish connection?
Brandon
I get this error
kubectl config use-context minikube
error: no context exists with the name: “minikube”
Ayub,
What do you get when you run kubectl config get-contexts?
Brandon
it didnt work for me either. worked only after starting minikube
Ramesh,
Good to know!
Brandon