Install kubernetes on windows + WSL

Dario De Bastiani
Jan 12, 2018 · 3 min read

While Windows Subsystem for Linux (WSL) does a decent job providing a unix system, it cannot run natively anything that requires access to virtualisation — for now.

If you already have docker installed, there’s a workaround: install minikube on windows, and then connect to that from within WSL.

To do that, start by opening powershell as an administrator:

Image for post
Image for post
Windows key, search “powershell”, right click, “Run as Administrator”

In the powershell window, paste the following commands to install minikube and kubectl:

cd $env:userprofile\AppData\Local\Microsoft\WindowsApps
# replace 1.9.0 with the most recent version
wget https://storage.googleapis.com/kubernetes-release/release/v1
.9.0/bin/windows/amd64/kubectl.exe -OutFile kubectl.exe
# replace 0.24.1 with the most recent version
wget https://storage.googleapis.com/minikube/releases/v0.24.1/minikube-windows-amd64.exe -OutFile minikube.exe

Now we need to create a virtual machine using hyper-v.
There’s currently a bug that keeps minikube hanging on start — as a workaround, create a new external virtual switch.
Name it “Primary Virtual Switch” (“The neighbours stole my dog” works just as well tbh) and use it to start the kubernetes cluster:

minikube.exe start --vm-driver=hyperv --hyperv-virtual-switch="Primary Virtual Switch"

That’s everything we need to do in powershell, now open the WSL bash:

# install kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && \
chmod +x kubectl && \
sudo mv kubectl /usr/local/bin/

That’s almost everything needed to see your service running — at this stage, it will only be accessible to kubernetes’ internal network.
Let’s make sure the deployment is working first:

$ kubectl get deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
hello-minikube 1 1 1 1 21s
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-minikube-7844bdb9c6-wkqtb 1/1 Running 0 34s

Now we can expose the service to the outside world:

$ kubectl expose deployment hello-minikube --type=NodePort
service "hello-minikube" exposed
$ kubectl get service hello-minikube
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-minikube NodePort 10.110.6.111 <none> 8080:30668/TCP 19s
# ☝ ️30668 externally reachable port

We need to go back to powershell to see the service in action:

## should open a browser tab showing the service just deployed
minikube.exe service hello-minikube

That’s it! Now might be a good time to enable autocompletion for kubectl.
Go deploy all the things!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store