Getting Started with Kubernetes on Windows 10 and WSL2

Nate Carpenter
6 min readMar 22, 2021

Setting up with Docker Desktop across Windows and WSL2

Screenshot of “Enabling Kubernetes” on Windows 10

In my work, I’ve sometimes had to create and test container-based applications on both Windows 10 and Linux, both on my local machine and on a remote development cluster. Instead of installing everything twice, it would be nice to access the Kubernetes environment from the Windows environment as well as from the Windows Subsystem for Linux (WSL2). As usual, I make things more difficult by using a limited user account on Windows, which I think is a best practice but causes no end of headaches when developing.

So what this article will talk about is:

  • Getting Docker Desktop working in a limited user account
  • Ensuring Kubernetes works from both Windows and WSL2 consoles
  • Adding some handy Kubernetes utilities

You will need to have WSL2 installed. Here’s an article about doing that, and there are plenty of others too.

Join the Group! Docker Desktop and Limited User Accounts

First, install Docker Desktop. But note, in case you’re in the middle of something:

  • You have to do this whole part as an administrator
  • You may need to go through some things in your computer’s BIOS to enable virtualization
  • You’ll have to log out at least once

But hey, you’re trying to get to the point where you’re running multiple pretend computers on your real computer, so there’s a lot of low-level stuff that has to go on.

So, to install Docker Desktop: Docker, as usual, has excellent instructions.

The part that is important for running under a Limited User Account is that you have to add your user to the docker-users group on Windows. Again, you will need administrator privileges to do this. From the linked instructions:

Run Computer Management as an administrator and navigate to Local Users and Groups > Groups > docker-users. Right-click to add the user to the group. Log out and log back in for the changes to take effect.

Don’t forget that last part — note that you just have to sign out and back in, not restart your computer! Don’t worry, I’ll wait.

Welcome Back!

So you’ll probably have noticed some different things happening at login, mainly that Docker Desktop is now running. Now, Docker actually has two different ways it can run on your machine: Docker Swarm and Kubernetes. Both are “orchestrators” — ways to manage a bunch of containers running together. The differences are well beyond the scope of this article (but not this one!), but based on the title I’m assuming you’re here for the K8S. That’s what l33t c0deRz call Kubernetes. Because there’s 8 letters between the K and the S. It’s also loads easier to type. Um. Continuing…

Let’s make sure your settings are good. Open Docker Desktop and go to “General”. Two things you want to ensure:

  • Make sure the “Use WSL 2 based engine” is checked
  • Docker Desktop uses up resources when running. Maybe a lot. If you use this computer for other things like playing Cyberpunk 2077 or Minesweeper 2078, and need that sweet sweet framerate, you will probably want to make sure the “Start Docker Desktop when you log in” isn’t checked

Next, go to the Kubernetes settings and, if the “Enable Kubernetes” box isn’t checked … check it! This will take a minute or ten, and will restart Docker Desktop. You can ignore the other checkboxes for now, but if you don’t care about ever using Docker Swarm (and you know what I mean by that phrase) then check the second one too.

Note that when I did this, it showed “Starting…” but never actually started. even after I rebooted. Then I spent 2 hours trying to make it work, and couldn’t. So I uninstalled it and reinstalled it and it worked. Sigh. My guess is that I’d been running it after installing it from my “dev” account which has admin privileges. Installing it from the limited account may have loosened some file permissions somewhere.

Running docker and kubectl

Now that Kubernetes is installed, you’ll need to be able to interact with it from both Windows and WSL2. Docker is controlled by a command called docker. Kubernetes is controlled by a command called kubectl. Which also controls Docker, kinda, sometimes. Anyway, when you install Docker Desktop, these will be installed. And, because you already installed WSL2, it’s smart enough to install them there too!

From PowerShell, CMD, or your WSL2 console you can now type:

> docker system info
or
> kubectl cluster-info

and you should see reasonable responses.

Docker: Here is a nice cheat sheet for Docker stuff. Now your computer is capable of running any of those “docker tutorials” that tell you how, for example, to install MongoDB. There will be lots of docker pull and docker run commands. And it’s great. But, you’re running a bunch of separate containers, not an orchestrated cluster. And you can get surprisingly far doing this — article over! But if you want to deploy a bunch of things together, like a system of microservices, UIs, and their databases, then this is where Kubernetes comes in.

Kubernetes: You’re really here because you want to use K8S to orchestrate containers. You’ll want to bookmark the kubectl cheatsheet and also take the time to get the autocomplete for bash/ZSH working as described there. For PowerShell this solution is available but you will need to know PowerShell better than I do to make it work properly. But, most importantly, you need to read up on Kubernetes in the first place. That is way, way beyond this article, but here are some great places to start:

Your K8S Utility Belt

I recommend installing kubetail which makes your logs so, so much easier to deal with. Normally, if you want to see a log for a pod, you have to:

> kubectl get pods
(Find your pod in the zoo of pods)
> kubectl logs <your-pod>
(boring logs for that pod spew out)

kubetail makes it much simpler:

> kubetail <partial container/pod name or even regex!!>
(Logs for all matching pods/containers come out, individually colored)

Nice!

You’ll get some mileage out of the Kubernetes Dashboard. It gives you plenty of data about your cluster in a nice web UI. Follow the official instructions to get it all set up and running.

I’ll keep adding new ones as I find them!

Wrapping Up

At this point, we’ve used Docker Desktop to create a fully provisioned Kubernetes environment that you can access from WSL2 or from Windows itself. You can deploy individual containers using docker run or kubectl run. You’ve got a couple of useful utilities to help you see what’s inside your cluster.

What’s next? How about building an app with a database, service, UI, and authentication all baked into a stack that you can deploy? Over the next weeks** I plan to build a series of articles that show you how to do just that.

** “weeks” in this context means “one or more 7-day periods, emphasis on more

--

--

Nate Carpenter

If it's optional, why do I get prompted every time?