A Journey With Kubernetes: Part 2 — Introducing Virtual Machines

The adventure continues….

Mike Wolfe
Sep 14, 2020 · 4 min read
Photo by NASA on Unsplash

In my previous post, we explored the struggles and triumphs that I undertook while creating a Kubernetes cluster using Raspberry Pi’s. Although there were quite a few issues getting it up and running, the end result was pretty exciting and very workable. In this post, we are going to build upon what I learned and instead of using Raspberry Pi’s, I will be using virtual machines on a server. The goal is to get everything up and running on x64 architecture and see if the cluster is still usable after a power loss.

The server I will be working with is a Dell Poweredge R710. It has seventy-two gigabytes of RAM and three terrabytes of storage running in RAID 1. Ubuntu Server 20.04 is running on top of all of this. For the virtual machines, they will be using Ubuntu Server 20.04 as well. I will not go into detail about creating the virtual machines. Just note that like the POC I ran during the semester, we will have one primary node and three worker nodes. In our case here, I am using QEMU/KVM with virt-manager (VMWare and Virtualbox should work just fine as well). It’s also helpful to have SSH installed too.

To start off, it’s important to update the operating system with:

After updating the system, Docker can be installed:

To check that Docker did in fact get installed, run:

Set Docker to launch when the system is booted:

To check that Docker is running:

In case Docker isn’t running, this command will start it up:

Next, it’s time to get Kubernetes installed. Before that can be done, I have to add the signing keys:

After that, the Kubernetes package repository can be added to the software sources:

Once added, Kubernetes can be installed:

Now that all packages are installed, swap has to be disabled before creating the cluster:

One thing I learned the hard way is that this command will not persist when the virtual machine is rebooted. Meaning, when the virtual machine is rebooted, swap will be re-enabled. To make it persist, I commented out the line that began with /swap in the /etc/fstab file using the Nano text editor.

Now that swap was disabled, I ran the following command to initialize and create the cluster. Note that it did take a few minutes to complete:

Output of the cluster being created successfully:

Running this command, will show all nodes on the cluster:

Output:

You’ll notice that the STATUS says not ready. This is because the cluster is missing networking software. Before that issue can be tackled, these commands need to be executed to create a directory for the cluster:

With the directory created, Flannel can be installed, adding a network layer to the cluster. This will allow the different nodes to communicate with each other.

The final step is to add the three worker nodes to the cluster. This was accomplished by running the bash script that I created here. Essentially, this script installs Docker, Kubernetes and disables swap (basically, what we did earlier ;)). After logging into the node em-worker01 and running the script, I ran following command to get the node to join the cluster:

After running this command, we get the following output:

If you’re like me and you forget to copy the join the command after initializing and creating the cluster, this will show that command:

For the remaining two nodes (em-worker02 and em-worker03) the previous steps were utilized. After all three worker nodes had joined the cluster, I went back to the primary node and re-ran the command to get all nodes:

It took a couple tries, but eventually the output looked like this:

At this point, the cluster is ready to use. The big perk here is that it is up and running on x64 architecture. Therefore, I shouldn’t have any issues with a lack of Docker images. Also, it’s also worth mentioning that the cluster was able to survive a server restart. This was a relief to see since it was quite annoying having to rebuild everything after a restart on the Raspberry Pi’s. In the next part of this series, I will attempt to get multiple databases deployed to the shiny new cluster. Cheers!

Special thanks to Kubernetes Documentation and Stackoverflow for helping me figure this out!

Nerd For Tech

From Confusion to Clarification

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store