Microk8s is an orchestrating tool for automating containerized applications’ management, deployment, and scaling. It is a CNCF-certified upstream Kubernetes deployment that runs entirely on our workstation.
Being a snap, it runs all Kubernetes services natively while packing the entire library. MicroK8s doesn’t require a virtual machine, unlike tools like Minikube, which spins up a local virtual machine for the Kubernetes cluster. This feature has its shortcomings also. Microk8s requires Linux (distributions that support snap) while tools like minikube offer support. We will need to set up Linux on top of a virtual machine if we are to deploy microk8s on a non-Linux OS.
We follow the approach of installing Ubuntu 20.04 on top of Windows 10 using VirtualBox. You can use an existing Ubuntu machine or spin up an ubuntu server on the cloud.
Access the VirtualBox downloads page from a browser. Click on ‘Windows Hosts’, and the downloading of the installer file will be started. Select the installer file from the browser downloads folder and start the installation.
Follow the on-screen instructions to complete the installation. Provide appropriate access permissions. Click finish and open Oracle VM VirtualBox Manager
Open Oracle VM VirtualBox Manager and Click on ‘New’
Execute the following steps:
* Give an appropriate name for VM
* Select the ‘Machine Folder’ to save all the files regarding VM
* Select Type as ‘Linux’ and version as ‘Ubuntu (64 bit)’
* Click on ‘Next’
Select appropriate RAM for the virtual machine. Ubuntu recommends 4 GB of RAM. Make sure enough RAM is left for the host system processes. Click Next.
Select ‘Create a virtual hard disk now. Click Create
Select the default Virtual Hard disk file type. Other options are also supported. Click Next
Select ‘Dynamically allocated’ for the storage option for the virtual hard disk. Click Next
Select the file location and file size. Ubuntu recommends 25 GB of free hard drive space. Click ‘Create’.
From the ‘Oracle VM VirtualBox Manager’ main window, select the configured VM (Ubuntu20.04 in our case). Click ‘Settings’
Click on ‘Storage’. Select the ‘Optical drive’ icon on Controller: IDE
Click Add and select the downloaded ‘Ubuntu 20.04’ iso file. Click Open and select Choose. Click Ok
Optionally, you can change the display settings to provide more video memory. Also, you can go to Network settings to change Network Adapter Attached to Bridged Adapter and Adapter type (under Advanced ) to a different option other than Intel PRO/1000 MT Desktop if you face considerably lower internet speed inside the VM.
Select the virtual machine and click ‘Start’. Click on Show. Wait for the disk checking to complete and proceed with the installation of ubuntu 20.04.
Click Install Ubuntu
Select the keyboard layout. Click on Continue. Select ‘Normal installation’ or ‘Minimal installation’. Optionally you can tick checkboxes for downloading updates and installing third-party software. Click Continue
Click on ‘Erase disk and Install Ubuntu’ or something else if you want to create multiple partitions. Click Install Now.
Select the geographical location and click ‘Continue’.
Provide your name, computer name, username, and password on the next screen. Click Continue
Wait for the installation to complete and reboot the Ubuntu virtual machine.
4. Setting up Microk8s on Ubuntu 20.04
Log into the virtual machine using the username and password provided earlier. Search and open terminal
Type the following commands to download the updated package information from all the configured sources and update existing packages to the latest version. Enter user password when prompted
$sudo apt update-y
Set the hostname
$sudo hostnamectl set-hostname Microk8s
Now install microk8s using the following command:
$sudo snap install microk8s--classic
If you want to install a specific version, select a channel like this
Now configure the firewall to allow communication from pods to the internet and between pods as follows:
$sudo ufw allow inon cni0&&sudo ufw allow out on cni0
$sudo ufw defaultallow routed
Now we need to add our current user to the group’ microk8s’ to be able to execute microk8s commands that require admin privilege.
Now we need to provide our current user access to the .kube directory under the user’s home directory. Use the su- $USER command to re-login as the same user. You can optionally log out and log back in manually and open the terminal. Provide a password when prompted
Use the following command to check the status of microk8s
Access Kubernetes and view nodes using kubectl:
$microk8s kubectl get nodes
We can set an alias if we want to use the kubectl command directly instead of ‘microk8s kubectl’. First, create a file (Edit the file if it already exists) .bash_aliases under the user’s home directory. Then, add the following line to the file and save the file. Press I to add to the file, and after adding the below line, press ESC +: wq to save and exit from the file
Re-enter the session or re-login for the alias to take effect.
$kubectl get nodes
5. Clustering Microk8s Instanced
Create additional Ubuntu machines in VirtualBox as required.
Assign different hostnames and static IP addresses on all the machines. Verify connectivity between the instances.
On our first instance, execute the following command:
Note down and copy the output of the previous command. On the new nodes, execute the microk8s join command:
Execute the following command on any node to verify that all the machines have joined the cluster:
$kubectl get nodes
6. Setup Dashboard on Microk8s
From the first Ubuntu VM (master node), execute the following command
$microk8s enable dns dashboard
We need to get a token as displayed after enabling the dashboard to access the dashboard. Use the following commands to get the token:
$token=$(kubectl-nkube-system get secret|grep default-token|cut-d" "-f1)
$kubectl-nkube-system describe secret$token
To get the IP address to access the dashboard, let’s check the Kubernetes dashboard service using the following command:
Note down the IP address against Kubernetes-dashboard and access it from a browser using https://<ip address>/When prompted with the security risk warning, scroll down and click on Accept the Risk and Continue
Enter the token obtained in the previous step
7. Setting up EFK Stack on Microk8s
Enable the Elasticsearch-Fluentd-Kibana logging and monitoring solution
$microk8s enable fluentd
Microk8s support using Kubernetes cluster using a single node (Linux). But it also supports clustering. So it is ideal to use three-plus nodes to ensure high availability.
MicroK8s uses Dqlite, a high-availability SQLite, as its datastore, a reliable datastore for storing the cluster state and providing high availability. Dqlite is a fast, embedded, persistent SQL database perfect for fault-tolerant Kubernetes clusters. In addition, it removes process overhead by embedding the database inside Kubernetes itself and reduces the overall memory footprint of the cluster.
Since Microk8s doesn’t require spinning up a virtual machine, we will have more resources to run our workloads and other applications. As a result, microK8s are ideal for less resource-consuming systems and IoT devices, given their smaller footprint.
9. About CloudThat
CloudThatis on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere to advance in their businesses. As a pioneer in the Cloud consulting realm, CloudThatis AWS (Amazon Web Services) Advanced Consulting Partner, AWS authorized Training Partner, Microsoft Gold Partner, and Winner of the Microsoft Asia Superstar Campaign for India: 2021. To get started, go through our Expert Advisorypage andManaged Services Packagethat isCloudThat‘sofferings. Then, you can quickly get in touch with our highly accomplished team of experts to carry out your migration needs.