Kubernetes also referred to as k8 , is a free and opensource tool used for management of Docker containers. It’s a container orchestration platform that is tailored to automate the deployment, scaling, and management of containerized applications. In this guide, you will learn how to install and configure Kubernetes on Ubuntu 18.04 LTS.

Prerequisites

Before we get started , we are going to have a test lab comprising 3 Ubuntu 18.04 nodes as shown below

  1. Kubernetes Master Node IP address: 172.31.4.36 Hostname: k8-master
  2. Kubernetes Slave Node 1 IP address: 172.31.4.170 Hostname: k8-slave
  3. Kubernetes Slave Node 2 IP address: 172.31.10.30 Hostname: k8-slave2

In addition, ensure that your system has the following minimum requirements.

  1. 2 CPUS
  2. 4 GB RAM
  3. 8 GB free Hard disk space

Let’s now dive in and get started.

Step 1. Setting up hostname & Updating hosts file

To start off, you are going to log in the Master Node via SSH and set up the hostname as shown

On the slave nodes run the following commands

Using your favorite text editor, make the following modifications in the /etc/hosts file for each of the 3 Nodes i.e k8-master, k8-slave and k9-slave2 respectively.

Step 2. Installing Docker on Master and Slave Nodes

To install docker on the Master node, first, update and upgrade the system using the command below

Next, install Docker both on the Master and Slave nodes using the following command

Output

Once Docker is successfully installed, start and enable Docker service on both the Master and slave nodes using the commands below.

To verify that docker is running, issue the command on the master and slave Nodes

To view the Docker version that you’ve just installed run

Step 3. Configuring Kubernetes repository on Master & Slave nodes

Before going to the next step, We need to install some useful packages. run the following commands on all the nodes

Output

Next, add the Kubernetes package repository key by executing the command below

Next, add the Kubernetes repository using the command below.

Output

NOTE:

Kubernetes package repository for Ubuntu 18.04 LTS is not available. Nevertheless, We have used the Xenial Kubernetes package repository.

Step 4. Disabling swap and installing kubeadm

We are going to install kubeadm package to allow us to deploy multiple nodes on our cluster.

But before we do so, Kubernetes Offical site recommends disabling the OS swap feature. To accomplish this run the following command.

you can now install the kubeadm package as follows.

Output

Upon successful installation of kubeadm package, verify its version using the command below

Output

Step 5. Starting Kubernetes Cluster using Kubeadm

On the Master node, log in and initialize kubernetes using kubeadm as shown.

Sample output

The output above is a confirmation that we have successfully initiated the Kubernetes Master node To start the cluster, execute the commands enclosed inside the green highlight, one after the other

Now we are going to verify the status of the Master node by running the command below.

At this point, you will get a prompt that the Master Node is not ready because we have not yet deployed any pod. In the next step, we are going to deploy a pod network which is the network that our cluster nodes will be able to communicate with each other. To accomplish this, we are going to deploy Flannel as our pod network. Flannel is going to provide an overlay network between cluster nodes

Step 6. Deploying Flannel as the pod network

To deploy the pod network, run the following command in the Master node

Sample output

At this point, we can now verify the status of the Master Node using the kubectl command

As seen above, the Master node status has changed to “Ready’. In addition, verify the pod namespaces as shown.

The output above shows that all the pod namespaces are in a running state. the final step will be joining the slave nodes to the cluster.

Step 7. Adding Slave node to the cluster

In this step, we are going to log in to both slave nodes (k8-slave and k8-slave2) and execute the following command which appears hightlighted in red in Step 5

Sample output

Now head out to the Master slave and check the status of the master and slave nodes using the kubectl command

Output

The output above confirms that we have successfully added our two slave nodes to the cluster and their status, as well as the Master node, is ready!

Wonderful! We have concluded our tutorial on how to install and configure Kubernetes on Ubuntu 18.04 LTS. Your feedback is most welcome.

By admin

Leave a Reply

%d bloggers like this: