How to set up a local Kubernetes instance with MicroK8s on Ubuntu

0


DevOps has dramatically changed the way software engineers and developers develop and deploy applications. One of the technologies at the heart of this revolution is Kubernetes.

Let’s see how to install a local instance of Kubernetes on Ubuntu using MicroK8s (MicroKates). With this setup in place, you can easily host container applications in a secure, reliable, and highly scalable manner.

Why use MicroK8s?

Kubernetes is an open source platform that helps streamline DevOps operations by automating the deployment, scaling, and management of containerized applications. Kubernetes is also known as K8s, the name derived from counting the eight letters between k and s on behalf of Kubernetes. Think of MicroK8s as a Micro Kubernetes instance.

Most production-grade public and private cloud environments that run Ubuntu use Charmed Kubernetes to manage containerized applications. The challenge with Charmed Kubernetes, however, is that it is resource intensive and requires a good level of knowledge to be properly configured.

This is where MicroK8s comes in. MicroK8s is a small and lightweight upstream Kubernetes that can run on a developer’s PC, IoT device, or edge devices natively without the need for a virtual machine. MicroK8s is cross-platform and can run on both Intel and ARM architectures.

MicroK8s gives you one of the best ways to get to know Kubernetes, with minimal friction. It is a Cloud Native Computing Foundation (CNCF) upstream certified Kubernetes, which ensures that Kubernetes implementations are compliant and interoperable to specified industry standards.

VIDEO OF THE DAY MAKEUSE

Step 1: Installing MicroK8s on Ubuntu

You can easily install MicroK8s on Ubuntu using the snap command.

sudo snap install microk8s --classic

Alternatively, you can install MicroK8s from the GUI using the Ubuntu Software Center. Just search microk8s then click on the To install button.



installing microk8s from the Ubuntu software center

Step 2: Configure your firewall for MicroK8

To ensure transparent communication between Pods and with the Internet, you must enable inbound and outbound communication on the container network interface of your firewall.

A pod is Kubernetes’ smallest deployable compute; it can be a single or a group of containers with shared storage and network resources, etc.

sudo ufw allow in on cni0 && sudo ufw allow out on cni0

Then run the following command:

sudo ufw default allow routed

Learn moreHow to configure Ubuntu firewall with UFW

Step 3: Adding your user to the MicroK8s group

For now, you will need to use the sudo to run most MicroK8s commands. While this is a good security measure on a production server, it may not be necessary on a development machine.

Add your user to the MicroK8s group to avoid using sudo.

sudo usermod -aG microk8s $USER

Also, make your current user the owner of the ~ / .kube phone book.

sudo chown -f -R $USER ~/.kube

For the changes to take effect, reload the user groups by running the following command:

newgrp microk8s

Learn more: How to manage user groups on Linux

Step 4: Activate Important Add-ons

By default, MicroK8s contains the bare minimum to achieve a minimum footprint on Edge and IoT devices. However, there are a few important add-ons you can install to manage MicroK8s services. Enable DNS, dashboard and storage add-ons with the microk8s order.

microk8s enable dns dashboard storage

The DNS add-on may be required by other services, so it is recommended that you always enable it.

The dashboard add-on gives you a graphical overview of the services in MicroK8s; you can also use it to manage services.

You can view a list of available MicroK8 add-ons by running the command:

microk8s status

Step 5: Viewing the MicroK8s Dashboard

Now that you’ve enabled the dashboard add-on, you can easily access the MicroK8s dashboard from your web browser.

First, you need the IP address of the dashboard pod. You can get it by running the command:

microk8s kubectl get all --all-namespaces


output listing microk8s namespaces

From the output of the above command, you will notice that the kubernetes-dashboard The service is running on IP address 10.152.183.35 and listening on TCP port 443. Note that this IP address may be different from the one used by your Dashboard service because it is randomly generated.

In your browser, navigate to the specified IP address. In this case it will be https://10.152.183.35:443. Make sure you point to the correct URL.

For security reasons, the Kubernetes dashboard will ask you for authentication details to sign in. You can access the default dashboard token by running the following command. Then copy the kubernetes.io/service-account-token presented and paste it into the token entry.

token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
microk8s kubectl -n kube-system describe secret $token


kubernetes dashboard authentication

The dashboard gives you an overview of workloads, services, configuration, clusters, and more. by MicroK8.



kubernetes dashboard on ubuntu linux

Step 6: Creating a service with MicroK8s

To see the MicroK8s in action, let’s create a microbot service deployment that contains two pods. Create the pod using the kubectl order:

microk8s kubectl create deployment microbot --image=dontrebootme/microbot:v1

Scale the microbot pod using the command below.

microk8s kubectl scale deployment microbot --replicas=2

Create a service to expose the deployment of the microbot.

microk8s kubectl expose deployment microbot --type=NodePort --port=80 --name=microbot-service

We have now deployed two microbot pods under the name service / service-microbot. You can view the details of the microbot service and other services by running the following command:

microk8s kubectl get all --all-namespaces


command output showing microk8s services

You will notice that the microbot service is running on a NodePort, so you can access it through your PC browser. In this case, the service is running on the randomly generated port 30353.

In your browser, navigate to the URL http: // localhost: 30353, or 30353 is the port number listed in the output above. Make sure you are using the correct port number.



microk8s microbot service running in browser

Kubernetes vs Docker: which one to choose?

This guide looked at how to install a minimal Kubernetes footprint locally on your PC or edge device. Kubernetes is part of the workflow of many developers and is widely used to deploy containerized applications on a large scale in production.


Kubernetes is used to easily manage or orchestrate a group of containers, for example Docker containers. Stand-alone Docker, on the other hand, is primarily used to manage single containers. Choosing to use Docker or Kubernetes will depend on the skills of your team and the size of the software to be deployed in production.


Shipping port

Which container system should you use: Kubernetes or Docker?

Choosing a container system for is a simple choice between two systems. Should you choose Kubernetes or Docker?

Read more


About the Author


Share.

Comments are closed.