MicroK8s is Canonical’s single-package fully conformant lightweight Kubernetes [Link]. It is a 100% compatible Kubernetes orchestrator that can be deployed with a single click on Ubuntu and many other distributions via Snap.

Compared to MiniKube [Link] and K3s [Link], MicroK8s is a minimal production-grade Kubernetes with a low operational overhead (low-ops).

Kubernetes was built by Google to meet Google-scale demands, which is why it is widely known to be complex to deploy and manage. This leads many companies to opt for managed services such as EKS (AWS), GKE (GCP), or AKS (Azure), all of which come with an associated cost.

Most container orchestration use cases are straightforward, and MicroK8s handles them well.


INSTALLATION

sudo snap install microk8s --classic
microk8s.inspect

That is it! Even kubectl is included in the package.

To use MicroK8s without sudo, add your username to the microk8s group.

sudo usermod -a -G microk8s userName

Stopping and starting the MicroK8s daemon.

microk8s.stop
microk8s.start

BASIC COMMANDS

sudo microk8s kubectl get nodes
sudo microk8s kubectl get services

For standard Kubernetes commands and use cases, see this reference post [Link].


EXTENDED FEATURES

Enabling popular addons.

sudo microk8s enable dashboard
sudo microk8s enable registry
sudo microk8s enable ingress
sudo microk8s enable dns
sudo microk8s enable gpu
sudo microk8s enable ha-cluster
sudo microk8s enable cert-manager
sudo microk8s enable prometheus
sudo microk8s enable community
sudo microk8s enable istio

ACCESSING THE DASHBOARD

sudo microk8s enable dashboard
sudo microk8s kubectl create token default

By default, the token expires in 1 hour. To extend it, optionally specify a namespace and duration.

sudo microk8s kubectl create token default --namespace=namespace --duration=24h

Expose the dashboard.

sudo microk8s kubectl port-forward -n kube-system service/kubernetes-dashboard 10443:443

Navigate to https://127.0.0.1:10443 and paste the generated token.

Note: This dashboard is not specific to MicroK8s. It is a standard Kubernetes module and is outside the scope of this post. See the Dashboard walkthrough post [Link].


RUNNING MICROK8S IN PROXMOX LXC

Create a new CT and uncheck the “unprivileged” option.

Before starting the CT for the first time, open a shell on the host and edit the CT configuration file.

nano /etc/pve/nodes/proxmox/lxc/100.conf
lxc.apparmor.profile: unconfined
lxc.cap.drop:
lxc.mount.auto: proc:rw sys:rw
lxc.mount.entry: /dev/fuse dev/fuse none bind,create=file 0 0
lxc.mount.entry: /sys/kernel/security sys/kernel/security none bind,create=file 0 0

Start the CT and add the following line to the root user’s crontab.

crontab -e
@reboot ln -s /dev/console /dev/kmsg

Set up the environment.

ln -s /dev/console /dev/kmsg
apt update && apt upgrade -y
apt install snapd squashfuse fuse -y
reboot

Now install MicroK8s.

snap install microk8s --classic
apparmor_parser --add /var/lib/snapd/apparmor/profiles/snap.microk8s.*
microk8s.inspect
reboot

After rebooting, verify everything is working as expected.

microk8s.inspect
microk8s kubectl get nodes
microk8s kubectl get services

BONUS

Auto-start MicroK8s and its dashboard on startup.

nano /etc/systemd/system/kubectl.service
[Unit]
Description=Port forward for Kubernetes Dashboard
After=network.target

[Service]
ExecStart=/root/microk8s.sh
Restart=always
User=root

[Install]
WantedBy=multi-user.target
nano /root/microk8s.sh
chmod +x /root/microk8s.sh
#!/bin/bash
apparmor_parser --add /var/lib/snapd/apparmor/profiles/snap.microk8s.*
microk8s.start
sleep 30
/snap/bin/microk8s kubectl port-forward -n kube-system service/kubernetes-dashboard 10443:443 --address 0.0.0.0
systemctl daemon-reload
systemctl enable kubectl --now

OTHER POSTS

Minikube on Ubuntu 22.04 [Link].

K3s on Ubuntu 22.04 [Link].

K8s Persistent Volumes [Link].

K8s Cheat Sheet [Link].

K8s Dashboard [Link].