Creating a Lightweight Local Windows K8S & Docker Development Environment

Edson Morais
5 min readJun 7, 2022

As a smart IT guy, applying DevOps’ practices and thoughts, let’s see how to create a simple, lightweight, and open-source solution for container orchestration, yeah, inside a Windows computer ;)

>>> Chocolatey (to manage Windows package installation) <<<

1 — Installation:

  • Download the installer (here).
  • Open Powershell as Administrator and run the command below:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(‘https://community.chocolatey.org/install.ps1'))

>>>Minikube (the K8S server) <<<

0 — Credits and References:

1 — Installation:

  • Open Powershell as Administrator and run the commands below:

choco install minikube
choco install kubernetes-cli

2 — Configuration:

  • Open the Hyper-V Manager:
  • Once in the Hyper-V Manager, on the right panel, select the Virtual Switch Manager:
  • Next, we will create a virtual switch for minikube. Select New virtual network switch on the right-hand side, select External for the network type, and then press the Create Virtual Switch button:
  • Name the switch Primary Virtual Switch and click the apply button:
  • Open the Windows Network Connections:
  • Important note: When we create a new Hyper-V network adapter, it’s directly related to the current network used in your computer (look at the adapter above, it’s related to the network “MEO-1720BF”), which means that you should be connected to this network, before starting the minikube, Docker, commands!
  • Edit the settings of the adapter “Primary Virtual Switch” and desirable the IPV6 option:
  • Open Powershell as Administrator and run the commands below:

minikube start — vm-driver hyperv — hyperv-virtual-switch “Primary Virtual Switch”

[Wait for the command success, and run the next one]

minikube stop

  • Once minikube has stopped, open the Hyper-V Manager again and right click on the minikube VM and select settings:
  • Select the Memory option on the left panel, then de-select Enable Dynamic Memory, and then click Apply button:
  • Open Powershell as Administrator and run the commands below:

minikube start
kubectl get pods -n kube-system

[You should see the following result]

minikube dashboard

[That will open up the dashboard window in your default browser]

[To use minikube Docker as your local Docker host and engine]

& minikube -p minikube docker-env — shell powershell | Invoke-Expression

docker image ls

[That will show a result like that]

>>> WSL2 pointing to the Minikube <<<

1 — Comments:

  • After the steps above opening the path [%USERPROFILE%] you’ll see the folders [.kube] and [.minikube]:

2 — Configuration:

  • Access your WSL2 environment [you can use the MS VS Code to do that, or another tool according to your preference].
  • The example below uses a WSL2 with Ubuntu.
  • Run the command below to install the kuctl:

sudo apt-get update
sudo apt-get install -y kubectl

  • Using the Windows Explorer or another tool according to your preference do the copy and paste below (pay attenuation to the FROM & TO):

FROM [Windows]: %USERPROFILE%/.minikube (all the files; not the folders !!)
TO [WLS2]: $HOME/.kube/.minikube

FROM [Windows]: %USERPROFILE%/.minikube/profiles/minikube (this folder)
TO [WLS2]: $HOME/.kube/profiles/minikube

FROM [Windows]: %USERPROFILE%/.kube/config
TO [WLS2]: $HOME/.kube/config
NOTES: After this copy&paste, in the [WSL2] open the file $HOME/.kube/config and change the paths below:

- cluster:
[FROM] certificate-authority: C:\Users\<user-name>\.minikube\ca.crt
[TO] certificate-authority: .minikube/ca.crt

users:
- name: minikube
user:

[FROM]
client-certificate: C:\Users\<user-name>\.minikube\profiles\minikube\client.crt
client-key: C:\Users\<user-name>\.minikube\profiles\minikube\client.key

[TO]
client-certificate: profiles/minikube/client.crt
client-key: profiles/minikube/client.key

Take a look at the folders and files after the steps above:

[Windows]

[WLS2]

  • In your WSL2 environment run the commands below:

kubectl get pods -n kube-system

[You should see the following result]

  • Considering that you have Docker installed in your WSL2 environment (if haven’t you the Docker installed, first, follow the steps to do that, here), run the commands below to set the WSL2 Docker to pointing to the Minikube server:

export DOCKER_TLS_VERIFY=”1"

export DOCKER_HOST=”tcp://<minikube-server-ip>:<minikube-server-port>”

export DOCKER_CERT_PATH=”$HOME/.kube/.minikube”

  • In your WSL2 environment run the commands below:

docker image ls

[You should see the following result]

Well done :)

Now you’re able to deploy your K8S workloads for development and study purposes., without dirtying your computer, and have more proximity, notion, and visibility to the real and stage|production environment.

Be fast, be productive, without suffering ;)

--

--