How to setup low-cost, zero-ops, full-featured Kubernetes Cluster in a single VM using MicroK8s
Microk8s is a lightweight, easy-to-install Kubernetes distribution that provides a fully-featured cluster on a single VM. It has gained popularity in recent years for its simplicity and ease of use, especially when compared to other similar Kubernetes options such as k3s and minikube.
Introduction
Microk8s is a lightweight, easy-to-install Kubernetes distribution that provides a fully-featured cluster on a single VM. It has gained popularity in recent years for its simplicity and ease of use, especially when compared to other similar Kubernetes options such as k3s and minikube. In this article, we'll dive into what Microk8s is, how it differs from managed Kubernetes clusters, and the advantages it offers over other Kubernetes distributions. We'll also share our own experiences using Microk8s for various projects, highlighting the benefits and value it provides. Lastly, we will show how to setup it on your VM.
What is Microk8s?
Microk8s is a Kubernetes distribution developed by Canonical, the company behind Ubuntu. It is designed to be a simple, single-node Kubernetes cluster that can run on any machine. It's perfect for developers, small deployments, edge computing, IoT, and other situations where a full-scale Kubernetes cluster isn't necessary or practical. Microk8s comes with a rich set of features, including automatic updates, built-in service discovery, and support for various storage and networking plugins.
Microk8s vs. Managed Kubernetes Clusters
Managed Kubernetes clusters are typically offered by cloud providers and come with the advantage of being fully managed by the provider. This means that they handle all administrative tasks, such as updates, scaling, monitoring, and backup. While managed clusters are convenient, they often come with a higher price tag and may not be suitable for smaller projects or for those who don't need all the features provided by a full-scale Kubernetes cluster.
In contrast, Microk8s is designed to be lightweight, self-contained, and easy to install. It can be run on a single VM, making it a perfect solution for smaller projects or when you need to spin up a Kubernetes cluster quickly. It requires minimal configuration and is ideal for developers who want to focus on their applications rather than managing their cluster.
Microk8s vs. K3s and Minikube
K3s and Minikube are two other popular lightweight Kubernetes distributions. While both offer a simplified Kubernetes experience, they have some key differences compared to Microk8s:
- K3s: Developed by Rancher Labs, K3s is designed for edge computing, IoT, and other resource-constrained environments. It has a smaller binary size than Microk8s and offers a more minimalistic feature set. However, Microk8s provides better support for various storage and networking plugins and has a more comprehensive set of features out of the box.
- Minikube: Minikube is specifically designed for local development, enabling developers to run a single-node Kubernetes cluster on their local machines. While Minikube is great for development and testing purposes, it lacks some of the more advanced features and plug-in support provided by Microk8s, making Microk8s a more versatile option.
This table provides an overview of the key differences between Microk8s, Managed Kubernetes Clusters, K3s, and Minikube in terms of their target use cases, installation, management, cost, and features. This should help you easily compare and understand their unique offerings and suitability for various scenarios.
Feature/Aspect | Microk8s | Managed Kubernetes Clusters | K3s | Minikube |
---|---|---|---|---|
Target Use Case | Developers, small deployments, edge computing, IoT | Larger deployments, enterprises | Edge computing, IoT, resource-constrained environments | Local development, testing |
Installation | Easy, single-node setup | Provider managed, multiple-node setup | Easy, single-node setup | Easy, single-node setup |
Management | Self-managed, minimal administrative tasks | Provider managed, full administrative support | Self-managed, minimal administrative tasks | Self-managed, minimal administrative tasks |
Cost | Free, open-source | Paid, pricing varies by provider | Free, open-source | Free, open-source |
Automatic Updates | Yes | Yes | Yes | No |
Service Discovery | Built-in | Depends on provider | Built-in | Built-in |
Storage and Networking Plugins | Comprehensive support | Depends on provider | Limited support | Limited support |
Binary Size | Small | N/A | Smallest | Small |
Additional Features | Rich set of features out of the box | Depends on provider | Minimalistic feature set | Focused on development and testing features |
Our Experience with Microk8s
We have used Microk8s for some of our projects, and it has truly lived up to our expectations of a Kubernetes cluster. Installation was a breeze, and we quickly had a full-featured Kubernetes cluster running on a single VM. With Microk8s, we were able to focus on our applications rather than administrative tasks, as it offered a genuine zero-ops experience.
In our experience, Microk8s has proven to be an excellent solution for small deployments, edge computing, and developer environments. It has allowed us to easily deploy and manage our applications without the overhead and complexity of a full-scale Kubernetes cluster.
How to Setup MicroK8s
Prerequisites
We will install and set up MicroK8s in a single VM. The first thing we need to do is prepare a VM. This VM should have a public IP address, so we can easily manage its MicroK8s.
The installation of this VM depends on your preference, but here are some details you should consider:
- It's not a must, but we recommend using Ubuntu instead of another Linux distribution. Yes, MicroK8s supports other Linux distros nicely, however, MicroK8s is a Canonical product, the company behind Ubuntu. It's logical that Canonical would prioritize its support for Ubuntu.
- MicroK8s requires at least 20 GB of disk space and 4 GB of memory. Ideally, the VM's specs should be double that.
- At a minimum, we need to open ports 443 and 80. Additionally, we should open port 16443, which is used by our local kubectl. This way, we can manage our MicroK8s from our local machine.
The example below demonstrates installing a VM in GCP (Google Cloud Platform) using Terraform.
Setup with Ansible
We provide a simple Ansible Playbook for setting up MicroK8s here: https://github.com/8grams/ansible-microk8s. Just follow the instructions in the Readme, and you will quickly spin up a MicroK8s instance in your VM.
Setup with Manual Steps
- SSH Login to your VM
- Install MicroK8s
~$ sudo snap install microk8s --classic --channel=1.27
- Add the user to the MicroK8s group and change the ownership of MicroK8s config files
~$ sudo usermod -a -G microk8s $USER
~$ sudo chown -f -R $USER ~/.kube
- Verify the MicroK8s installation
~$ microk8s status
- You may want to refresh the bash shell by logging out and SSH logging in again
- Activate common addons. In Microk8s, addons are pre-packaged Kubernetes extensions and services that can be easily enabled or disabled to enhance the functionality of your Kubernetes cluster. These addons help users to quickly set up and configure various components without the need to manually install and manage them.
~$ microk8s enable dns cert-manager ingress hostpath-storage
- Optionally, you may want to enable community addons
~$ microk8s enable community
Yeay!! Congratulations, you have a Kubernetes Cluster now in your VM.
Additional Setup
Manage MicroK8s instance locally
It's a convenient to be able to manage K8s cluster directly on our local machine. Here are the steps to do that:
- Login to your VM
- Get MicroK8s's configuration
~$ microk8s config
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: XXXX
server: https://10.0.0.45:16443
name: microk8s-cluster
contexts:
- context:
cluster: microk8s-cluster
user: admin
name: microk8s
current-context: microk8s
kind: Config
preferences: {}
users:
- name: admin
user:
token: XXX
- Copy the result of command above to your local
~/.kube/config
. Do not forget to change cluster server with VM's IP Address
- cluster:
certificate-authority-data: XXXX
server: https://<VM IP Address here>:16443
name: microk8s-cluster
- Edit
csr.conf.template
in order to make your MicroK8s instance accessible remotely
~$ vim /var/snap/microk8s/current/certs/csr.conf.template
- Put VM's IP Address in
alt_names
section. Set a unique name, in this case we just randomly set it asIP.100
[ alt_names ]
...
...
IP.100 = <VM IP Address here>
- Verify with local kubectl
~$ kubectl config use-context microk8s-cluster
~$ kubectl get nodes
- If last command show your VM's name, then it's done.
Conclusion
Microk8s is a powerful, lightweight Kubernetes distribution that offers a simple and easy-to-install solution for developers and small deployments. Its full-featured set of capabilities, minimal management overhead, and versatility make it an attractive option for a wide range of use cases.
When compared to managed Kubernetes clusters, Microk8s provides a more cost-effective and accessible solution for smaller projects and teams that don't require the full support and features offered by cloud providers. In contrast to other lightweight Kubernetes distributions like K3s and Minikube, Microk8s stands out with its comprehensive support for various storage and networking plugins and a richer feature set out of the box.
Our experience with Microk8s has demonstrated its value for projects where a full-scale Kubernetes cluster isn't necessary or practical. The zero-ops experience it offers allows developers to focus on building and deploying applications, rather than getting bogged down in cluster management tasks.
Overall, if you're looking for a Kubernetes solution that's lightweight, easy to install, and comes with a wide range of features, Microk8s is an excellent choice. Whether you're a developer, working on edge computing, or managing small deployments, Microk8s can help you streamline your Kubernetes experience and deliver applications more efficiently.
About 8grams
We are a small DevOps Consulting Firm that has a mission to empower businesses with modern DevOps practices and technologies, enabling them to achieve digital transformation, improve efficiency, and drive growth.
Ready to transform your IT Operations and Software Development processes? Let's join forces and create innovative solutions that drive your business forward.
Subscribe to our newsletter for cutting-edge DevOps practices, tips, and insights delivered straight to your inbox!