Skip to content

Instantly share code, notes, and snippets.

@CarlosDomingues
Last active April 29, 2022 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarlosDomingues/a20bec076b12f296de7573d0e93b9be6 to your computer and use it in GitHub Desktop.
Save CarlosDomingues/a20bec076b12f296de7573d0e93b9be6 to your computer and use it in GitHub Desktop.
Kubernetes on Docker on Linux on Windows

Kubernetes on Docker on Linux on Windows

This guide shows how to run Kubernetes in a Windows Host, using kind to run the control plane in Docker and WSL 2 to run Docker itself.

The whole point of doing that is to run Kubernetes:

  1. In a Windows Host
  2. Without managing virtual machines (Docker Desktop + WSL 2 will do that for us)
  3. Without using Docker Desktop's native Kubernetes feature (as it has a tendency to break workflows that do not relly on K8s).

To use this guide, just follow each session sequentially. There are no optional steps.

Install Scoop

scoop is a lightweight package manager for Windows. It installs applications in ~/.scoop and adds then to PATH. We will use it to install CLI tools.

Set-ExecutionPolicy RemoteSigned -scope CurrentUser
iwr -useb get.scoop.sh | iex
scoop --version

Install CLI Tools

kind is a tool for running local Kubernetes clusters using Docker containers as “nodes”.

kubectl is a tool that allows runing commands against Kubernetes clusters.

We will install those tools using scoop.

scoop install kind kubectl
kind version
kubectl version --client

Install Docker Desktop on Windows

Docker Desktop an application created by Docker Inc.'s (the company that created Docker, the technology). It provides a user friendly graphical user interface to run and inspect Docker containers. It also creates and manages a virtual machine in which containers are executed. That allows Windows users to run Linux containers. The most recent versions of Docker for Desktop run containers using WSL 2, which is a Windows subsystem that ships a Linux kernel, allowing users to run Linux distros in Windows without the overhead of a virtual machine.

To install Docker Desktop, download it from the official web page and follow the interactive graphical installer (this will require privillege elevation).

Create a cluster

Create a cluster by invoking kind, then check if kubectl is configured correctly:

kind create cluster
kubectl cluster-info --context kind-kind

If everything was setup correctly, you should see a message like so:

Kubernetes control plane is running at https://127.0.0.1:62109
CoreDNS is running at https://127.0.0.1:62109/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

A Quick Test

Create a simple deployment:

kubectl create deployment nginx --image=nginx --port=80
kubectl expose deployment/nginx

Networking

Resources can be accessed from the Windows host using a browser.

  • Control Plane: https://127.0.0.1:62109
  • Services:

A Winner is You

That's it. You can now run commands against your cluster using kubectl or use graphical tools like Lens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment