Local Kubernetes

If you’ve used containers either for work or in your hobby you will have no doubt come across Kubernetes. It makes possible orchestration of hundreds and even thousands of containers on a cluster of machines. However if you are just starting and want to run a local test you don’t want to be setting up a local cluster at this point.

Another option would be a Kubernetes service from Azure, AWS or Google. Easy to set up but you may not want to pay for hosted services at this point. Or you want the retain the ability to test locally before checking the code where a CI/CD pipeline will put the container(s) into your running cloud service.

The typical answer in the past has been to set up minikube. How if you are running Windows Pro and have Hyper-V configured you may prefer the installing multipass and runing microk8s from Ubuntu instead.

You can download a Windows installer for multipass from the above link and there is a how to set up Kubernetes on Windows guide which covers getting started. Any VMs started by multipass can be viewed in Hyper-V Manager as normal.

One thing I didn’t like was the way it stored the VMs in C:\Windows\System32\config\systemprofile\AppData\Roaming by default with no option I could find to change in. I keep the VM images on a different drive for space reasons, not my SSD C: drive. Thankfully Windows has been able to create hard links since Vista.

If like me you want to move the images to a separate drive, open up C:\Windows\System32\config (you mayneed to grant yourself access to this folder) then the systemprofile folder (again you may need to grant yourself access). Continue to AppData \ Roaming \ multipass.

Move (cut and paste) the vault folder to another drive; I will use I: as an example. Then open up a command prompt as administrator (mklink is not available in powershell) and enter the following two commands

cd C:\Windows\System32\config\systemprofile\AppData\Roaming\multipassd
mklink /j vault I:\vault

That’s it; images moved to another drive with more space and you are ready to use multipass for running Ubuntu images on Windows.

If you have installed Docker Desktop for Windows (and I recommend you do) then this will install a version of kubectl for interacting with your newly built cluster. You can confirm it is installed and in your path by typing kubectl version.

While you should have got a version for the client; you will probably get an error saying it cannot talk to the server. That’s because the server is not running on the localhost but a separate VM. If you type kubectl config view you should see no clusters are configured.

The instructions on getting the configuration (and status) on the Ubuntu page is incorrect; microk8s is an executable not a set of files. To get a configuration file locally on your machine enter the command below: (it’s a single command that should be entered on one line)

multipass exec microk8s-vm -- sudo /snap/bin/microk8s config > microk8sconfig

You can now verify kubectl can access the server with the following command which should now return both the client and the server version

kubectl --kubeconfig=microk8sconfig version