Building A Sandbox Environment for A Big Data Cluster With microk8s

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:

  1. 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
  2. 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:

    ssh <Ubuntu_user_account>@<Ubuntu_Vm_ip_address>
  3. Create a single node cluster:

    sudo snap install microk8s --channel=1.18 --classic
  4. Add the Ubuntu user to the microk8s group:

    sudo usermod -a -G microk8s <Ubuntu_user_account>
  5. We can now access kuebctl via:

    microk8s.kubectl

    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:

    newgrp -
  6. Enable the Kubernetes dashboard:

    microk8s enable dashboard
  7. Enable persistent storage for the cluster:

    microk8s enable storage
  8. Create the config for accessing the cluster from your Windows client, execute the following commands from with a DOS command shell:

    cd Users\username
    ssh <Ubuntu_user_account>@<Ubuntu_Vm_ip_address> "/snap/bin/microk8s.kubectl config view --raw" > .kube\config
  9. 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:

    server: https://127.0.0.1:16443

    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.
  10. 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

  11. Obtain the name of the secret associated with the dashboard:

    kubectl get secret
  12. 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
    dashboard-admin-sa-token-vjjgx.
  13. Describe the dashboard secret and save the token text from the output somewhere safe:

    kubectl describe secret dashboard-admin-sa-token-vjjgx
  14. Start a proxy for the Kubernetes cluster API server on your Windows machine:

    kubectl  proxy
  15. Paste this text into the URL bar of your client machines browser:

    http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
  16. 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.

Next Up

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s