Setup a MicroK8s Kubernetes cluster
Categories:
4 minute read
Overview
This project will setup a MicroK8s kubernetes cluster on three Ubuntu Server 20.04 LTS servers. Two are Raspberry Pi and one is running standard hardware.
Install Ubuntu Server 22.04 on standard hardware
Follow the referenced guide from Canonical to setup Ubuntu 22.04 on standard hardware
Install Ubuntu Server 22.04 on Raspberry Pi
Follow the referenced guide from Canonical to setup Ubuntu 22.04 on Raspberry Pi hardware
Configure Ubuntu Server base settings
Before installing any software or services on Ubuntu it’s good practice to setup the base server first.
Update Ubuntu to the latest release
sudo apt-get update && sudo apt-get upgrade
Enable UFW (firewall) Ubuntu 22.04 servers can use the UFW firewall to ensure only connections to certain services are allowed.
ufw app list
Applications can register their profiles with UFW upon installation. These profiles allow UFW to manage these applications by name. OpenSSH, the service that allows you to connect to your server, has a profile registered with UFW.
You can examine the list of installed UFW profiles by typing:
ufw app list
Output
Available applications:
OpenSSH
You will need to make sure that the firewall allows SSH connections so that you can log into your server next time. Allow these connections by typing:
ufw allow OpenSSH
Now enable the firewall by typing:
ufw enable
Type y and press ENTER to proceed. You can see that SSH connections are still allowed by typing:
ufw status
Output
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
The firewall is currently blocking all connections except for SSH. If you install and configure additional services, you will need to adjust the firewall settings to allow the new traffic into your server.
Install MicroK8s
Logon to the main server using SSH and use the following snap
command to install MicroK8s
.
sudo snap install microk8s --classic
If installed successfully then you’ll receive a message similar to this. Notice the version installed was the latest stable release.
$ microk8s (1.28/stable) v1.28.3 from Canonical✓ installed
Running this command will show you the status of MicroK8s and which addons are enabled/disabled.
$ sudo microk8s status
microk8s is running
high-availability: no
datastore master nodes: 127.0.0.1:19001
datastore standby nodes: none
addons:
enabled:
dns # (core) CoreDNS
ha-cluster # (core) Configure high availability on the current node
helm # (core) Helm - the package manager for Kubernetes
helm3 # (core) Helm 3 - the package manager for Kubernetes
disabled:
cert-manager # (core) Cloud native certificate management
cis-hardening # (core) Apply CIS K8s hardening
community # (core) The community addons repository
dashboard # (core) The Kubernetes dashboard
gpu # (core) Automatic enablement of Nvidia CUDA
host-access # (core) Allow Pods connecting to Host services smoothly
hostpath-storage # (core) Storage class; allocates storage from host directory
ingress # (core) Ingress controller for external access
kube-ovn # (core) An advanced network fabric for Kubernetes
mayastor # (core) OpenEBS MayaStor
metallb # (core) Loadbalancer for your Kubernetes cluster
metrics-server # (core) K8s Metrics Server for API access to service metrics
minio # (core) MinIO object storage
observability # (core) A lightweight observability stack for logs, traces and metrics
prometheus # (core) Prometheus operator for monitoring and logging
rbac # (core) Role-Based Access Control for authorisation
registry # (core) Private image registry exposed on localhost:32000
rook-ceph # (core) Distributed Ceph storage using Rook
storage # (core) Alias to hostpath-storage add-on, deprecated
Configure kubectl
MicroK8s come pre-bundled with its version kubectl and can execute the native Kubernetes commands to inspect and work with the cluster.
sudo microk8s kubectl get all -n kube-system
To avoid using microk8s as a prefix while running kubectl commands, you can add an alias if you don’t have an existing installation of kubectl using the following command.
alias kubectl='sudo microk8s kubectl'
Now, you can execute kubectl commands directly without the prefix.
kubectl get nodes
MicroK8s Dashboard
Install the dashboard.
microk8s enable dashboard ingress
Viewing the Dashboard view it by first starting a port-forward:
microk8s kubectl port-forward -n kube-system service/kubernetes-dashboard 10443:443
View the dashboard using the URL https://localhost:10443. To log in, we need a token or the full kubeconfig:
Generate a token
$ microk8s kubectl create token default
Generate kubeconfig
$ microk8s config Copy Note that the cluster uses a self-signed certificate, which will cause web browser warnings.
References
How to install Ubuntu Server on your Raspberry Pi
How to build a Raspberry Pi Kubernetes cluster using MicroK8s
Initial Server Setup with Ubuntu 22.04
How to Setup a MicroK8s Kubernetes Cluster on Ubuntu 22.04
UFW Essentials: Common Firewall Rules and Commands
Deploy and Access the Kubernetes Dashboard