MicroK8s is a powerful, lightweight and a reliable production-ready Kubernetes distribution. It is the smallest and fastest multi-node kubernetes and works on Linux, Windows and MacOS. MickroK8s can easily be installed with a single command and takes away the complexity associated with setting up Kubernetes. MicroK8s is great for offline development, prototyping, and testing.

Install MicroK8s on Linux Mint 20

We are going to use snap to install MicroK8s on Linux Mint 20. We should, however, remember that snap is disabled in Linux 20. To enable snap support on Linux Mint, follow the guide here:

How to install and use snap on Linux

Installing MicroK8s

Once snap is enable on Linux mint 20, run the below command to install MicroK8s

$ sudo snap install microk8s --classic

Add user to microk8s group

Your local user should be part of microk8s group for it to run commands without sudo.

sudo usermod -a -G microk8s $USER 
sudo chown -f -R $USER ~/.kube
sudo reboot

Managing Microk8s

The following steps show how to manage Microk8s service.

Start MicroK8s

To start MicroK8s, we run the below command

$ microk8s start

Check MicroK8s status

To check whether MicroK8s is running, we use the below command.

$ microk8s status
microk8s is running 
high-availability: no 
datastore master nodes:
Enable MicroK8s

Enable/ disable MicroK8s

To enable or disable MicroK8s, we use snap as shown:

$ sudo snap enable microk8s
microk8s enabled

$ sudo snap disable microk8s
microk8s disabled

MicroK8s List all nodes

To list nodes in MicroK8s, we use the following command:

$ microk8s kubectl get nodes
linux   Ready    <none>   3h32m   v1.19.0-34+1a52fbf0753680 

MicroK8s check services

Use the below commands to list MicroK8s services

$ microk8s kubectl get services
kubernetes   ClusterIP   <none>        443/TCP   23h

$ microk8s kubectl get all
pod/nginx   1/1     Running   0          70m
NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   <none>        443/TCP   23h

Adding a Node to Microk8s cluster

To create a cluster out of two or more already-running MicroK8s instances, use the microk8s add-node command. The MicroK8s instance on which this command is run will be the master of the cluster and will host the Kubernetes control plane.

$ microk8s add-node
From the node you wish to join to this cluster, run the following: 
microk8s join <server-ip>:25000/4788df710f77d3fc8d8c3a1e2386132a 

If the node you are adding is not reachable through the default interface you can use one of the following: 
microk8s join <server-ip>:25000/4788df710f77d3fc8d8c3a1e2386132a 
microk8s join 
microk8s join

Run the above instructions on the node to be added to the cluster. After that confirm if the host is added. The below output shows two nodes, the node was successfully added.

$ microk8s kubectl get no 
linux       Ready    <none>   3h32m   v1.19.0-34+1a52fbf0753680 
app2        Ready    <none>   86s     v1.19.0-34+1a52fbf0753680

Remove Node from Mikrok8s Cluster

To remove a node from the cluster, first run the leave command from the node to be removed

$ microk8s leave

On the remaining nodes run the command:

$ microk8s remove-node <node-ip/node.name>

Confirm it has been removed. From my output you can see that only one node is present.

$ microk8s kubectl get nodes
linux       Ready    <none>   3h32m   v1.19.0-34+1a52fbf0753680

Deploy Pods in Mikrok8s Cluster

Pods are the basic building blocks of K8s and can have one or more containers in them. When you instantiate a Pod, you’re prompted to specify the number of replica Pods it should have. We are going to deploy nginx as an example.

$ microk8s.kubectl run nginx --replicas 2 --image nginx

To check for any existing pod in your MicroK8s environment, run the command as shown below:

$ microk8s kubectl get pods
nginx   1/1     Running   0          4m57s

Enable MicroK8s Addons

The next steps show how to enable MicroK8s addons

Enable dashboard and DNS

Deploy dashboards and dns with the command below:

$ microk8s.enable dashboard dns
service/dashboard-metrics-scraper created 
deployment.apps/dashboard-metrics-scraper created 

If RBAC is not enabled access the dashboard using the default token retrieved with: 

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

In an RBAC enabled setup (microk8s enable RBAC) you need to create a user with restricted 
permissions as shown in: 
https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md 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

Retrieve the token that will be used in accessing dashboard by executing the ‘token =’ and microk8s lines. Ensure to keep the token in the above output.

$ token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
$ microk8s kubectl -n kube-system describe secret $token
Name:         default-token-s8xpj 
Namespace:    kube-system 
Labels:       <none> 
Annotations:  kubernetes.io/service-account.name: default 
             kubernetes.io/service-account.uid: 2bc1562d-4287-4d4d-946c-48213b2bb8ba 

Type:  kubernetes.io/service-account-token 

ca.crt:     1103 bytes 
namespace:  11 bytes 
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6ImU1b1FkT1k5U0hZeTlTdGxSY1ZWd1hGeHlrZm55SjNtOE9NZ3o5Ni1VTU0ifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0

Enable MicroK8s storage

Use the command:

$ microk8s.enable storage
serviceaccount/microk8s-hostpath created 
clusterrole.rbac.authorization.k8s.io/microk8s-hostpath created 
clusterrolebinding.rbac.authorization.k8s.io/microk8s-hostpath created 
Storage will be available soon

Enable MicroK8s Prometheus

Use the command as shown to enable MicroK8s Prometheus

$ microk8s.enable prometheus
service/prometheus-k8s created 
serviceaccount/prometheus-k8s created 
servicemonitor.monitoring.coreos.com/prometheus created 
servicemonitor.monitoring.coreos.com/kube-apiserver created 
servicemonitor.monitoring.coreos.com/coredns created 
servicemonitor.monitoring.coreos.com/kube-controller-manager created 
servicemonitor.monitoring.coreos.com/kube-scheduler created 
servicemonitor.monitoring.coreos.com/kubelet created 
The Prometheus operator is enabled (user/pass: admin/admin)

Set MicroK8s Prometheus and Grafana port forwarding to enable external access

$ microk8s kubectl port-forward -n monitoring service/prometheus-k8s --address 9090:9090
$ microk8s kubectl port-forward -n monitoring service/grafana --address 3000:3000

Ensure to allow the ports through the firewall if firewall is enabled

$ sudo firewall-cmd --add-port={9090/tcp,3000/tcp} --permanent
$ sudo firewall-cmd --reload

On your browser, open http://<your-server-ip>:9090 to access prometheus dashboard. You should see an output as below:

For Grafana, http://<your-server-ip>:3000. Output as shown

Enable MicroK8s registry

The command is as below:

$ microk8s.enable registry
service/registry created 
configmap/local-registry-hosting configured 
The registry is enabled

Check what is deployed for MickoK8s

To see everything deployed we use the command below:

$ microk8s.kubectl get all --all-namespaces
NAMESPACE     NAME                                             READY   STATUS    RESTARTS   AGE 
kube-system   pod/dashboard-metrics-scraper-6c4568dc68-llfgj   1/1     Running   2          22h 
kube-system   pod/metrics-server-8bbfb4bdb-7w9x2               1/1     Running   2          22h 
kube-system   pod/kubernetes-dashboard-7ffd448895-b52jk        1/1     Running   2          22h 
default       pod/nginx                                        1/1     Running   0          28m 
kube-system   pod/hostpath-provisioner-5c65fbdb4f-2knzl        1/1     Running   0          14m 
kube-system   pod/calico-node-znfw4                            1/1     Running   0          19h 
kube-system   pod/coredns-86f78bb79c-brg7h                     1/1     Running   2          22h 
kube-system   pod/calico-kube-controllers-847c8c99d-95jzq      1/1     Running   2          22h 
monitoring    pod/prometheus-adapter-557648f58c-zkbmj          1/1     Running   0          5m15s 
monitoring    pod/prometheus-operator-5b7946f4d6-87x4n         2/2     Running   0          5m57s 
monitoring    pod/grafana-7c9bc466d8-2nbn6                     1/1     Running   0          5m33s 
monitoring    pod/node-exporter-z42lk                          2/2     Running   0          5m26s 
monitoring    pod/kube-state-metrics-66b65b78bc-8gzxs          3/3     Running   0          5m30s 
monitoring    pod/alertmanager-main-0                          2/2     Running   0          4m57s 
monitoring    pod/prometheus-k8s-0                             3/3     Running   1          4m55s 

NAMESPACE     NAME                                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                        AGE 
default       service/kubernetes                  ClusterIP     <none>        443/TCP                        22h 
kube-system   service/metrics-server              ClusterIP   <none>        443/TCP                        22h 
kube-system   service/kubernetes-dashboard        ClusterIP   <none>        443/TCP                        22h 
kube-system   service/dashboard-metrics-scraper   ClusterIP   <none>        8000/TCP                       22h 
kube-system   service/kube-dns                    ClusterIP    <none>        53/UDP,53/TCP,9153/TCP         22h 
monitoring    service/prometheus-operator         ClusterIP   None             <none>        8443/TCP                       6m2s 
monitoring    service/alertmanager-main           ClusterIP   <none>        9093/TCP                       5m45s 
monitoring    service/grafana                     ClusterIP   <none>        3000/TCP                       5m35s 
monitoring    service/kube-state-metrics          ClusterIP   None             <none>        8443/TCP,9443/TCP              5m32s 
monitoring    service/node-exporter               ClusterIP   None             <none>        9100/TCP                       5m31s 
monitoring    service/prometheus-adapter          ClusterIP    <none>        443/TCP                        5m18s 
monitoring    service/prometheus-k8s              ClusterIP    <none>        9090/TCP                       5m10s 
monitoring    service/alertmanager-operated       ClusterIP   None             <none>        9093/TCP,9094/TCP,9094/UDP     5m 
kube-system   service/kubelet                     ClusterIP   None             <none>        10250/TCP,10255/TCP,4194/TCP   5m 
monitoring    service/prometheus-operated         ClusterIP   None             <none>        9090/TCP                       4m56s 

kube-system   daemonset.apps/calico-node     1         1         1       1            1           kubernetes.io/os=linux   22h 
monitoring    daemonset.apps/node-exporter   1         1         1       1            1           kubernetes.io/os=linux   5m31s 

NAMESPACE     NAME                                        READY   UP-TO-DATE   AVAILABLE   AGE 
kube-system   deployment.apps/dashboard-metrics-scraper   1/1     1            1           22h 
kube-system   deployment.apps/metrics-server              1/1     1            1           22h 
kube-system   deployment.apps/kubernetes-dashboard        1/1     1            1           22h 
kube-system   deployment.apps/hostpath-provisioner        1/1     1            1           14m 
kube-system   deployment.apps/coredns                     1/1     1            1           22h 
kube-system   deployment.apps/calico-kube-controllers     1/1     1            1           22h 
monitoring    deployment.apps/prometheus-adapter          1/1     1            1           5m19s 
monitoring    deployment.apps/prometheus-operator         1/1     1            1           6m4s 
monitoring    deployment.apps/grafana                     1/1     1            1           5m36s 
monitoring    deployment.apps/kube-state-metrics          1/1     1            1           5m33s 

NAMESPACE     NAME                                                   DESIRED   CURRENT   READY   AGE 
kube-system   replicaset.apps/dashboard-metrics-scraper-6c4568dc68   1         1         1       22h 
kube-system   replicaset.apps/metrics-server-8bbfb4bdb               1         1         1       22h 
kube-system   replicaset.apps/kubernetes-dashboard-7ffd448895        1         1         1       22h 
kube-system   replicaset.apps/hostpath-provisioner-5c65fbdb4f        1         1         1       14m 
kube-system   replicaset.apps/coredns-86f78bb79c                     1         1         1       22h 
kube-system   replicaset.apps/calico-kube-controllers-847c8c99d      1         1         1       22h 
monitoring    replicaset.apps/prometheus-adapter-557648f58c          1         1         1       5m20s 
monitoring    replicaset.apps/prometheus-operator-5b7946f4d6         1         1         1       6m4s 
monitoring    replicaset.apps/grafana-7c9bc466d8                     1         1         1       5m37s 
monitoring    replicaset.apps/kube-state-metrics-66b65b78bc          1         1         1       5m33s 

NAMESPACE    NAME                                 READY   AGE 
monitoring   statefulset.apps/alertmanager-main   1/1     5m1s 
monitoring   statefulset.apps/prometheus-k8s      1/1     4m57s

From the above output you can the different IPs for accessing various services dashboards, including kubernetes dashboard and metrics dashboard. Alternatively, run the below command to get various dashboards urls

$ microk8s.kubectl cluster-info
Kubernetes master is running at 
Metrics-server is running at 
CoreDNS is running at

Or this other command

$ kubectl get services -n kube-system      
NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                        AGE 
metrics-server              ClusterIP   <none>        443/TCP                        22h 
kubernetes-dashboard        ClusterIP   <none>        443/TCP                        22h 
dashboard-metrics-scraper   ClusterIP   <none>        8000/TCP                       22h 
kube-dns                    ClusterIP    <none>        53/UDP,53/TCP,9153/TCP         22h 
kubelet                     ClusterIP   None             <none>        10250/TCP,10255/TCP,4194/TCP   23m

Show MicroK8s config

The below command displays MicroK8s configs

$ microk8s.config
apiVersion: v1 
- cluster: 
   server: https://<server-ip>:16443 
 name: microk8s-cluster 
- context: 
   cluster: microk8s-cluster 
   user: admin 
 name: microk8s 
current-context: microk8s 
kind: Config 
preferences: {} 
- name: admin 
   token: aWdjSHJWbEs4U0VaZmN5dGY1VjBveE9rNnU5ejE2SEhzbStLV1VFZ3Faaz0K

Kubernetes Learning materials:

Kubernetes for the Absolute Beginners – Hands-on

Certified Kubernetes Administrator (CKA) with Practice Tests

Docker and Kubernetes: The Complete Guide

Learn DevOps: The Complete Kubernetes Course

You have successfully set up MicroK8s on Linux Mint 20. Enjoy using it! Check below more captivating Linux guides


Please enter your comment!
Please enter your name here