Ubuntu in WSL
eth0 172.18.230.128/20
- Docker Engine 29.2.1
- kind
- kubectl
- helm
- File-watch limits
No kind network yet. Step 3 creates one with a range of its own, clear of WSL's 172.18.230.128/20.
Build a local Kubernetes lab on Windows
Before you start
What you’ll build
This lab builds a small Kubernetes cluster on your own Windows machine: one control planeThe node that runs Kubernetes' own components: the API server, the scheduler and the controllers. and three workersA node that runs your workloads: the pods of your apps., each a container inside WSLWindows Subsystem for Linux: a real Linux kernel running in a lightweight virtual machine on Windows.. It costs nothing, needs no spare hardware, and stays off until you start it.
The cluster sits on its own Docker network, which behaves like a small office network (a LANLocal area network: the machines on the same switch, which can reach each other directly.). That matters for tools such as MetalLB that answer for addresses on the LAN: your WSL shell is on the same network, so you see what a laptop on a real office network would see.
How to work through it. Each step shows its commands, what each one does, and what the real run printed. Press Run in the lab on a command to try it in the practice terminal first, where the drawing under the terminal shows what it built. Then run the same command in your own Ubuntu terminal and check your output against the step's.
What you need:
- WSL 2 with Ubuntu. In PowerShell,
wsl -l -vlistsUbuntuwithVERSION 2. - Docker Engine running inside Ubuntu. Step 1 checks it.
- About 4 GB of free memory for the four nodes, and 2 GB of disk for the node image.
Tested with
- Windows
- 11
- WSL
- 2.5.10
- Ubuntu
- 24.04
- Docker Engine
- 29.2.1
- kind
- 0.33.0
- Kubernetes
- 1.37.0
- kubectl
- 1.37.3
- Helm
- 4.3.2
Step 1 of 5
Check WSL and Docker
WSL 2 with Ubuntu, and Docker Engine running inside it.
Ask Docker which version is running, and on what. If this prints an error instead, Docker isn't running inside Ubuntu yet: start it before going on.
docker info --format '{{.ServerVersion}} ({{.OperatingSystem}})'29.2.1 (Ubuntu 24.04.3 LTS)Step 2 of 5
Install kind, kubectl and Helm
Three single files, each checked against its published checksum before it's installed.
kindKubernetes in Docker: runs each Kubernetes node as a Docker container, so a whole cluster fits on one machine. creates the cluster, kubectl talks to it, and HelmA package manager for Kubernetes: a chart bundles all of an app's objects, installed with one command. installs apps into it. Each is a single file you download, check and copy into place.
Make a folder for the downloads, and go into it:
mkdir -p ~/lab-install && cd ~/lab-installDownload kind, and the checksum its project publishes for it. -L follows redirects and -O keeps the file's own name. Then sha256sum -c recomputes the file's fingerprint and compares it with the published one:
curl -LO https://kind.sigs.k8s.io/dl/v0.33.0/kind-linux-amd64
curl -LO https://github.com/kubernetes-sigs/kind/releases/download/v0.33.0/kind-linux-amd64.sha256sum
sha256sum -c kind-linux-amd64.sha256sumkind-linux-amd64: OKThe same for kubectl. Its checksum file holds only the fingerprint, without the file name, so the command adds the name before checking:
curl -LO https://dl.k8s.io/release/v1.37.3/bin/linux/amd64/kubectl
curl -LO https://dl.k8s.io/release/v1.37.3/bin/linux/amd64/kubectl.sha256
echo "$(cat kubectl.sha256) kubectl" | sha256sum -ckubectl: OKAnd Helm, which comes as an archive, so unpack it once it checks out. That makes a linux-amd64 folder with helm inside:
curl -LO https://get.helm.sh/helm-v4.3.2-linux-amd64.tar.gz
curl -LO https://get.helm.sh/helm-v4.3.2-linux-amd64.tar.gz.sha256sum
sha256sum -c helm-v4.3.2-linux-amd64.tar.gz.sha256sum
tar -xzf helm-v4.3.2-linux-amd64.tar.gzhelm-v4.3.2-linux-amd64.tar.gz: OKIf any check doesn't say OK, the download is broken or isn't what the project published: delete it and download again.
Copy the three programs into /usr/local/bin, which is on every user's path. install -m 0755 copies a file and makes it runnable in one go:
sudo install -m 0755 kind-linux-amd64 /usr/local/bin/kind
sudo install -m 0755 kubectl /usr/local/bin/kubectl
sudo install -m 0755 linux-amd64/helm /usr/local/bin/helmAdd three small network tools that later labs use: arping asks the network who has an address, tcpdump shows the packets, and ts (in moreutils) puts a timestamp on each line so you can time a failover.
sudo apt-get update && sudo apt-get install -y iputils-arping tcpdump moreutilsThe following NEW packages will be installed:
ibverbs-providers iputils-arping libibverbs1 libio-pty-perl libipc-run-perl libnl-3-200
libnl-route-3-200 libpcap0.8t64 libtime-duration-perl libtimedate-perl moreutils tcpdump
0 upgraded, 12 newly installed, 0 to remove and 230 not upgraded.Check all three answer:
kind version && kubectl version --client && helm version --shortkind v0.33.0 go1.26.7 linux/amd64
Client Version: v1.37.3
Kustomize Version: v5.8.1
v4.3.2+g8346aaaStep 3 of 5
Give the cluster its own network
A Docker network with a fixed address range that doesn't clash with WSL's own.
kind puts its nodes on a Docker network called kind. Creating it yourself first lets you choose its address range, so later labs can rely on it. First see which addresses WSL itself uses:
ip addr show eth02: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:15:5d:87:3c:56 brd ff:ff:ff:ff:ff:ff
inet 172.18.230.128/20 brd 172.18.239.255 scope global eth0
valid_lft forever preferred_lft foreverThe inet line is WSL's address, 172.18.230.128, on a /20 network that runs from 172.18.224.0 to 172.18.239.255.
How the /20 range is worked out
An IPv4 address is four numbers, and each one is 8 bits, because 8 bits count from 0 to 255. That makes 32 bits in all:
172 . 18 . 230 . 128
8 8 8 8/20 splits those 32 bits in two:
- The first 20 bits are the network part. Every machine on this network has the same ones.
- The other 12 bits are the machine part. Each machine on the network has its own.
20 bits is 8 + 8 + 4: all of the first two numbers, 172.18, and the first 4 bits of the third. So 172.18 never changes, the fourth number is all machine part, and only the third number is split, 4 bits on each side. Each of its 8 bits stands for a value, and the number is the sum of the values whose bit is 1. The | marks the split:
network |machine
value 128 64 32 16|8 4 2 1
mask 1 1 1 1|0 0 0 0
230 1 1 1 0|0 1 1 0
lowest 1 1 1 0|0 0 0 0
highest 1 1 1 0|1 1 1 1The mask has a 1 for every network bit and a 0 for every machine bit. For the third number that's 1111|0000, which is 128 + 64 + 32 + 16 = 240. That's why tools also write /20 as 255.255.240.0: each 255 is a number whose 8 bits are all network.
The lowest address is the address ANDed with the mask: a bit stays 1 only where both have a 1. So the network bits of 230 are kept, 1110, and its machine bits all become 0000: 128 + 64 + 32 = 224. The fourth number's mask is all 0s, so it becomes 0 too, and the network starts at 172.18.224.0.
The highest address keeps the same network bits and sets every machine bit to 1: 128 + 64 + 32 + 8 + 4 + 2 + 1 = 239. The fourth number becomes 255, so the network ends at 172.18.239.255.
The brd (broadcast) address on the inet line is that last address, which confirms it. In the same way, /16 is exactly the first two numbers, so 172.30.0.0/16 runs from 172.30.0.0 to 172.30.255.255: every address that starts with 172.30.
The cluster gets 172.30.0.0/16: every address that starts with 172.30. So there's one thing to check: your eth0 address must not start with 172.30. If it does, pick another private range for the cluster.
Four kind nodes on one machine can run out of file-watch handles ("too many open files"), so raise the two Linux limits first:
sudo sysctl -w fs.inotify.max_user_watches=524288 fs.inotify.max_user_instances=512fs.inotify.max_user_watches = 524288
fs.inotify.max_user_instances = 512Then create the network. Docker prints its ID:
docker network create kind --subnet 172.30.0.0/161639579274dba9556ce66e6603fe5c576dcac93b941bf2857bb88f9990da3550Step 4 of 5
Create the cluster
One control plane and three workers, from a short config file.
Describe the cluster in a file. Each role line is one node:
cat > ~/kind-lab.yaml <<'EOF'
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker
EOFCreate the cluster from it. The first run downloads the node image, about 1 GB, so it takes a few minutes. The cluster gets kind's default name, kind, so every later lab can use the same one, and kind points kubectl at it:
kind create cluster --config ~/kind-lab.yamlCreating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.37.0) 🖼️
✓ Preparing nodes 📦 📦 📦 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
✓ Joining worker nodes 🚜
Set kubectl context to "kind-kind"List the nodes. -o wide adds each node's address, from the range you chose:
kubectl get nodes -o wideNAME STATUS ROLES AGE VERSION INTERNAL-IP ...
kind-control-plane NotReady control-plane 13s v1.37.0 172.30.0.5 ...
kind-worker NotReady <none> 1s v1.37.0 172.30.0.3 ...
kind-worker2 NotReady <none> 1s v1.37.0 172.30.0.2 ...
kind-worker3 NotReady <none> 1s v1.37.0 172.30.0.4 ...NotReady is normal for the first half minute, until the network pluginContainer Network Interface plugin: gives pods their addresses and connects them. kind uses its own, kindnet. is running on every node. Ask again:
kubectl get nodesNAME STATUS ROLES AGE VERSION
kind-control-plane Ready control-plane 2m29s v1.37.0
kind-worker Ready <none> 2m17s v1.37.0
kind-worker2 Ready <none> 2m17s v1.37.0
kind-worker3 Ready <none> 2m17s v1.37.0Step 5 of 5
Keep it off until you need it
Stop the nodes starting with WSL, and switch the cluster on and off with one command.
kind sets its nodes to restart whenever Docker does, and Docker starts with WSL, so by default opening Ubuntu brings the whole cluster back. Turn that off for the four node containers (kind labels them, so the filter finds exactly those). Docker prints each container's ID:
docker update --restart=no $(docker ps -aq --filter label=io.x-k8s.kind.cluster=kind)Add a small kind-lab command that starts or stops all four. tee writes the lines up to EOF into the file, and chmod +x makes it runnable:
sudo tee /usr/local/bin/kind-lab >/dev/null <<'EOF'
#!/usr/bin/env bash
# Start or stop the shared kind cluster's node containers.
nodes=$(docker ps -aq --filter label=io.x-k8s.kind.cluster=kind)
case "$1" in
up) docker start $nodes >/dev/null && echo "kind cluster started" ;;
down) docker stop $nodes >/dev/null && echo "kind cluster stopped" ;;
*) echo "usage: kind-lab up|down" ;;
esac
EOF
sudo chmod +x /usr/local/bin/kind-labCheck the restart policy took on every node:
docker ps -a --filter label=io.x-k8s.kind.cluster=kind --format '{{.Names}}' | xargs docker inspect -f '{{.Name}} restart={{.HostConfig.RestartPolicy.Name}}'/kind-worker restart=no
/kind-worker3 restart=no
/kind-worker2 restart=no
/kind-control-plane restart=noSwitch the cluster off and on again. After kind-lab up, give the nodes half a minute, then kubectl get nodes shows them Ready again. This part wasn't in the logged run: the two messages are the script's own.
kind-lab down
kind-lab upkind cluster stopped
kind cluster startedFrom now on:
| To | Run |
|---|---|
| Start the cluster | kind-lab up |
| Stop the cluster | kind-lab down |
| Stop WSL completely, Docker included | wsl --shutdown, in PowerShell |
| Delete the cluster | kind delete cluster. The kind network stays, ready for the next one |