Docker Kubernetes on WSL 2
Tags: wsl, docker, kubernetes, containers
Published: 2020-05-28 00:12:22

Windows Subsystem for Linux (WSL) is a component which was introduced in Windows 10 that provides a Linux environment for development on Windows. The Linux environment works by proxying Linux kernel commands to the Windows kernel.

WSL2 is the second iteration over WSL which creates a virtualized Linux environment and new features such as filesystem access using the native Windows explorer application, Docker and more. WSL2 also provides notable performance improvements over the first version.

This guide will go over what is required to set up a functioning Kubernetes development environment using Windows 10, WSL2, Visual Studio Code, and Docker.

# Installing WSL

> ℹ *[ Edit ]:* I've heard news that the may 2020 release of Windows 10 was just released. WSL 2 should be considered GA now.
> ~~⚠ At the time of writing, WSL2 is currently a release preview with anticipated General Availability release planned for Summer 2020. WSL2 can be downloaded by first moving into the _"Release Preview"_ ring of the [Windows Insider Program](https://insider.windows.com/en-us/). WSL2 requires Windows build 2004 or later.~~

After the upgrade to Windows build 2004, WSL can be installed using the following instructions https://docs.microsoft.com/en-us/windows/wsl/install-win10

Due to past experiences, I've installed Debian for its performance and ease-of-use.

# Installing Docker

With WSL2 installed, Docker will need to be installed. Docker is a tool used to create, run, and orchestrate containers. Containers are self-contained environments that applications can run on. Docker can be downloaded from [the download page](https://docs.docker.com/docker-for-windows/install/)

Once Docker is download it, install it by running the downloaded executable file. During the docker installation process, a prompt will display asking whether to enable the WSL 2 backend or not. Select yes when this prompt is displayed.

The WSL backend for Docker can also be turned on post-install by accessing the settings menu

![Docker Settings](https://lh3.googleusercontent.com/CVC9ViMzbJRujQrWS4kz0Zav6twzkx7kq7M7r8JqhNRy1OqCRkl_aLd2HYqpWmc0kuHsPxnIBMiK8I8-lcYmuosskGyZ83wJ48DeHCTJa5Zi3i1Ohgm-rYi3WIxgGyik6wFucslq6bU=h300)

From the settings menu, select the **General** tab and check the box next to *Use the WSL 2 based engine*

![WSL2 Engine](https://lh3.googleusercontent.com/q92me9xwgqs10mru9-XDKnhbT-l9kdF9PHdptw3jJjtodWRGWzRO4mn9iLzCI_91FD9667RJYr8ExIeflrX-SYXWamj3-sFifezOQGCEZYDZPT71YyYugeueFk3BmBAWgYgBsibRHkk=w1024)

# Enabling Kubernetes

Once Docker has been installed and the WSL 2 Backend has been enabled, Kubernetes on Docker can be enabled by switching to the **Kubernetes** tab on the Docker settings window and checking the *Enable Kubernetes* checkbox.

![Enable Kubernetes Setting](https://lh3.googleusercontent.com/78RWhu8TtmDuTvCx3Yj7fPH8VrfauLw1Xh8aN0KmneRDBjk6NKm37qH6Dz5SOASMpxGhXHbfRPLuw-dwlxa4i8V9jDNsd8OalR0_MvZ7m7CRpxiofzrKzyeeEC9C8TPg-PvmQbJ6HyI=h1024)

## Advantages of Kubernetes in Docker

Using Kubernetes in Docker means skipping on complicated installation instructions such as setting up CLI tools like `kubeadm` or `k3s`.

Using Kubernetes in Docker also means not having to set up a [CNI layer](https://kubernetes.io/docs/concepts/extend-kubernetes/compute-storage-net/network-plugins/) such as `calico`, or `flannel`.

Docker provides a load balancer which allows traffic to be ingressed through localhost.

Docker for Windows will also set up the CLI tools which are used with both Kubernetes and Docker such as the Docker CLI and `kubectl` once the container engine is running.

## Advantages of Kubernetes in WSL 2

I migrated from using Kubernetes in Minikube. I found Minikube -- even with the HyperV backend to be cumbersome and resource intensive.

WSL by comparison allowed me to deploy more containers so that I can test multiple applications at a time.