More Kubernetes: WSL2, Hyper-V, Docker, and X11

Most programming I do at my day job is done via PuTTY and IntelliJ. The latter runs on Linux and I run MobaXterm as an X11 server. I don’t use Moba’s terminal because the chrome around it’s way to gizmo-ey, like I’m at an ugly sweater party or something.

PuTTY is ideal because it’s so minimal and it has all the features I need. I actually use PuTTY Tray, which is a fork that has a few more options than the standard PuTTY. IntelliJ works great over X11 and MobaXterm is pretty snappy on our local network, even from our datacenter to our office.

That said, at home I don’t have access to a fancy $70k server running dual Intel Platinum Xeon processors with 512GB of RAM and 1.6TB of Enterprise-grade Northbridge-connected NVMe drives. I have a 12/24 core AMD Ryzen 3900X and Windows 10 Pro for Workstations. But Windows is so developer-friendly these days, it gives me a ton of options for development.

You can do Linux a few ways, two of which are in a VM via Hyper-V or using Windows Subsystem for Linux (WSL). In the very latest fast-ring builds of Windows, you can enable WSL2, which is an overhaul of the subsystem that’s a lot faster and more compatible with Linux binaries.

WSL2

To get WSL2, I joined the Windows Insider program and set updates to the “Fast Ring”. Right now I’m running Windows 10 Pro for Workstations Build 19025.vb_release.191112-1414, or whatever. Then I followed the steps here to enable WSL2. Yippee!

Docker

Docker isn’t by default available in WSL2, and I’d prefer it was since I like to stay in a bash prompt over PowerShell or cmd.exe. Lucking the latest Docker for Windows Edge version has an option to expose Docker to WSL2. It’s in Settings > Resources > WSL Integration. To check things are working, run wsl -l -v

PS C:\Users\nic> wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop         Running         2
  docker-desktop-data    Running         2

X11

I wanted to see if I could get IntelliJ to run under WSL/X11 and my initial attempts were met with utter failure. IntelliJ wouldn’t start up no matter what I set my DISPLAY variable to. localhost:0 (or 0.0) didn’t work, nor 127.0.0.1:0, nor the eth0 IP reported by ifconfig, nor the Windows desktop IP. Finally, I went into /etc.resolve.conf and saw this:

nameserver 172.22.80.1

Setting my DISPLAY to 172.22.80.1:0 worked.

One interesting observation is that the WSL2 network and my Desktop bridged network to my home router are isolated enough that IntelliJ’s license check can’t detect that I had two copies open. One copy running natively on Windows and the second running in the WSL context over X11. On a flat network, the second copy would refuse to run, or the first copy would die on launch of the second. I forget!

Kubernetes

So I went through all of this so I could interact with my Kubernetes cluster at the WSL prompt. I setup Rancher as a container running in Docker for Windows. Once Rancher was running, I created three VM’s running Ubuntu using Hyper-V and called them node1, node2, and node3. Rancher made it easy to have each VM register itself as a node in a cluster called “Lab”. At this point I’m using 27GB of my 32GB of RAM, which is surprising so I’ll probably scale down Docker and the VM’s RAM. maybe giving each VM 4GB was a little excessive.

I still have two free DIMM slots so I guess it will be time to get to 64GB soon.

The cluster is extremely unstable and I’m in the process of figuring out why. When I reboot the desktop, the VM’s (cluster nodes) shut down (along with Rancher’s container) and after the reboot rancher comes up, tons of containers in each node come up, but the status is redder than Carrie at her Prom.

For some reason, the containers running on each VM node do not auto-start until I invoke docker somehow, like sudo docker ps. I’m still researching why this is.