MicroK8s is a powerful open-source container platform that makes it easy to build and manage Kubernetes clusters. With MicroK8s, you can run your own Kubernetes cluster on your own computer or server. You can use MicroK8s to run Kubernetes on nodes that are small and low-power, or you can use MicroK8s to run Kubernetes on nodes that are more powerful and expensive. You can use MicroK8s to run Kubernetes on any platform that has a microcontroller, such as Raspberry Pi, Arduino, or Microsoft Azure cloud services. You can also use MicroK8s to run Kubernetes on devices that are not connected to the internet, such as phones or tablets. To start running your own Kubernetes cluster with MicroK8s, you first need to install the microk8s-server package. Then you need to create a new directory for your cluster and install the microk8s-client package. Finally, you need to create a file called kubernetserver in this directory and paste the following code into it:
kubernetserver - create a new kubernetes server # # kubernetserver - name “my_server” - port 8080 - user “root” - password “password” # # kubernetserver - start my_server
MicroK8s is a lightweight single-package Kubernetes distribution developed by Canonical, best known for the Ubuntu operating system. MicroK8s follows upstream Kubernetes releases and focuses on providing an effortless installation and management experience. Here’s how to get started running your own cluster.
Installation
MicroK8s is available on Linux, Windows, and macOS. A graphical Windows installer is offered on the project’s website. macOS users should use Brew while Linux users are served by snaps.
Follow the separate Snap installation steps if you’re missing snapd on your system. Then use the snap install command to add MicroK8s:
This installs the latest MicroK8s version. You can select a specific release using the –channel flag:
This will give you a version of MicroK8s that’s based on Kubernetes v1.19.
Installation can take a while to complete as Kubernetes services start up. Running microk8s status –wait-ready lets you check progress so you know when MicroK8s is ready to use.
Interacting With Your Cluster
MicroK8s bundles its own version of the Kubectl command-line tool. Use microk8s kubectl to interact with your cluster, appending a regular kubectl command:
This command surfaces all the resources in your cluster.
Next create a basic manifest to deploy:
Apply the manifest to your cluster:
MicroK8s will create a new Pod running the NGINX web server. It’ll show up when you re-run microk8s kubectl get all.
MicroK8s is compatible with all Kubectl commands. If you want to drop the microk8s prefix, you can use a “real” kubectl binary instead:
This exports the MicroK8s connection information into your Kubernetes configuration file, allowing plain kubectl commands to reach your cluster.
Most MicroK8s commands require superuser access. For long-term use, add your user account to the microk8s group so you don’t need to use sudo each time:
Accessing Docker Images
MicroK8s can’t access your local Docker images automatically. If you want to deploy an image you’ve just built, manually import it to the MicroK8s registry by exporting it as a tar archive.
Now your Pods can successfully reference the image. You can list all known images in the MicroK8s registry with the microk8s ctr images ls command.
Beyond simple use on your local machine, you should set up a dedicated Docker image registry to hold your images. Push images there and grant MicroK8s pull access so it can retrieve them from your storage. The steps to follow depend on your registry’s configuration.
Enabling the Kubernetes Dashboard
The Kubernetes web dashboard is bundled with MicroK8s but is disabled by default. You can activate it by enabling its addon, then navigating to the IP address of the dashboard service.
The service might take a few moments to start. Run microk8s kubectl get services –namespace kube-system and wait for the kubernetes-dashboard service to show up. Note down its CLUSTER-IP and visit its address in your browser. The Kubernetes dashboard should appear, letting you interact with your resources using a graphical interface.
Using More Addons
MicroK8s ships with several other optional addons for common use cases. The dns addon adds support for DNS deployment, storage provides a default storage class based on host directories, and ingress offers an ingress controller that lets you create Ingress routing resources.
The registry addon is a special service that deploys a ready-to-use Docker registry on localhost:32000. Using the registry provides a private storage space which you can push your images to, before using them in your Kubernetes Pods. Similarly, the istio addon launches an Istio mesh to provide service discovery functions.
An exhaustive description of these addons is provided in the MicroK8s documentation. You can view all the available addons in your installation by running microk8s enable without any arguments. Only the bare minimum Kubernetes functionality is active by default as MicroK8s focuses on providing a streamlined experience.
Managing Your Cluster
All cluster management functions are provided by the microk8s command. Running microk8s status shows an overview of your cluster, including whether it’s running and the list of active addons.
To shutdown your cluster, run microk8s stop. This will stop all services, taking everything offline. You restart the cluster with the microk8s start command. It might take a few moments for all your services to get running.
You can view your cluster connection details by running microk8s config. This emits a Kubectl-compatible YAML file, ready to use with other tools.
Running microk8s reset will reset your cluster to its initial post-installation state. This is a destructive time-consuming operation that will destroy all your resources. It facilitates experimentation by letting you teardown everything, without removing the MicroK8s snap. Kubernetes storage volumes will be retained by default; you can delete them too by adding the –destroy-storage flag.
Multi-Node Clusters
Although MicroK8s started as a single-node project, you can now add secondary nodes to your cluster. Additional nodes give you redundancy, as well as increased workload capacity. Each node requires its own fully isolated environment – either a separate physical machine, VM, or container. You can’t run two MicroK8s worker instances in the same environment.
First, run microk8s add-node on your original node. This will become the controlling master that runs the Kubernetes control plane.
The command creates a provisional registration for the new node. It’ll output a microk8s join command which will join the node to the control plane. The joining process will take a few seconds to complete. The node must be able to reach your master over the displayed network address.
Once the node’s been added, it will be eligible to host your Pods. You can view all available nodes by running microk8s kubectl get nodes.
Removing a node from the cluster is an exercise in reversal. First, run microk8s leave on the target node. Then run microk8s remove-node 10.108.0.1 on the master, substituting in the IP address of the removed node. This will notify all other nodes of the removal. The target node will revert to a regular standalone MicroK8s installation, becoming its own master.
Conclusion
MicroK8s is a minimal Kubernetes distribution that’s easily self-hosted on your own hardware. It’s fully CNFC-compliant and comes with built-in addons for the official Kubernetes dashboard, Ingress routing, and the Istio service mesh. These help you quickly set up your own production-ready cluster capable of matching the managed Kubernetes offerings from public cloud providers.
MicroK8s supports a particularly broad range of hardware and deployment architectures. It works on developer workstations, in highly available production environments, and on the Raspberry Pi. This flexibility lets you use exactly the same technology in development and production, even down to the Kubernetes implementation.
Compared to rival projects such as Minikube, MicroK8s excels at running in resource-constrained environments with minimal overheads. It benefits from its own containerization, using the snap package format, so there’s no heavy VM to run. This leaves you with more capacity to host your workloads and other developer tools.
While MicroK8s began life as a developer-centric project, targeting local testing and prototyping, it’s now billed as a production-ready Kubernetes distribution with a proven record for closely following upstream releases. Clusters can be upgraded to new Kubernetes releases using the snap refresh microk8s command.