Installing microk8s on ubuntu with snap

MicroK8s is a lightweight Kubernetes distribution developed by Canonical, the company behind Ubuntu Linux. It is designed to be a simple and efficient way to run a Kubernetes cluster on a single machine or in a small-scale environment.

MicroK8s aims to provide a minimalistic and easy-to-install Kubernetes experience without compromising on essential features. It is primarily focused on developers and users who want to quickly set up a local Kubernetes environment for testing, development, or learning purposes.

To install MicroK8s, a lightweight Kubernetes distribution on your Ubuntu Box, you can follow these steps:

Step #1 Update your system:

sudo apt update
sudo apt upgrade -y

Step #2 Install snapd (if not already installed):

Here is an one-liner to install Ubuntu Snap.

sudo apt install snapd

Step #3 Install MicroK8s (using snap):

sudo snap install microk8s --classic

This command will install MicroK8s using the classic confinement and the stable channel. You can adjust the channel version according to your preference.

Step #4 Add your user to the ‘microk8s’ group to access the cluster:

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

Step #5 Enable required services:

sudo microk8s enable dns storage

This command enables the DNS and storage services in MicroK8s.

Step #6 (Optional) Enable additional services as per your requirements:

sudo microk8s enable dashboard ingress

You can enable other services like the Kubernetes dashboard or the Ingress controller if needed. Modify the command accordingly.

Step #7 Check the status of your MicroK8s cluster:

sudo microk8s status --wait-ready

Wait until the status shows as “microk8s is running” and all the necessary services are enabled.

Step #8 (Optional) Alias the microk8s.kubectl command:

echo "alias kubectl='microk8s kubectl'" >> ~/.bashrc
source ~/.bashrc

This step is optional but recommended, as it allows you to use kubectl directly instead of microk8s kubectl.

Bonus Step ## How to Access the Kubernetes Dashboard

sudo microk8s dashboard-proxy

Related: How to Access the MicroK8S Kubernetes Dashboard

You have successfully installed MicroK8s on your system. You can now start using Kubernetes with MicroK8s locally.

Overall, MicroK8s simplifies the process of setting up and managing a local Kubernetes environment, making it an excellent choice for developers, hobbyists, and individuals who want to experiment with Kubernetes or develop applications locally before deploying them to production Kubernetes clusters.

References: