Running a Kubernetes local cluster on Windows
Tags: kubernetes, devops, cloud, docker
Published: 2021-03-28 23:44:11

Nowadays we can use WSL _Windows Subsystem for Linux_ technology to run Kubernetes on Windows almost seamlessly! So let's do this :sunglasses: 

---
:clipboard: [Installation](#configuration-stuff)
:x: [Known issues](#known-issues)
:ferris_wheel: [Playing with kubernetes](#playing-with-kubernetes)
:pencil2: [Conclusion](#Conclusion)

---

:warning: **First of all** check requirements for running WSL 2 :warning:

:white_small_square: For x64 systems: Version 1903 or higher, with Build 18362 or higher.
:white_small_square: For ARM64 systems: Version 2004 or higher, with Build 19041 or higher.


## Configuration Stuff

1. To install and enable WSL here's the official guide made by Microsoft: https://docs.microsoft.com/en-us/windows/wsl/install-win10
  - In this step, I choose the Ubuntu 20.04 distro.
2. Install Docker Desktop on Windows: https://www.docker.com/products/docker-desktop
3. Configuring Docker Desktop to use WSL
  - In Docker Desktop `Settings`
     - :arrow_forward: ***General***
     - Then select:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2gt5bs83ycguksv6xm4r.png)
     - :arrow_forward: ***Resources***
     - :arrow_right: WSL Integration
     - Then select:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3p90ebo1p4aocxswq6yr.png)
     - _Apply_ and _Restart_!
4. To check the previous step, open your wsl distro and execute `docker version` and `kubectl version`. Both binaries have been installed in your distro. 
5. Finally, just enable Kubernetes in Docker Desktop ***settings***:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ocgbxc9ecjmtvcb4kb4.png)
- This may take a while so be patient.

## Known issues

_Be patient_ but don't wait forever. So if your kubernetes installation process stuck in ***"Kubernetes is starting.."*** go to the troubleshooting section, ***Get Suport*** and waiting for *DIAGNOSTICS*.
The *output log* from Docker Desktop, in my case:
```
cannot get lease for master node: an error on the server (\"\") has prevented the request from succeeding (get leases.coordination.k8s.io docker-desktop)
```
You can try any of these solutions from _stackoverflow_:
>https://stackoverflow.com/questions/55361963/kubernetes-is-starting-forever-error-on-windows-10

- But I had to reset Docker Desktop to default to solve this issue :disappointed_relieved:.

## Playing with Kubernetes

> You can use `kubectl` commands in wsl distro or directly from Windows, in this case you have to [install the binary](https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/) 

`kubectl config get-contexts` the expected output is all clusters configured in your `kubeconfig` file but we're interested at:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/slni3e57rjgsnqrxhqtz.png)

`kubectl get pods -n kube-system` to see related kubernetes system 
 PODs.
`kubectl cluster-info` to get cluster information.
`kubectl get nodes -o wide` to get information about the single node running in our cluster.
### Deploying a hello world app
`kubectl run hello --image=tutum/hello-world --port=80`
`kubectl get pods` to see the hello POD up and running
`kubectl port-forward hello 8080:80` to forward local port 8080 to  POD port 80 and make it accessible through http://localhost:8080/
`kubectl logs hello` to see the stdout from `hello` POD

## Conclusion

I know we can't test all kubernetes power with a _single node cluster_ but even with just a single node there's a lot of features and scenarios that we can test and I promise to write a more interesting example than a basic hello world someday.
I really had a great experience using WSL2 and if you are just like me that have to use Windows on the laptop for whatever reason I encourage you to try it!