Last week, I spent a fantastic couple of days remotely visiting KubeCon2020 and CloudNativeCon2020. Tons of great keynotes, in depth demos, and more information than was humanly possible to absorb. I, as an interested explorer to all this Cloud Native “Stuff”, wanted to rush home and try it for myself. In that aim, there are a few projects aimed at small, sandbox style installations, for the individual that wishes to get their hands dirty and start learning without spending buckeroos on cloud resources or making a fleet of Atomic Pis (side note: I absolutely will be doing this in the near future).

Be Kind

The main solution that I found to be the most painless to setup was from a small and somewhat newer project called Kind. There are others like MiniKub or Microk8s . All of them provide about the same thing, but watching the Con chatter it seemed a lot more folks were excited to share Kind(ness) as the main getting started tool.

The big difference is that Kind does not use a Virtual machine, but instead uses docker containers, so it feels much more integrated with the cloud native super project Kubernetes, which is afterall, a container orchestrator.

https://kind.sigs.k8s.io/

Getting Started

These instructions are going to be based around Windows specifically, because that is what I use for my daily computer. Because it’s windows, there are a few extra hoops to jump through, but have no worries, because we will step through those together.

1. Prerequisites

The biggest pre-req to make this all work seamlessly, is to have a version of windows (OS build 20211 or higher) that support WSL version 2. If you do not have a version of windows that is compatible with WSLv2, then the other projects like MiniKub or MicroK8S may work better for your use case.

Verify your system is up to date with V2 by following the Microsoft WSLv2 docs

WSL v2 is the Windows Subsystem for Linux, but what is special about V2, is that docker for windows can utilize WSL for managing near-natural (cgroups, shared kernel) docker containers within WSL instead of creating a headless Virtual Machine, which tends to be slow and overall a less than pleasing experience. Another improvement with WSLv2, is the integration with VSCode is much nicer. Through VSCode one can open a session in WSLv2 with whatever flavor of Linux you choose ( I went with Ubuntu 20.04) and have full Linux support/tooling, which often speeds things up as many documents and Cloud Native technologies are geared more towards the Linux/MacOS crowds.

Enable WSL2

With Admin Powershell

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform, Microsoft-Windows-Subsystem-Linux

Reboot

wsl --set-default-version 2

Install a Linux distro from the Windows Store, I’ve gone with Ubuntu 20.04

Docker Desktop

After WSLv2, Docker for Windows needs to be installed and configured. Follow Docker’s instructions here: Docker Desktop

Once Docker Desktop is installed there is one setting to verify to make sure it is using the WSLv2 backend instead of a Virtual Machine.

  1. Find the whale in your system tool bar (usually on the bottom right)
  2. Right click on Whale, select Settings
  3. Within General, make sure Use the WSL2 Based Engine is selected
  4. Apply and Restart

Go

Now we are read to install the final Prerequisite, GO. Since we are using WSL for everything it must be a Linux compatible version of Golang and must be greater than version 1.11. Which of course does not come in the default (apt install golang) installation path. To install a recent version of go follow these instructions

# All of these steps are to be ran on Ubuntu 20.04 within WSLv2
wget https://golang.org/dl/go1.15.5.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.15.5.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
# to save the path for every start up do the following
sudo touch /etc/profile.d/go.sh
sudo chmod +x /etc/profile.d/go.sh
echo "export PATH=$PATH:/usr/local/go/bin" | sudo tee -a /etc/profile.d/go.sh

Then every time you login the path will be added to the default and magic can begin

Setup Kind

Lucky for us, although the prerequisites are a bit of jumble to get up and running, the install of Kind is a single one line

GO111MODULE="on" sudo go get sigs.k8s.io/kind@v0.9.0

install kubectl

The main and official tool to manage a kubernetes cluster is known as kubectl. Now is the time to install that, and double bonus the wonderful folks at Google, have distilled all of the complexities down to a single one liner.

curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"

From here you can start a kubernetes cluster on your machine

sudo kind create cluster
sudo kubectl create deployment nginx --image=nginx --port=80

…and you’re done…well sort of

Windows Funkiness

Since we’re a few layers deep in abstractions and subsystems and dockers, there’s a special way to deploy kind so that it can forward traffic from windows to a deployment which enables you to bring up the frontend deployment in a web browser or suing a cli tool like curl.

Start over

Assuming you started the nginx deployment from the above instructions:

sudo kubectl delete deployment nginx
sudo kind delete cluster

create a file in wsl2, cluster-config.yml

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 30000
    hostPort: 30000
    protocol: TCP

The above YAML once applied will give our windows machine access to a service running within Kubernetes on port 30000.

sudo kind create cluster --config=cluster-config.yml
sudo kubectl create deployment nginx --image=nginx --port=80
sudo kubectl create service nodeport nginx --tcp=80:80 --node-port=30000
curl http://localhost:30000

The above and more information on all of the WSL2 considerations for using Kind can be found on the official docs here: https://kind.sigs.k8s.io/docs/user/using-wsl2/

Summary

If you have Windows 10 OS build 20211 or higher, than this guide can take you from 0 kubernetes to up and running in about a half an hour, with most of that waiting for a few things to download.

Getting started with Kubernetes on Windows is getting easier and more accessible all the time, and thanks to tools like WSLv2 and Kind, now is a great opportunity to get started without a high barrier to entry.