
Setting Up a MicroK8s Kubernetes Cluster on Ubuntu 24
MicroK8s is Canonical’s lightweight Kubernetes distribution that gives you a full-featured Kubernetes cluster without the complexity of traditional setups. Unlike heavyweight solutions like kubeadm or managed services, MicroK8s runs locally on your Ubuntu machine, making it perfect for development, testing, edge computing, and IoT deployments. In this guide, you’ll learn how to set up a complete MicroK8s cluster on Ubuntu 24, configure essential add-ons, and troubleshoot common issues that’ll save you hours of head-scratching.
How MicroK8s Works Under the Hood
MicroK8s packages all Kubernetes components into a single snap package, eliminating the dependency hell that usually comes with Kubernetes installations. Instead of managing separate containers for the API server, etcd, kubelet, and other components, MicroK8s runs everything as systemd services within the snap’s confined environment.
The architecture is surprisingly elegant:
- Containerd handles container runtime (no Docker daemon needed)
- Dqlite replaces etcd for lightweight distributed state management
- Calico provides networking by default
- Built-in DNS with CoreDNS for service discovery
- Add-ons system for extending functionality without manual YAML wrestling
This design makes MicroK8s consume significantly fewer resources compared to traditional Kubernetes distributions while maintaining full API compatibility.
Prerequisites and System Requirements
Before diving in, let’s check if your Ubuntu 24 system is ready:
Component | Minimum | Recommended |
---|---|---|
RAM | 2GB | 4GB+ |
CPU | 2 cores | 4 cores |
Storage | 10GB | 20GB+ |
Network | Internet access | Static IP preferred |
Update your system and install snapd if it’s not already present:
sudo apt update && sudo apt upgrade -y
sudo apt install snapd -y
sudo systemctl enable --now snapd.socket
Step-by-Step MicroK8s Installation
Installing MicroK8s is refreshingly straightforward compared to the usual Kubernetes installation nightmare. Here’s the complete process:
Install MicroK8s
# Install the latest stable version
sudo snap install microk8s --classic
# Or install a specific version
sudo snap install microk8s --classic --channel=1.28/stable
Configure User Permissions
Add your user to the microk8s group to avoid typing sudo constantly:
sudo usermod -a -G microk8s $USER
sudo chown -f -R $USER ~/.kube
newgrp microk8s
Log out and back in, or use newgrp microk8s
to refresh group membership.
Verify Installation
# Check cluster status
microk8s status --wait-ready
# Get node information
microk8s kubectl get nodes
# Check system pods
microk8s kubectl get pods -A
You should see output similar to:
NAME STATUS ROLES AGE VERSION
ubuntu-desktop Ready <none> 2m v1.28.3
Essential Add-ons Configuration
MicroK8s shines with its add-on system. Enable the most useful ones for development:
# Enable DNS (essential for service discovery)
microk8s enable dns
# Enable dashboard for web UI
microk8s enable dashboard
# Enable storage class
microk8s enable hostpath-storage
# Enable ingress controller
microk8s enable ingress
# Enable registry for local image storage
microk8s enable registry
# Enable metrics server for resource monitoring
microk8s enable metrics-server
Check enabled add-ons:
microk8s status
Setting Up kubectl Access
You can use MicroK8s’s built-in kubectl or configure your system’s kubectl:
Option 1: Use microk8s kubectl directly
# Create an alias for convenience
echo 'alias kubectl="microk8s kubectl"' >> ~/.bashrc
source ~/.bashrc
Option 2: Configure system kubectl
# Install kubectl if not present
sudo apt install kubernetes-client -y
# Export MicroK8s config
microk8s config > ~/.kube/config
# Verify connection
kubectl get nodes
Real-World Examples and Use Cases
Let’s deploy a practical example to test your cluster:
Deploy a Sample Application
# Create a deployment
kubectl create deployment nginx --image=nginx:latest
# Expose the deployment
kubectl expose deployment nginx --port=80 --type=NodePort
# Check the service
kubectl get services
# Get the node port
kubectl get service nginx -o jsonpath='{.spec.ports[0].nodePort}'
Access your application at http://localhost:<nodeport>
.
Deploy with Ingress
Create a more realistic setup with ingress:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
spec:
replicas: 2
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: gcr.io/google-samples/hello-app:1.0
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: hello-world-service
spec:
selector:
app: hello-world
ports:
- port: 8080
targetPort: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hello-world-ingress
spec:
rules:
- host: hello.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hello-world-service
port:
number: 8080
Apply this configuration:
kubectl apply -f hello-world.yaml
# Add to /etc/hosts
echo "127.0.0.1 hello.local" | sudo tee -a /etc/hosts
# Test
curl http://hello.local
Multi-Node Cluster Setup
MicroK8s can create multi-node clusters easily. On your first node (already set up):
# Generate join token
microk8s add-node
On additional Ubuntu 24 nodes:
# Install MicroK8s
sudo snap install microk8s --classic
# Join the cluster (use token from previous command)
microk8s join <master-ip>:25000/<token>
Verify multi-node setup:
microk8s kubectl get nodes -o wide
Comparison with Other Kubernetes Distributions
Feature | MicroK8s | K3s | kubeadm | Kind |
---|---|---|---|---|
Installation complexity | Very Easy | Easy | Complex | Easy |
Resource usage | Low | Very Low | High | Medium |
Production ready | Yes | Yes | Yes | No |
Add-ons system | Excellent | Good | Manual | Limited |
Multi-node support | Yes | Yes | Yes | No |
Update mechanism | Snap channels | Binary replacement | Manual | Image updates |
Common Issues and Troubleshooting
MicroK8s Not Starting
If MicroK8s fails to start:
# Check snap services
sudo systemctl status snap.microk8s.*
# Restart MicroK8s
microk8s stop
microk8s start
# Check logs
journalctl -u snap.microk8s.daemon-cluster-agent.service -f
DNS Resolution Issues
Common DNS problems and fixes:
# Test DNS
kubectl run -it --rm debug --image=busybox --restart=Never -- nslookup kubernetes.default
# If DNS fails, restart CoreDNS
microk8s kubectl rollout restart deployment/coredns -n kube-system
Storage Issues
If pods can’t mount volumes:
# Check storage class
kubectl get storageclass
# Verify hostpath-storage is enabled
microk8s status
# Check available disk space
df -h
Firewall Configuration
Ubuntu’s UFW might block MicroK8s traffic:
# Allow MicroK8s ports
sudo ufw allow in on cni0
sudo ufw allow out on cni0
sudo ufw default allow routed
Performance Optimization and Best Practices
Resource Limits
Always set resource limits in production:
apiVersion: v1
kind: Pod
spec:
containers:
- name: app
image: nginx
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
Cluster Monitoring
Enable monitoring stack:
# Enable Prometheus and Grafana
microk8s enable prometheus
# Access Grafana
kubectl port-forward -n monitoring service/prometheus-grafana 3000:80
Backup and Maintenance
Regular backup practices:
# Backup cluster state
microk8s kubectl get all --all-namespaces -o yaml > cluster-backup.yaml
# Backup snap data
sudo snap save microk8s
Security Considerations
Harden your MicroK8s installation:
# Enable RBAC (usually enabled by default)
microk8s enable rbac
# Create non-admin user
kubectl create serviceaccount developer
kubectl create clusterrolebinding developer --clusterrole=view --serviceaccount=default:developer
# Use network policies
microk8s enable cilium
Advanced Configuration
Custom Add-ons
Create custom add-ons directory:
sudo mkdir -p /var/snap/microk8s/common/addons/custom
sudo chmod 755 /var/snap/microk8s/common/addons/custom
Configuration Override
Modify MicroK8s arguments:
# Edit kubelet arguments
sudo nano /var/snap/microk8s/current/args/kubelet
# Restart to apply changes
microk8s stop && microk8s start
MicroK8s on Ubuntu 24 provides an excellent balance of simplicity and functionality for Kubernetes development and edge deployments. Its snap-based distribution model ensures easy updates and consistent behavior across different environments. Whether you’re developing cloud-native applications, learning Kubernetes, or deploying edge workloads, MicroK8s offers a production-ready solution without the operational overhead of traditional Kubernetes distributions.
For more detailed information, check the official MicroK8s documentation and the Kubernetes documentation for deeper insights into cluster management and application deployment strategies.

This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.
This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.