MicroK8s is a lightweight, upstream, production-grade, conformant Kubernetes that can run anywhere, from a developer workstation to edge and IoT appliances. It can be used as a single-node or multi-node. If used as a multi-node, MicroK8s becomes highly available automatically.

MicroK8s is a cloud-native infrastructure that lets developers focus on production levels like adding value to the business. It is a Zero-Ops Kubernetes, just set it up and let it run. It will then perform over-the-air updates and security fixes needed without any administration.

MicroK8s is easy to install, requires no configuration as it sets the defaults and it can be run on any operating system. You can choose to configure the defaults but most people do not as they simply ‘work’.

Some of the use cases include;

  • Edge
  • Building CI/CD pipelines
  • Artificial Intelligence
  • Machine Learning 
  • IoT

This guide will show you how to install MicroK8s on KDE Neon|Kubuntu.

Install MicroK8s on KDE Neon / Kubuntu

First, update your package list using the following command.

###KDE Neon###
sudo apt update
sudo pkcon update -y

### Kubuntu ###
sudo apt update && sudo apt upgrade -y

Install snap first on your KDE Neon / Kubuntu system.

sudo apt install snapd

Install microK8s using snap command line tool

sudo snap install microk8s --classic

Sample installation output

microk8s (1.23/stable) v1.23.4 from Canonical✓ installed

Configure the firewall to allow pod-to-pod and pod-to-internet communication

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

To add a User to MicroK8s Group, use the following command.

sudo usermod -a -G microk8s $USER

This will allow you to run the commands without appending ‘sudo‘ at the beginning of each command

Use this command for the group change to take place without login out.

newgrp microk8s

Check status while Kubernetes starts

microk8s status --wait-ready

Sample Output

microk8s is running
high-availability: no
  datastore master nodes: 127.0.0.1:19001
  datastore standby nodes: none
addons:
  enabled:
    ha-cluster           # Configure high availability on the current node
  disabled:
    ambassador           # Ambassador API Gateway and Ingress

Enable addons like dns and dashboard.

$ microk8s enable dns dashboard
Enabling DNS
Applying manifest
serviceaccount/coredns created
configmap/coredns created
deployment.apps/coredns created
service/kube-dns created
clusterrole.rbac.authorization.k8s.io/coredns created
clusterrolebinding.rbac.authorization.k8s.io/coredns created
Restarting kubelet
DNS is enabled
Enabling Kubernetes Dashboard
Enabling Metrics-Server
serviceaccount/metrics-server created

Check deployment progress using the following command

$ microk8s kubectl get all --all-namespaces
NAMESPACE     NAME                                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default       service/kubernetes                  ClusterIP   10.152.183.1     <none>        443/TCP                  9m51s
kube-system   service/kube-dns                    ClusterIP   10.152.183.10    <none>        53/UDP,53/TCP,9153/TCP   2m3s
kube-system   service/metrics-server              ClusterIP   10.152.183.98    <none>        443/TCP                  109s
kube-system   service/kubernetes-dashboard        ClusterIP   10.152.183.137   <none>        443/TCP                  104s
kube-system   service/dashboard-metrics-scraper   ClusterIP   10.152.183.104   <none>        8000/TCP                 103s

NAMESPACE     NAME                         DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
kube-system   daemonset.apps/calico-node   1         1         1       1            1           kubernetes.io/os=linux   9m47s

Access MicroK8s Kubernetes Dashboard

To access the Kubernetes dashboard, use the Cluster IP and listening port assigned. This is done randomly. As we can see above the Kubernetes dashboard is assigned a cluster IP of 10.152.183.137 and a Listening port of 443. If I head over to my browser and put https://10.152.183.137:443 I will get to see the dashboard.

But first, to access it, you must put a token retrieved by the following command for security reasons.

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

You copy the token and paste it on the login page.

Then once logged in, you can view the dashboard as shown below.

Access Kubernetes Dashboard using NodePort

Patch the Service to listen use NodePort

microk8s kubectl patch svc kubernetes-dashboard --type='json' -p '[{"op":"replace","path":"/spec/type","value":"NodePort"}]' -n kube-system

Confirm Port assigned

$ microk8s kubectl get svc -n kube-system
NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
kube-dns                    ClusterIP   10.152.183.10    <none>        53/UDP,53/TCP,9153/TCP   7m15s
metrics-server              ClusterIP   10.152.183.203   <none>        443/TCP                  7m3s
dashboard-metrics-scraper   ClusterIP   10.152.183.75    <none>        8000/TCP                 6m59s
kubernetes-dashboard        NodePort    10.152.183.95    <none>        443:32394/TCP            6m59s

You can the access Dashboard on https://micork8s-server-ip:nodeport

Get Token and use it to authenticate

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

Hosting Service on Kubernetes on KDE Neon|Kubuntu

1. Hosting Nginx Service (example)

We can rename the command mickrok8s kubectl to mkctl using the following command. which going onwards is what we will use to create a deployment.

alias mkctl="microk8s kubectl"

To host a service, start by creating a deployment. In my case, I will create Nginx deployment by using the following command.

$ mkctl create deployment nginx --image nginx
deployment.apps/nginx created

To expose our deployment we create a service using the following command.

mkctl expose deployment nginx --port 80 --target-port 80 --selector app=nginx --type ClusterIP --name nginx

Sample output

service/nginx exposed

View the using the following command.

$ mkctl get all --all-namespaces
NAMESPACE     NAME                                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default       service/kubernetes                  ClusterIP   10.152.183.1     <none>        443/TCP                  40m
kube-system   service/kube-dns                    ClusterIP   10.152.183.10    <none>        53/UDP,53/TCP,9153/TCP   32m
kube-system   service/metrics-server              ClusterIP   10.152.183.98    <none>        443/TCP                  32m
kube-system   service/kubernetes-dashboard        ClusterIP   10.152.183.137   <none>        443/TCP                  32m
kube-system   service/dashboard-metrics-scraper   ClusterIP   10.152.183.104   <none>        8000/TCP                 32m
default       service/nginx                       ClusterIP   10.152.183.107   <none>        80/TCP                   11m

You can see the service has been created and you can access it via web browser by using HTTP:10.152.183.107:80 and you will get the following page opened.

2. Configuring Prometheus service

Enable addons for Prometheus using the following command.

microk8s enable prometheus dashboard dns

View the services using

microk8s kubectl get services -n monitoring

Sample Output

NAME                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
prometheus-operator     ClusterIP   None             <none>        8443/TCP                     111s
alertmanager-main       ClusterIP   10.152.183.13    <none>        9093/TCP                     106s
blackbox-exporter       ClusterIP   10.152.183.227   <none>        9115/TCP,19115/TCP           106s
grafana                 ClusterIP   10.152.183.29    <none>        3000/TCP                     104s
kube-state-metrics      ClusterIP   None             <none>        8443/TCP,9443/TCP            104s
node-exporter           ClusterIP   None             <none>        9100/TCP                     104s
prometheus-adapter      ClusterIP   10.152.183.170   <none>        443/TCP                      103s
prometheus-k8s          ClusterIP   10.152.183.211   <none>        9090/TCP                     103s
alertmanager-operated   ClusterIP   None             <none>        9093/TCP,9094/TCP,9094/UDP   0s
prometheus-operated     ClusterIP   None             <none>        9090/TCP                     0s

Get pods in the monitoring namespace.

$ microk8s kubectl get pods -n monitoring
NAME                                   READY   STATUS    RESTARTS      AGE
node-exporter-p8dt7                    2/2     Running   0             69s
prometheus-operator-667757c7b9-mw9x5   2/2     Running   0             69s
kube-state-metrics-bbd47c478-q5bjs     3/3     Running   0             69s
prometheus-adapter-5b7fb5c557-j9mdd    1/1     Running   0             69s
prometheus-adapter-5b7fb5c557-krv49    1/1     Running   0             69s
grafana-59f6895cb8-zzdrc               1/1     Running   0             69s
blackbox-exporter-5c4d9867d6-4kxz8     3/3     Running   0             69s
alertmanager-main-0                    2/2     Running   0             56s
prometheus-k8s-0                       2/2     Running   1 (33s ago)   56s

Set port forwarding to enable external access

microk8s kubectl port-forward -n monitoring service/prometheus-k8s --address 0.0.0.0 9090:9090

Sample Output:

Forwarding from 0.0.0.0:9090 -> 9090

Now access it via the browser on I will use the cluster IP and its listening port. HTTP://10.152.183.211:9090 . Then it will show the Prometheus UI.

Other microk8s management commands

To reset MicroK8s use the following command.

microk8s reset

To stop and start the service use the following command.

microk8s stop
microk8s start

To check the status of the service use the command below.

microk8s status

To disable and enable microK8s

snap disable microk8s
snap enable microk8s

To show Configuration

microk8s config

Conclusion

From this guide, you have gotten an introduction to MicroK8s service. You have learned how to install MicroK8s on KDE Neon||Kubuntu. You have also learned how to host a service specifically Nginx on Kubernetes by creating and exposing the service. We have also enabled Prometheus Login. Remember to add the user to the MicroK8s group to run commands without appending sudo.

More guides:

LEAVE A REPLY

Please enter your comment!
Please enter your name here