Part 2: Installing MicroK8s on Ubuntu 24.04+
๐ What You'll Learn ## โ Why MicroK8s? ## ๐ฆ Install MicroK8s ### Update your system ### Install MicroK8s via Snap ### Verify installation ## ๐ฅ Add Your User to the MicroK8s Group ## ๐ก Pro Tip: Create a Kubectl Alias ## ๐ง Enable Essential Kubernetes Add-ons ### Recommended add-ons ### Optional but useful add-ons ### Check status ## ๐งช Test Your Kubernetes Cluster ### Check node status ### Check system pods ## ๐ณ Deploy a Test NGINX App ### Create deployment ### Expose the deployment ### Get service details ### Access the application ## ๐ Ensuring MicroK8s Auto-Starts on Boot ### โ๏ธ Step 1: Check Service Status ### โ๏ธ Step 2: Enable Autostart (If Needed) ### โ๏ธ Step 3: Reboot & Validate ### Verify your NGINX app survived the reboot ## ๐ ๏ธ Troubleshooting Tools ### Check cluster health (Generates a report) ### Restart MicroK8s ### Check specific logs ## ๐ Summary Checklist ## ๐งน Clean Up Test Deployment (Optional) ## ๐ฏ Final Thoughts ## ๐ Previous Guide ## ๐ What's Next? MicroK8s is a powerful yet lightweight Kubernetes distribution perfect for: This configuration is ideal for running MicroK8s with multiple workloads, monitoring tools, and CI/CD pipelines. In this guide, you will: It includes core Kubernetes components and plug-and-play add-ons like DNS, Ingress, Helm, and the Dashboard. This will take a few minutes. MicroK8s installs the latest stable Kubernetes release. ๐ Kubernetes is up and running! MicroK8s creates its own Unix group to manage access. Add your user to avoid using sudo every time: Apply group changes immediately without logging out: Now you can run microk8s commands without sudo! Typing microk8s kubectl every time is tedious. Let's create an alias so you can just type kubectl. Add the alias to your bash configuration: Apply the changes to your current session: From this point forward, all commands in this guide will use kubectl for brevity, but remember it is running the MicroK8s version. Enable DNS for internal service discovery: Enable storage for persistent volumes (databases, file storage): Enable Ingress for external access (domain routing, SSL): Enable Helm 3 package manager: Enable Kubernetes Dashboard (UI): Enable Metrics Server (for monitoring CPU/RAM usage): You should see all enabled add-ons listed as active. STATUS should be Ready โ All components should show Running or Completed status: If everything shows Running, your cluster is healthy! ๐ Let's deploy a simple NGINX workload to verify everything works end-to-end: You'll see output like: Note the NodePort (e.g., 31234). Open your browser and visit: If you see the NGINX welcome page โ ๐ Your Kubernetes cluster is working perfectly! Since MicroK8s is installed via Snap, systemctl cannot be used directly. Snap manages startup behavior automatically, but let's verify and ensure it's active. If all services show Startup: enabled, MicroK8s is set to autostart โ If services show disabled, simply run: This enables the entire application service and its internal daemons. Reboot the server to test autostart: After logging back in, run: If you see microk8s is running, then autostart is confirmed! ๐ Your nginx pod should be running. Check how much of your 8GB RAM MicroK8s is using: Check disk usage (out of 120GB): MicroK8s typically uses: This leaves plenty of resources for your workloads! ๐ Once you've verified everything works, you can remove the test NGINX deployment: Congratulations! ๐ Your 4-core, 8GB RAM, 120GB Ubuntu server is now running a fully functional MicroK8s cluster! You have a robust foundation ready for production workloads. ๐ Back to Part 1: Prerequisites & Basic Ubuntu Setup Ready to deploy production applications? ๐ ๐ Continue to Part 3: Production Namespace, App Deployment & Configuration In Part 3, you'll learn how to: Templates let you quickly answer FAQs or store snippets for re-use. as well , this person and/or COMMAND_BLOCK:
sudo apt update && sudo apt upgrade -y COMMAND_BLOCK:
sudo apt update && sudo apt upgrade -y COMMAND_BLOCK:
sudo apt update && sudo apt upgrade -y COMMAND_BLOCK:
sudo snap install microk8s --classic COMMAND_BLOCK:
sudo snap install microk8s --classic COMMAND_BLOCK:
sudo snap install microk8s --classic COMMAND_BLOCK:
sudo microk8s status --wait-ready COMMAND_BLOCK:
sudo microk8s status --wait-ready COMMAND_BLOCK:
sudo microk8s status --wait-ready CODE_BLOCK:
microk8s is running
high-availability: no datastore master nodes: 127.0.0.1:19001 datastore standby nodes: none CODE_BLOCK:
microk8s is running
high-availability: no datastore master nodes: 127.0.0.1:19001 datastore standby nodes: none CODE_BLOCK:
microk8s is running
high-availability: no datastore master nodes: 127.0.0.1:19001 datastore standby nodes: none COMMAND_BLOCK:
sudo usermod -a -G microk8s $USER COMMAND_BLOCK:
sudo usermod -a -G microk8s $USER COMMAND_BLOCK:
sudo usermod -a -G microk8s $USER CODE_BLOCK:
newgrp microk8s CODE_BLOCK:
newgrp microk8s CODE_BLOCK:
newgrp microk8s COMMAND_BLOCK:
echo 'alias kubectl="microk8s kubectl"' >> ~/.bashrc COMMAND_BLOCK:
echo 'alias kubectl="microk8s kubectl"' >> ~/.bashrc COMMAND_BLOCK:
echo 'alias kubectl="microk8s kubectl"' >> ~/.bashrc CODE_BLOCK:
source ~/.bashrc CODE_BLOCK:
source ~/.bashrc CODE_BLOCK:
source ~/.bashrc COMMAND_BLOCK:
kubectl version --client COMMAND_BLOCK:
kubectl version --client COMMAND_BLOCK:
kubectl version --client CODE_BLOCK:
microk8s enable dns CODE_BLOCK:
microk8s enable dns CODE_BLOCK:
microk8s enable dns CODE_BLOCK:
microk8s enable storage CODE_BLOCK:
microk8s enable storage CODE_BLOCK:
microk8s enable storage CODE_BLOCK:
microk8s enable ingress CODE_BLOCK:
microk8s enable ingress CODE_BLOCK:
microk8s enable ingress CODE_BLOCK:
microk8s enable helm3 CODE_BLOCK:
microk8s enable helm3 CODE_BLOCK:
microk8s enable helm3 CODE_BLOCK:
microk8s enable dashboard CODE_BLOCK:
microk8s enable dashboard CODE_BLOCK:
microk8s enable dashboard CODE_BLOCK:
microk8s enable metrics-server CODE_BLOCK:
microk8s enable metrics-server CODE_BLOCK:
microk8s enable metrics-server CODE_BLOCK:
microk8s status CODE_BLOCK:
microk8s status CODE_BLOCK:
microk8s status COMMAND_BLOCK:
kubectl get nodes COMMAND_BLOCK:
kubectl get nodes COMMAND_BLOCK:
kubectl get nodes COMMAND_BLOCK:
NAME STATUS ROLES AGE VERSION
hostname Ready <none> 5m v1.31.3 COMMAND_BLOCK:
NAME STATUS ROLES AGE VERSION
hostname Ready <none> 5m v1.31.3 COMMAND_BLOCK:
NAME STATUS ROLES AGE VERSION
hostname Ready <none> 5m v1.31.3 COMMAND_BLOCK:
kubectl get pods --all-namespaces COMMAND_BLOCK:
kubectl get pods --all-namespaces COMMAND_BLOCK:
kubectl get pods --all-namespaces CODE_BLOCK:
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system calico-node-xxxxx 1/1 Running 0 5m
kube-system coredns-xxxxx 1/1 Running 0 4m
ingress nginx-ingress-microk8s-controller-xxxxx 1/1 Running 0 3m CODE_BLOCK:
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system calico-node-xxxxx 1/1 Running 0 5m
kube-system coredns-xxxxx 1/1 Running 0 4m
ingress nginx-ingress-microk8s-controller-xxxxx 1/1 Running 0 3m CODE_BLOCK:
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system calico-node-xxxxx 1/1 Running 0 5m
kube-system coredns-xxxxx 1/1 Running 0 4m
ingress nginx-ingress-microk8s-controller-xxxxx 1/1 Running 0 3m COMMAND_BLOCK:
kubectl create deployment nginx --image=nginx COMMAND_BLOCK:
kubectl create deployment nginx --image=nginx COMMAND_BLOCK:
kubectl create deployment nginx --image=nginx COMMAND_BLOCK:
kubectl expose deployment nginx --port=80 --type=NodePort COMMAND_BLOCK:
kubectl expose deployment nginx --port=80 --type=NodePort COMMAND_BLOCK:
kubectl expose deployment nginx --port=80 --type=NodePort COMMAND_BLOCK:
kubectl get svc nginx COMMAND_BLOCK:
kubectl get svc nginx COMMAND_BLOCK:
kubectl get svc nginx COMMAND_BLOCK:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx NodePort 10.152.183.45 <none> 80:31234/TCP 10s COMMAND_BLOCK:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx NodePort 10.152.183.45 <none> 80:31234/TCP 10s COMMAND_BLOCK:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx NodePort 10.152.183.45 <none> 80:31234/TCP 10s CODE_BLOCK:
http://your-server-ip:31234 CODE_BLOCK:
http://your-server-ip:31234 CODE_BLOCK:
http://your-server-ip:31234 COMMAND_BLOCK:
sudo snap services microk8s COMMAND_BLOCK:
sudo snap services microk8s COMMAND_BLOCK:
sudo snap services microk8s CODE_BLOCK:
Service Startup
microk8s.daemon-apiserver enabled
microk8s.daemon-containerd enabled
... CODE_BLOCK:
Service Startup
microk8s.daemon-apiserver enabled
microk8s.daemon-containerd enabled
... CODE_BLOCK:
Service Startup
microk8s.daemon-apiserver enabled
microk8s.daemon-containerd enabled
... COMMAND_BLOCK:
sudo snap start --enable microk8s COMMAND_BLOCK:
sudo snap start --enable microk8s COMMAND_BLOCK:
sudo snap start --enable microk8s COMMAND_BLOCK:
sudo reboot COMMAND_BLOCK:
sudo reboot COMMAND_BLOCK:
sudo reboot CODE_BLOCK:
microk8s status --wait-ready CODE_BLOCK:
microk8s status --wait-ready CODE_BLOCK:
microk8s status --wait-ready COMMAND_BLOCK:
kubectl get pods COMMAND_BLOCK:
kubectl get pods COMMAND_BLOCK:
kubectl get pods COMMAND_BLOCK:
sudo microk8s inspect COMMAND_BLOCK:
sudo microk8s inspect COMMAND_BLOCK:
sudo microk8s inspect COMMAND_BLOCK:
sudo microk8s stop
sudo microk8s start COMMAND_BLOCK:
sudo microk8s stop
sudo microk8s start COMMAND_BLOCK:
sudo microk8s stop
sudo microk8s start COMMAND_BLOCK:
# Check kubelet logs
journalctl -u snap.microk8s.daemon-kubelet -f # Check API server logs
journalctl -u snap.microk8s.daemon-apiserver -f COMMAND_BLOCK:
# Check kubelet logs
journalctl -u snap.microk8s.daemon-kubelet -f # Check API server logs
journalctl -u snap.microk8s.daemon-apiserver -f COMMAND_BLOCK:
# Check kubelet logs
journalctl -u snap.microk8s.daemon-kubelet -f # Check API server logs
journalctl -u snap.microk8s.daemon-apiserver -f COMMAND_BLOCK:
kubectl delete deployment nginx
kubectl delete service nginx COMMAND_BLOCK:
kubectl delete deployment nginx
kubectl delete service nginx COMMAND_BLOCK:
kubectl delete deployment nginx
kubectl delete service nginx - ๐ Developers testing Kubernetes locally
- ๐งช CI/CD environments
- ๐ Homelabs
- ๐ ๏ธ Edge and IoT systems
- ๐งฉ Single-node or small clusters - โจ Install MicroK8s
- ๐ Configure user permissions
- ๐งฐ Enable essential add-ons
- ๐งช Verify the cluster is running
- ๐ Deploy a test application
- ๐ Ensure services autostart on boot - Lightweight ๐ชถ โ Minimal resource footprint
- Easy to install โก โ One command setup
- Zero external dependencies ๐ฏ โ Everything bundled
- Production-ready ๐ฅ โ Enterprise-grade
- Beginner-friendly and pro-friendly ๐จโ๐ป โ Great for learning and production - ~500MB-1GB RAM at idle
- ~2-3GB storage for base installation - ๐๏ธ Create production namespaces for workload isolation
- ๐ Deploy PostgreSQL and n8n with proper configurations
- ๐ฆ Set up Persistent Volume Claims for databases
- ๐ Secure sensitive data using Kubernetes Secrets