There’s no question Kubernetes is hard. Even from the very beginning, deploying a Kubernetes cluster can be a challenge for many IT pros. Fortunately, there’s a tool that makes this considerably easier, especially when you’re dealing with Ubuntu Server as the hosting platform. That tool is Microk8s, and I’m going to walk you through the way I deploy a Kubernetes cluster with regular success.
SEE: Hiring kit: Python developer (TechRepublic Premium)
The process isn’t that challenging, but you do have to take all the necessary steps, because if you skip anything, the cluster will not work. With that said, let’s get to the deployment.
What you’ll need to deploy Kubernetes with Microk8s
To successfully deploy a Kubernetes cluster with Microk8s, you’ll need the following:
- At least three instances of Ubuntu Server running.
- A user with sudo privileges on all nodes.
That’s it. Let’s get to work.
How to set the proper timezone
The first thing we must do is set the proper timezone on all three nodes. I discovered this the hard way after attempting a deployment on three machines without realizing the proper timezone hadn’t been set. Without the proper timezone, the nodes cannot join the controller.
To set the timezone, log into the first node and issue the command:
From that list, locate your timezone, such as America/New_York. To set that timezone, issue the command:
sudo timedatectl set-timezone America/New_York
Make sure to substitute America/New_York for your timezone, and make sure to do the above on all nodes that will be a part of your cluster.
How to set the hostname for each node
We’ll now set the hostname for each node. I’m going with k8s1, k8s2 and k8s3. The command to set the hostname looks like this:
sudo hostnamectl set-hostname k8s1
Once you’ve run the command, log out and log back in so the change takes effect. Make sure to run that command, substituting the name of each node, on all machines that will be part of the cluster.
How to configure the hosts file
Next, we need to configure the hosts file on all nodes. Let’s say your address mapping looks like this:
Open the hosts file with the command:
sudo nano /etc/hosts
Add the above address mapping, substituting your IP addresses and hostnames, at the bottom of the file. Save and close the file.
How to install Microk8s
This is where I’ve discovered other issues. The most recent version of Microk8s I’ve successfully been able to cluster is 1.24. To install Microk8s version 1.24, the command would be:
sudo snap install microk8s --channel=1.24/stable --classic
Make sure to run the above command on all nodes.
How to join the nodes to the cluster
On the controller, which would be k8s1 in the above configuration, issue the command:
The above command will return the joining instructions for all of your nodes. Those instructions will include a command like this:
microk8s join 192.168.1.70:25000/b72da5f131d0aa09cbeaa9712cd865f5/5786c9b72085
You must then issue the above on all other nodes. Once you’ve successfully run the join command on all nodes, go back to the controller and check for the status with the command:
microk8s kubectl get nodes
You should see something like this in the output:
k8s1 Ready <none> 24h v1.24.8-2+1dda18a15eea38
k8s2 Ready <none> 24h v1.24.8-2+1dda18a15eea38
k8s3 Ready <none> 24h v1.24.8-2+1dda18a15eea38
Your cluster is ready
That’s all there is to deploy a Kubernetes cluster with Microk8s. Make sure to take all of the above steps to avoid a failed cluster deployment. With the cluster ready, you can now start deploying your pods and enjoying the power of Kubernetes.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.
Learn more about Linux with The Mastering Linux Development Bundle from TechRepublic Academy.
Subscribe to the Developer Insider Newsletter
From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays