AWS, Azure, Cloud Computing, Kubernetes

8 Mins Read

Kubernetes Cluster Using Microk8s On Ubuntu

TABLE OF CONTENT

1. Introduction
2. Setting Up VirtualBox
3. Set-Up Ubuntu 20.04 on VirtualBox
4. Setting up Microk8s on Ubuntu 20.04
5. Clustering Microk8s Instances
6. Setup Dashboard on Microk8s
7. Setting up EFK Stack on Microk8s
8. Conclusion
9. About CloudThat

1. Introduction

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.

Learn more about 8 Key Attributes of Modern Cloud-Native Architecture

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.

If you are new to Kubernetes, here is A Beginner’s Guide To Kubernetes With Real-Time Example. 

2. Setting Up VirtualBox

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.

  1. 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.
    Ubuntu installation
  2. Follow the on-screen instructions to complete the installation. Provide appropriate access permissions. Click finish and open Oracle VM VirtualBox Manager
    Ubuntu installation

3. Set-Up Ubuntu 20.04 on VirtualBox

  1. Visit the Ubuntu downloads page from a browser: https://ubuntu.com/download/desktop and click ‘Download.’ Save the file
    Ubuntu installation
  2. Open Oracle VM VirtualBox Manager and Click on ‘New’
    Ubuntu installation
  3. 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’
  4. 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.
  5. Select ‘Create a virtual hard disk now. Click Create
    Ubuntu installation
  6. Select the default Virtual Hard disk file type. Other options are also supported. Click Next
    Ubuntu installation
  7. Select ‘Dynamically allocated’ for the storage option for the virtual hard disk. Click Next
  8. Select the file location and file size. Ubuntu recommends 25 GB of free hard drive space. Click ‘Create’.
    Ubuntu installation
  9. From the ‘Oracle VM VirtualBox Manager’ main window, select the configured VM (Ubuntu20.04 in our case). Click ‘Settings’
    Ubuntu installation
  10. Click on ‘Storage’. Select the ‘Optical drive’ icon on Controller: IDEUbuntu installation
  11. Click Add and select the downloaded ‘Ubuntu 20.04’ iso file. Click Open and select Choose. Click Ok
    Ubuntu installation
    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.

    Ubuntu installation
    Ubuntu installation
    Ubuntu installation
    Ubuntu installation
  12. 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.
    Ubuntu installation
  13. Click Install Ubuntu
    Ubuntu installation
  14. 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
    Ubuntu installation
    Ubuntu installation
  15. Click on ‘Erase disk and Install Ubuntu’ or something else if you want to create multiple partitions. Click Install Now.
    Ubuntu installation
  16. Click Continue
    Ubuntu installation
  17. Select the geographical location and click ‘Continue’.
    Ubuntu installation
  18. Provide your name, computer name, username, and password on the next screen. Click Continue
    Ubuntu installation
    Wait for the installation to complete and reboot the Ubuntu virtual machine.

4. Setting up Microk8s on Ubuntu 20.04

  1. Log into the virtual machine using the username and password provided earlier. Search and open terminal
  2. 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

    Microk8s on Ubuntu
  3. Set the hostname

    Microk8s on Ubuntu
  4. Now install microk8s using the following command:

    If you want to install a specific version, select a channel like this

    Microk8s on Ubuntu
  5. Now configure the firewall to allow communication from pods to the internet and between pods as follows:

    Microk8s on Ubuntu
  6. Now we need to add our current user to the group’ microk8s’ to be able to execute microk8s commands that require admin privilege.

    Microk8s on Ubuntu
  7. 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

    Microk8s on Ubuntu
  8. Use the following command to check the status of microk8s

    Microk8s on Ubuntu
  9. Access Kubernetes and view nodes using kubectl:

    Microk8s on Ubuntu
  10. 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

    Microk8s on Ubuntu
    Microk8s on Ubuntu
  11. Re-enter the session or re-login for the alias to take effect.

Microk8s on Ubuntu

5. Clustering Microk8s Instanced

  1. Create additional Ubuntu machines in VirtualBox as required.
  2. Assign different hostnames and static IP addresses on all the machines. Verify connectivity between the instances.
  3. On our first instance, execute the following command:
  4. Note down and copy the output of the previous command. On the new nodes, execute the microk8s join command:
  5. Execute the following command on any node to verify that all the machines have joined the cluster:

Microk8s on Ubuntu

6. Setup Dashboard on Microk8s

  1. From the first Ubuntu VM (master node), execute the following command

    Microk8s on Ubuntu
    Microk8s on Ubuntu
  2. We need to get a token as displayed after enabling the dashboard to access the dashboard. Use the following commands to get the token:

    Microk8s on Ubuntu
    Microk8s on Ubuntu
  3. To get the IP address to access the dashboard, let’s check the Kubernetes dashboard service using the following command:
  4. 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
    Micro8ks on Ubuntu
    Micro8ks on Ubuntu
  5. Enter the token obtained in the previous step
    Micro8ks on Ubuntu

7. Setting up EFK Stack on Microk8s

Enable the Elasticsearch-Fluentd-Kibana logging and monitoring solution

Micro8ks on Ubuntu

8. Conclusion:

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

CloudThat is 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, CloudThat is 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 Advisory page and Managed Services Package that is CloudThat‘s offerings. Then, you can quickly get in touch with our highly accomplished team of experts to carry out your migration needs.

Voiced by Amazon Polly

WRITTEN BY Anees A

SHARE

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!