Kubernetes

Kubernetes Home Lab with Microk8s, Microceph, and Portainer

Build your own Kubernetes Home Lab using three components that provide a really great experience: microk8s, microceph, and Portainer

As you guys know I have been exploring what I think are really great setups from a standpoint of a home lab and also for learning purposes in production. Recently, I explored how viable it was to run a Docker Swarm cluster and found this to be an extremely good solution for home lab and even production environments, with the right tools. I wanted to take this forward into a Kubernetes configuration with Microk8s, Rook-Ceph, and Portainer as the UI management interface, which I used with the Docker Swarm configuration.

Why Kubernetes instead of Swarm?

When you compare the two, Kubernetes is much more complex than Swarm. However, it is the defacto standard that everyone is using in production environments and cloud. It is a great idea to learn Kubernetes as more than likely, you will run into it at some point in the future.

However, as I mentioned in my previous post, I think Docker Swarm is a very viable solution and is often overshadowed by Kubernetes when it probably shouldn’t be. In smaller environments, Swarm could be a perfect fit without the complexity.

Let’s take a look at the three components of my current Kubernetes home lab that I think are great building blocks for not only lab environments but also production:

  1. Microk8s
  2. Microceph
  3. Portainer
Overview of kubernetes home lab components with microk8s microceph and portainer
Overview of kubernetes home lab components with microk8s microceph and portainer

Microk8s

Microk8s is a solution from Canonical (makers of Ubuntu) that provides a production-ready Kubernetes you can easily spin up in a home lab environment. It is simple and easy to use and can be installed with a simple single command:

sudo snap install microk8s --classic
Microk8s install with snap
Microk8s install with snap

Also, I will get more into Portainer below, but it actually has an automated installation of Microk8s cluster using the Portainer environments tool. Instead of just adding an environmment you already have, you can go through the wizard and point it to 3 clean Linux servers and it will install Microk8s and onboard it into Portainer management all in one process.

I have written about this before and shown how to do this here: Mikrok8s Automated Kubernetes Install with new Portainer Feature.

To generate codes to add nodes, you just use this command:

sudo microk8s add-node
Running the add node command in microk8s
Running the add node command in microk8s

On your other nodes, just install microk8s using the first command and then use one of the commands generated by the add-node command to add the additional nodes to the cluster.

You can learn more about Microk8s from the official documentation here: MicroK8s – Zero-ops Kubernetes for developers, edge and IoT.

Microceph

For storage, Microceph is a purpose-built software-defined storage solution based on Ceph that you can use to provide persistent storage for pods that you want to create PVCs or persistent volume claims. Once the PVC is created, a persistent volume is bound to the pod.

You can install Microceph using the same simple one-liner snap command as we did with microk8s.

sudo snap install microceph
Installing microceph in ubuntu server for use with microk8s kubernetes home lab
Installing microceph in ubuntu server for use with microk8s kubernetes home lab

Next, to bootstrap the cluster, we can run the command:

sudo microceph cluster bootstrap
Bootstrapping the microceph cluster and checking status
Bootstrapping the microceph cluster and checking status

To add disks you use:

sudo microceph disk add /dev/sdb --wipe

Enable rook-ceph in Microk8s

Now that Ceph is installed and bootstrapped along with adding disks, you can connect this with Microk8s:

sudo microk8s enable rook-ceph

sudo microk8s connect-external-ceph

Learn more about Microceph here: MicroCeph documentation.

Portainer

As I detailed in my blog post covering Docker Swarm, using Portainer is like the icing on the cake. It provides all the GUI bells and whistles that allow you to control your Microk8s cluster and perform day-to-day operations.

Also, for home lab, you can get a free 3-node Business license (personal and student), or spring for a 15-node license for home lab that costs $125. Either of these are great option that allow you to fully explore the features and capabilities of the solution.

Portainer provides just a fantastic view of your Kubernetes environment, as it does with Docker Swarm.

Kubernetes cluster dashboard in portainer
Kubernetes cluster dashboard in portainer

You also have quick and easy access to your kubectl command shell. Another benefit of this running in Portainer when connected to a Microk8s cluster is you don’t have to prefix your commands with microk8s. Instead you can just use the normal kubectl commands.

Running kubectl shell in portainer
Running kubectl shell in portainer

You can quickly and easily see your applications running in the cluster and edit these if needed.

Viewing my microk8s kubernetes cluster in portainer
Viewing my microk8s kubernetes cluster in portainer

Viewing cluster details.

Viewing cluster details in portainer
Viewing cluster details in portainer

If you drill into a host, you will see the options to quickly change the availability status of a cluster node.

Viewing specific cluster host details and viewing availability options
Viewing specific cluster host details and viewing availability options

You can learn more about Portainer here: Kubernetes and Docker Container Management Software.

Thoughts and impressions

So far, my Kubernetes home lab based on microk8s, microceph, and Portainer are serving me well. It was quick and easy to build and Portainer even has the automated build out of your Microk8s cluster if you want it to do the heavy lifting. Otherwise, you can still build it yourself and then connect Portainer to your Microk8s cluster after the fact. One benefit of that is that I have found when building out Microk8s with Portainer, it seems to default to a non-HA configuration. You can go in and turn on HA for the cluster after, but that is just one observation. Also, I could be missing a setting or configuration somewhere in Portainer on that front.

Subscribe to VirtualizationHowto via Email ๐Ÿ””

Enter your email address to subscribe to this blog and receive notifications of new posts by email.



Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com, and a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.