At work we are seeing a burgeoning demand for Kubernetes test and development environment, as such we have been looking at simple and rapid ways to provision clusters. I have already blogged about the use of Kubespray to deploy multi-node “Production grade” clusters. However, for multi-node test/development environments there is a far simpler way to do this, and that is to use microk8s from Canonical. Simply put microk8s comes as a snap with Ubuntu, snap being the next generation package management and deployment system built into Ubuntu. The beauty of microk8s is that you can spin up a single node cluster in a single command. Unlike minikube, multi-node clusters can be built using microk8s and it can leverage storage plugins that adhere to the Container Storage Interface standard.
Here are the steps for creating a single node microk8s cluster:
- Create an Ubuntu virtual machine:
Kubernetes does not require virtualisation, however, my experience is that most organisations run SQL Server on top of an infrastructure virtualized via VMware. Therefore, when most people try spinning up a Kubernetes cluster for the very first time, its highly likely to be on top of VMware. If you are a “VMware shop” you can follows the instructions in section 2.3 of this material I have helped put together for Microsoft. Hyper-V users can follow the instructions in this blog post. A third option is to use multipass from Canonical:
multipass launch -n microk8s-vm -c 8 -m 64GB -d 100G
- ssh into the Ubuntu virtual machine
You can use a ssh client such as Putty to do this, or simply fire up a DOS command shell session and issue:
- Create a single node cluster:
sudo snap install microk8s --channel=1.18 --classic
- Add the Ubuntu user to the microk8s group:
sudo usermod -a -G microk8s <Ubuntu_user_account>
- We can now access kuebctl via:
However, being a pedant, I prefer to be able to run the command without having to use a microk8s prefix, this is easily fixed by creating an alias for kubectl:
echo "alias kubectl='sudo /snap/bin/microk8s.kubectl'" >> ~/.bashrc
force your current shell session to pick this alias by issuing:
- Enable the Kubernetes dashboard:
microk8s enable dashboard
- Enable persistent storage for the cluster:
microk8s enable storage
- Create the config for accessing the cluster from your Windows client, execute the following commands from with a DOS command shell:
ssh <Ubuntu_user_account>@<Ubuntu_Vm_ip_address> "/snap/bin/microk8s.kubectl config view --raw" > .kube\config
- Change the ip address in the config file from that of localhost:
Open the config file in the text editor of your choice, I like textpad for Windows. The fifth line down in the config file should look like:
Change 127.0.0.1 to the ip address of the Ubuntu virtual machine on the network – the same ip address by which it can be accessed by your Windows client machine.
- Create a service account for accessing the dashboard and bind it the cluster-admin role, this can be carried out using kubectl from your Windows machine:
kubectl create serviceaccount dashboard-admin-sakubectl create clusterrolebinding dashboard-admin-sa --clusterrole=cluster-admin --serviceaccount=default:dashboard-admin-sa
- Obtain the name of the secret associated with the dashboard:
kubectl get secret
- The output from the prevsious command should contain a secret with a name prefixed by dashboard-admin-sa-token, when testing this, the secret in my single node cluster is
- Describe the dashboard secret and save the token text from the output somewhere safe:
kubectl describe secret dashboard-admin-sa-token-vjjgx
- Start a proxy for the Kubernetes cluster API server on your Windows machine:
- Paste this text into the URL bar of your client machines browser:
- A dialog with two radio buttons will appear, select the radio button for token, paste the token text into the dialog that was obtained earlier and hit sign in.
You are probably thinking that was a lot of steps that we went through to deploy the dashboard, but there is a very good reason behind this – as per this blog post by Joe Beda on why securing the Kubernetes dashboard is important.
Following the steps in this blog post will result in a single node Kubernetes cluster. The minimum resources requirements for deploying a big data are:
- 64GB of memory
- 8 logical processors
- 100GB of storage
For the purpose of deploying a big data cluster in order to see what one looks like from the perspective of the objects it is comprised of, a virtual machine with 16GB of memory will suffice. In the follow on post to this, we will deploy an actual big data cluster to our sandbox.