Kubernetes is a free and open-source container orchestration system that can be used to deploy and manage container. It was developed by Google and specially designed for autoscaling and automated deployments. Kubernetes can run on any cloud infrastructure and bare metal. Kubernetes enables you to distribute multiple applications across a cluster of nodes. Kubernetes comes with a rich set of features including, Self-healing, Auto-scalability, Load balancing, Batch execution, Horizontal scaling, Service discovery, Storage orchestration and many more..
Prerequisites
Two servers with Ubuntu 18.04 installed.
Minimum 2 GB of RAM installed on each server.
A root password is configured on both servers./li>
Getting Started
First, you will need to update both servers with the latest stable version. You can update them by running the following command:
Once both servers are updated, restart them to apply all the changes.
By default, Kuberenetes does not support swap memory and will not work if swap is active. So you will need to disable swap memory on both servers.
To disable swap memory temporary run the following command:
To disable swap memory permanently open /etc/fstab file:
Comment out the last line:
Save and close the file. Then, run the following command to apply the configuration changes:
Next, you will need to setup hostname resolution on both servers. So, each server can communicate with each other using the hostname.
To do so, open /etc/hosts/etc/hosts file using your preferred editor:
Add the following lines:
Save and close the file, when you are finished. Then, proceed to the next step.
Install Docker And Kubernetes
Next, you will need to install Docker and Kubernetes tool kubelet, kubeadm, and kubectl on both servers.
First, install required packages and add GPG key with the following command:
Next, add Docker CE repository on both servers by running the following command:
Next, update the repository and install Docker CE with the following command:
Once the installation is completed, check the status of Docker CE with the following command:
You should see the following output:
Kubernetes packages are not available in the Ubuntu 18.04 default repository. So, you will need to add the Kubernetes repository on both servers.
You can add it with the following commands:
Next, update the repository and install Kubernetes packages with the following command:
Once all the packages are installed, you can proceed to configure Master server.
Configure Kubernetes Master Server
First, you will need to initialize your cluster with its private IP address on the Master server:
You can do it with the kubeadm command:
Once the Cluster initialized successfully, you should see the following output:
Next, you will need to configure the kubectl tool on your Master server. You can do it with the following command:
Next, you will need to deploy a Container Networking Interface (CNI) on your server. Because, the cluster does not have a CNI.
You can deploy the CNI to your cluster with the following command:
You should see the following output:
You can now check your namespaces by running the following command:
If everything goes fine, you should see the following output:
Next, verify whether the master node is now running properly with the following command:
You should see the following output:
Add Slave to the Kubernetes Cluster
Next, log in to your slave server and run the following command to add the slave to the Kubernetes cluster:
Next, go to the master server and check whether the slave is added to your Kubernetes cluster with the following command:
You should see the following output:
Once you are finished, you can proceed to the next step.
Deploy NGINX on the Kubernetes Cluster
Kubernetes cluster is now installed, configured and working properly. It's time to deploy Nginx on the Kubernetes cluster.
Go to the Master server and create an Nginx deployment with the following command:
You can now list the Nginx deployment with the following command:
You should see the following output:
Once the Nginx has been deployed, the application can be exposed with the following command:
You can now see a new Service and ClusterIP address assigned with the following command:
You should see the following output:
Congratulations! you have successfully deployed Nginx on Kubernetes cluster. You can also add another node to the Kubernetes cluster easily. For more information, refer the Kubernetes official doc at Kubernetes Doc. Feel free to ask me if you have any questions.
Originally published October 28, 2019
Latest update October 27, 2019