Kubernetes (minikube) on Windows

AirwaveTech
7 min readSep 3, 2019

--

Windows 10 Professional, to be exact.

Hello, World! This is Airwave Tech’s first Medium post, and what better way to kick it off than with a write up about how to setup Kubernetes on Windows!

If you want to get straight to the steps, skip down to Objectives.

Our Backstory

Airwave Tech is an agency that was born out of the need to build better software while building better culture. I have been a part of big company initiatives that have spanned multiple years and I have raised over $4M USD in venture capital trying to help live streamers make a livable wage from creating content. Now, Airwave Tech is here to you help you build the hardest parts of your Stack.

So why Windows?

I needed to buy a personal computer and had the option of purchasing a custom-built Windows PC used for live streaming and video games, or a 2016 15" Macbook Pro. I opted to purchase the Windows 10 PC; which should tell you something about my frustrations with the latest Apple laptops. It’s been over a decade since I’ve done any professional work on Windows, and since Airwave Tech is based out of Seattle, Washington I thought getting started on this new journey with a PC would be fitting, i.e., Microsoft is in Redmond; a city relatively close to Seattle.

Objectives

  1. Requirements — Making sure you have everything ready before you begin.
  2. Setup minikube on Windows 10 — Have Kubernetes running locally
  3. Deploy a webapp — Deploy something to mimic the real world
  4. Setup ingress with Nginx — Make your webapp resolvable using a reverse proxy

Step 1. Requirements — Making sure you have everything ready before you begin

a. Make sure you can run Hyper-V and then install it

You need a hypervisor to control the virtual instance that runs Kubernetes since it doesn’t run natively on Windows. You could use VirtualBox, which is free virtualization software, but I didn’t go that route because it’s just more 3rd party software I didn’t want to install. So Hyper-V it is!

Run the command prompt as an administrator and run

systeminfo

You are looking for this at the very bottom:

Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.

This will let you know if you can run Hyper-V or not.

Install it using the information here:

https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v

b. Install Docker Desktop for Windows

https://docs.docker.com/docker-for-windows/install/

c. Install windows package manager Chocolately

This is very much like homebrew for Mac, or APT for various Linux distros. If you are unfamiliar with either, think of it as a software repository that you can use to install applications that are better in the background, much like how Windows Services run, or in a shell.

Test functionality of Chocolately by running the help command.

choco -?

Step 2. Setup minikube on Windows 10

a. Now that Chocolately is installed, use it to install minikube.

choco install minikube
If it fails, run it again. This happened to me a few times, but I never looked into why.

b. Configure a virtual switch

Minikube needs a virtual switch. I’ve tried starting it up without one. It doesn’t like that so run PowerShell as an administrator and create an external switch named “minikube”. I’m using my Ethernet adapter here. If you aren’t sure, you can always use the Hyper-V manager.

New-VMSwitch -name minikube -NetAdapterName Ethernet -AllowManagementOS $true

OR

Hyper-V Manager > Action > Virtual Switch Manager..

c. Start minikube

You can run this in PowerShell or the command prompt as long as you are running them as administrator

minikube start --vm-driver hyperv --hyperv-virtual-switch "minikube"

Test your installation with kubectl

kubectl get pods

You shouldn’t see any resources since you haven’t deployed anything. At this point, minikube is up and running. Congratulations!!! I was pretty surprised at how easy this was.

If you want to check the dashboard, open a new PowerShell or command prompt as an administrator and type in

minikube dashboard --url

Copy and paste the URL shown into your browser

If you want to customize your minikube, here is the list of options:

minikube start --help

Step 3. Deploy a webapp

Now that minikube is running on Windows, let’s deploy a webapp. Here is a webapp I have created for this demo. The links to everything mentions are just a few scrolls down.

kubectl apply -f https://raw.githubusercontent.com/airwavetechio/hello-world/master/_k8s/deployment.yml

Check your Kubernetes dashboard and watch the progress. When all is green, you are done with the deployment but you won’t be able to resolve the webapp just yet! We will cover that in Step 4.

The code for the webapp and Docker container are hosted here, respectively.

https://github.com/airwavetechio/hello-world

and

https://hub.docker.com/r/airwavetechio/hello-world

Step 3b (optional). Understand what’s happening.

If you took a look at the Github repository, you would see that the app.js is being served on port 5000.

This states if an environment variable named “PORT” is set, use that for the port, or else use port 5000.

You can test this out by opening a PowerShell or command prompt as an administrator and then running the same container locally:

docker run -p 5000:5000 --name airwave-helloworld airwavetechio/hello-world

Going from right to left, you are telling Docker to run the container airwavetechio/hello-world container, with the name of airwave-helloworld, with port 5000 on your host mapped to port 5000 within the container.

Open your browser to http://localhost:5000/ and you should see this

I’m touching on ports a bit later so you can understand it a bit easier.

When you are done, press CTRL+C and then

docker kill airwave-helloworld

Step 4. Setup ingress with Nginx

In this exercise, you will finally be able to hit your webapp hosted on minikube.

Enable ingress on your minikube cluster by entering this in your PowerShell or command prompt. As always, run it as an administrator.

minikube addons enable ingress

Count to 30 and then verify by running

kubectl get pods -n kube-system

You should see nginx-ingress-controller-xxxxxxx-xxxxx starting up. Once it says running, continue on.

In our k8s/deployment.yml file, we are setting the environment variable “PORT” to 4998 so I can explain a little bit about port allocation in Kubernetes.

In our code, the port is also getting printing it out to the log on startup for easy troubleshooting.

In the real world, a lot of developers will build a service using the same port. The ports in Kubernetes will allow you to run multiple apps that should be running on the same port, but then get translated by ingress through the use of clever Kubernetes networking.

If you run this command, you will now be able to hit your webapp.

kubectl expose deployment airwavetechio-hello-world-deployment --target-port=4998 --type=NodePort

You just setup a NodePort (which is a direct pass through from your host to the container) to the target-port, which we know is 4998 as shown above.

Get the URL and test it.

minikube service airwavetechio-hello-world-deployment --url

Your URL is proably going to be different.

This is what we did:

Browser:32451 > 32451:NodePort: 4999 > 4999: TargetPort:4998 > 4998:webapp

Step 5. Clean up

Delete the NodePort service

kubectl delete service airwavetechio-hello-world-deployment

Delete the deployment

kubectl delete -f https://raw.githubusercontent.com/airwavetechio/hello-world/master/_k8s/deployment.yml

Stop minikube

minikube stop

Thanks for getting through this and I hope you were able to follow along with successful results. If you have any questions or comments, feel free to drop us a line.

--

--

AirwaveTech
AirwaveTech

Written by AirwaveTech

Helping you build the hardest parts of your Stack

No responses yet