How to Install Kubernetes on CentOS 7

What is Kubernetes?
Kubernetes is a portable, extensible open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.

Google open-sourced the Kubernetes project in 2014. Kubernetes builds upon a decade and a half of experience that Google has with running production workloads at scale, combined with best-of-breed ideas and practices from the community.

In this tutorial I will show you how to create a Kubernetes cluster with 1 master and 2 worker nodes.

Note: This guide is written for CentOS 7 and written for a non-root user.
Commands that require elevated privileges are prefixed with [sudo]

Servers
I have created 3 CentOS 7 VM’s with the minimal installation.

Installation of Kubernetes Nodes
We start with the installation of the Kubernetes Master.
First we need to disable Selinx and FirewallD.

Add the Kubernetes repository on our system.

Now that we added the repository we can install Kubernetes.

Make sure that Docker and Kubernetes are started at startup.

Some users on RHEL/CentOS 7 have reported issues with traffic being routed incorrectly due to iptables being bypassed. You should ensure net.bridge.bridge-nf-call-iptables is set to 1 in your sysctl config.

The last step of the Kubernetes installation is to disable swap.
All Kubernetes master and worker(s) are expected to have swap disabled.
This is the recommended deployment by the Kubernetes community.

Reboot the system to make sure the swap has been disabled.
Perform these same steps also for the worker nodes.

Configuration of the Kubernetes Master
Before we initialize our Kubernetes cluster, we need to choose a subnet range for CIDR to be used for pod IP addresses. Since I’m using the “Calico” network plugin I will be using the default CIDR 192.168.0.0/16.
Note: The CIDR may be different if you decide to use an other network plugin.
Keep in mind that your values may differ from those below.

If the initialization is succesfull, the init command will give us the token that can be used to add external worker node to the cluster. Note this command

If you wat to run kubectl as a non-root user you need to execute the following commands

Use the kubectl command to check if kubernetes is running fine. This could take a few minutes

As you can see all the containers are up and running with the exeption of kube-dns.
The reason for this is that we don’t have the network plugin installed yet.

Now that everything is working perfectly we can at the worker(s) to the cluster.
Login on both worker nodes and execute the “kubeadm join” command from the cluster initialization.

Check if both nodes are added to the cluster. This could take a few minutes

Let’s install network plugin. In our case Calico
First we install the Calico CNI (Container Networking Interface)

We also need to install the Calico Controller to manage the CNI

Check if Calico is installed and if its working. This could take a few minutes

As we can see from the output there are some additional system containers installed on the master and worker nodes.
Now that Kubernetes is installed let’s spin up our first container

First Container
Now time to deploy our first container. In this tutorial I’ll be using NGINX

Next we make the NGINX container available to the network.

Check if the NGNIX is listing.

Note: The 32637 port was assigned during the create service command.
Keep in mind that your values may differ from those below.

Let’s test with a curl command if can display the NGINX index.html page

If you see the same output as above, congratulations, your NGINX container has been deployed on your Kubernetes cluster.

If you open up a webbrowser to http://<IP_or_DNS>:<NODEPORT> (Where IP or DNS is one of your nodes and NODEPORT is the port assigned during the create service command), you should see the NGINX Welcome page!

If you have some suggestions or tips, just leave a comment below.

Thanks for reading.

Leave a Reply

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