Deploying a high-availability cluster with MicroK8s

If you’re looking to deploy a highly available cluster, your job has been made exponentially easier, thanks to Microk8s. Jack Wallen shows you how to do this.

With the release of Microk8s 1.19, High Availability (HA) is enabled by default. This means a cluster can withstand a failure on any one of its nodes and continue serving workloads without interruption. HA is an important feature, especially for businesses looking to deploy containers and pods that can deliver a level of reliability necessary when working at scale.

You might be thinking that Microk8s would be a challenge to deploy. Thanks to Canonical and snap, it’s not. In fact, you can get HA-ready MicroK8s rolled out in minutes. I’m going to show you how to do just that.

What you’ll need

In order to do this, you’ll need at least Linux servers that support snap up and running. I’ll be demonstrating on Ubuntu Server. You’ll also need a user with sudo privileges.

Note: You can successfully deploy this cluster on your own data center servers or on cloud-based servers from the likes of AWS, Azure, and Google Cloud.

How to install MicroK8s

The first thing you must do is install MicroK8s on the controller and the nodes. So log in to your controller and issue the command:

sudo snap install microk8s --classic --channel=1.19/stable

When that finishes, you’ll want to add your user to the microk8s group with the command:

sudo usermod -aG microk8s $USER

You’ll then need to change the permissions of the ~/.kube directory with the command:

sudo chown -f -R $USER ~/.kube

Next, move over to the first and second nodes and issue the same commands above (all three–snap, usermod, and chown).

After you add your user to the group, you must log out and log back in so the changes will take effect.

How to add nodes

The next step is to add your nodes to the controller. On the controller, issue the command:

microk8s add-node

The above command will output a join string that looks like:

microk8s join 192.168.1.210:25000/9ffec747d20e944148fe5a5f00a07cf6

Head over to your first node and issue the above command. It’ll take a few minutes for the join to complete. Once you receive your bash prompt back, the node has successfully joined. When that completes, go back to the controller and re-issue the microk8s add-node command. You’ll get a new join command with a new token. Copy that command and run it on the second node. Remember: Every time you add a new node, you must get a new join token from the controller.

How to check the status of your cluster

Once both nodes have joined the cluster, go back to the controller and issue the command:

microk8s status

In the output you should see all nodes in the cluster as well as the ha-cluster module enabled (Figure A).

Figure A

Our cluster has been deployed.

And that’s all there is to deploying a high-availability cluster with the latest release of Microk8s. Enjoy that newfound power and failover.

This article has been published from the source link without modifications to the text. Only the headline has been changed.

Source link