Add a Windows worker node to MicroK8s

MicroK8s supports running Windows workloads. This guide will go through the process of joining a Windows Server 2019 node to an existing MicroK8s cluster running Calico.

Prerequisites

Export kubeconfig

To access the cluster, calicoctl will need a copy of the kubeconfig from MicroK8s. This can be made in any location - this example copies it to the default path:

  1. mkdir -p ~/.kube
  2. microk8s config > ~/.kube/config

Set affinity

In order for Windows pods to schedule, strict affinity must be set to true. This is required to prevent Linux nodes from borrowing IP addresses from Windows nodes. This can be set with the calicoctl binary. Be sure to point calicoctl to the Kubernetes API, rather than directly to Etcd.

  1. DATASTORE_TYPE=kubernetes KUBECONFIG=~/.kube/config calicoctl ipam configure --strictaffinity=true

(replace the path for the kube config file if you saved it in a different location)

Gather the Kubernetes version

At a later stage, you will need to know the exact version of Kubernetes installed. This can be grabbed from MicroK8s.

  1. microk8s kubectl get node $(hostname)

Note the output in the format X.X.X, e.g. 1.19.3.

Install components on the Windows node

You are now ready to install Calico onto the Windows node. This will also install Kubernetes components required for a working node.
All code snippets here should be run in PowerShell running as Administrator.

Create directory for Kubernetes

All Kubernetes components will be installed into this directory.

  1. mkdir C:\k\

In here, place the kubeconfig file previously exported from MicroK8s. Be careful as some editors may try to append file extensions. You can test that it has been named correctly by trying to print the contents after you’ve saved it:

  1. cat C:\k\config

Install

The Calico Project provides a helper script to fetch all the required binaries and services. Official documentation is available for this script, but the required steps are covered here.

First, download the script.

  1. Invoke-WebRequest https://docs.projectcalico.org/scripts/install-calico-windows.ps1 -OutFile C:\install-calico-windows.ps1

You can then run the script with the required parameters. Change the -KubeVersion argument to the version noted earlier.

  1. C:\install-calico-windows.ps1 -DownloadOnly yes -KubeVersion 1.19.3

Note: You can also explicitly set whether you are running Calico in vxlan or BGP mode by specifying this as an addidional argument, e.g.-CalicoBackend "vxlan"

Register the Calico services.

  1. C:\CalicoWindows\install-calico.ps1

Then register the Kubernetes services so they come up with the node.

  1. C:\CalicoWindows\kubernetes\install-kube-services.ps1

This script won’t start the Kubernetes services. Let’s do that now:

  1. Start-Service kubelet
  2. Start-Service kube-proxy

Cleanup

Remove the temporary files created in the previous steps:

  1. rm C:\install-calico-windows.ps1
  2. rm C:\calico-windows.zip

Finish

You can verify the node come up on the cluster by switching back to the MicroK8s node and running the command:

  1. microk8s kubectl get no -o wide

Uninstalling

To uninstall the node components, simply run the downloaded script once more:

  1. C:\install-calico-windows.ps1 -DownloadOnly yes -KubeVersion 1.19.3

This will indicate that a version is already installed and prompt if you want to remove it. Choose Y and the node components will be uninstalled

Upgrading

There is no specific upgrade path for a Windows node. If you have upgraded MicroK8s to a later version, and wish the Windows node to remian compatible, you should re-run the install script to uninstall the node components (see above), then run the installer again, indicating the new version of Kubernetes to use.

Last updated a month ago. Help improve this document in the forum.