LinuxTutorialsUbuntu

How To Install Kubernetes on Ubuntu 18.04 LTS

Install Kubernetes on Ubuntu 18.04 LTS

In this tutorial, we will show you how to install Kubernetes on Ubuntu 18.04 LTS. For those of you who didn’t know, Kubernetes is a free and open-source container management system that provides a platform for deployment automation, scaling, and operations of application containers across clusters of host computers. With Kubernetes, you can freely make use of the hybrid,on-premise, and public cloud infrastructure in order to run the deployment tasks of your organization.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Kubernetes on a Ubuntu 18.04 (Bionic Beaver) server.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 18.04 (Bionic Beaver).
  • It’s recommended that you use a fresh OS install to prevent any potential issues
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, you can harm your system if you’re not careful when acting as the root.

Install Kubernetes on Ubuntu 18.04 LTS Bionic Beaver

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

sudo apt update
sudo apt upgrade

Step 2. Installing Docker.

Now we have to install Docker because Docker images will be used for managing the containers in the cluster. Run the following commands:

sudo apt install docker.io

Once the Docker is installed ensure that it is enabled to start after reboot:

sudo systemctl enable docker 
sudo systemctl start docker

Step 3. Installing Kubernetes on Ubuntu.

First, add the Kubernetes signing key on both the nodes:

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add

Next, add Xenial Kubernetes Repository on both the nodes:

sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"

Step 4. Installing Kubeadm.

The final step in the installation process is to install Kubeadm on both the nodes through the following command:

sudo apt install kubeadm

Check the version number of Kubeadm and also verify the installation through the following command:

kubeadm version

Step 4. Kubernetes Deployment.

First, disable swap memory (if running) on both nodes:

sudo swapoff -a

Next, give hostnames to each node:

sudo hostnamectl set-hostname master-node
sudo hostnamectl set-hostname slave-node
  • Initialize Kubernetes on the master node:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

You can check the status of the master node by running the following command:

kubectl get nodes
  • Deploy a Pod Network through the master node:

A pod network is a medium of communication between the nodes of a network:

sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Use the following command in order to view the status of the network:

kubectl get pods --all-namespaces

Now when you see the status of the nodes, you will see that the master node is ready:

sudo kubectl get nodes

Next, add the slave node to the network in order to form a cluster:

sudo kubeadm join 192.168.100.6:6443 --token 06tl4c.oqn35jzecidg0r0m --discovery-token-ca-cert-hash sha256:c40f5fa0aba6ba311efcdb0e8cb637ae0eb8ce27b7a03d47be6d966142f2204c

Now when you run the following command on the master node, it will confirm that two nodes, the master node, and the server nodes are running on your system:

sudo kubectl get nodes

Congratulations! You have successfully installed Kubernetes. Thanks for using this tutorial for installing Kubernetes on Ubuntu 18.04 systems. For additional help or useful information, we recommend you check the official Kubernetes website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button