How to Install Kubernetes cluster on an Ubuntu VPS

Do you want to learn how to set up Kubernetes on Ubuntu? Keep reading this article!

Kubernetes is a powerful open-source platform for automatic scaling, deployment, and management of containerized systems. It’s a robust application that groups containers into logic units making it easy to discover and manage them across multiple clusters of hosts. Kubernetes has many pieces such as network transport drivers, various system components, and CLI utilities. The system also works with numerous container tools such as Docker and includes many moving parts and enormous workloads which makes its installation intricate.

This tutorial will show you how to quickly install kubernetes on Ubuntu with minimal to no frustration.

Additional reading: if you wish to research Kubernetes and container hosting further, we recommend the following articles:

Let’s get started.

Must Haves:

For our installation to succeed, you should have the following:

  1. At least two Ubuntu machines; one as the master and the other for worker. If you can get etcd and Apiserver on a single machine with one core and one GB RAM for clusters with at least 10s of nodes that will be enough for this installation.  On the other hand, if you intend to use more active and larger clusters consider getting more core.

Step 1: Install the dependencies

The first and the most important thing when setting up Kubernetes on Ubuntu is installing the required dependencies. The dependencies must be installed on all the machines that make your Kubernetes cluster.

One of the dependencies you need to install is the apt-transport-https. This package allows you to utilize the HTTP and HTTPS protocols in the apt repository resources. The package can be installed using the following command:

sudo apt-get update && apt-get install -y apt-transport-https

The second dependency is Docker. Docker is a reliable application that simplifies the creation and configuration of application processes in containerized systems. The Kubernetes installation will rely on Docker, and for this reason, it should be installed first. Use the following command to install Docker:

sudo apt install docker.io
Note
Special Note: Docker works best on the 64-bit Ubuntu or a kernel version greater than or equal to 3.10. For this reason, we’ll install the kubernetes on the default 64-bit Ubuntu 16.04 server. The version meets the requirements.

Once Docker is fully installed, run the following commands to start and enable the application:

sudo systemctl start docker
sudo systemctl enable docker

Step 2: Installing kubernetes components

Once the Docker is up and running, you are ready for the next step. As aforementioned, Kubernetes has many pieces and installing all the necessary components should be straightforward.

Note
Special Note: all the components should be configured on all the machine joining the clusters.

Download and incorporate the Key by running the following command at the terminal:

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

Run the command below to install kubernetes apt repo:

$ apt-get update && apt-get install -y apt-transport-https \
 && curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
$ echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list

Next, you need to update the package list using the following command:

apt-get update

Now, we install three components Kubeadm, kubelet, and kubernetes-cni. The kubeadm is a great utility that helps you configure the multiple components that form a working cluster; the Kubelet makes it easy to run the containers on the hosts, whereas the Kubernetes-cni defines the networking components. CNI or Container Networking Interface is a robust spec that dictates how network drivers interact with kubernetes.

Use the following command to install the three components:

$ apt-get update \
 && apt-get install -y kubelet kubeadm kubernetes-cni

Run kubeadm to initialize your server. Kubeadm provides a secure cluster using mechanisms such as RBAC.

Step 3: Initialize the master

Once you have installed the three components, you can proceed to initialize your master. Go to the machine you intend to use as the master and run the following command:

sudo kubeadm init

When the initialization is complete, you will get the command below which is required to join your nodes to the master:

The command above indicates your kubernetes master is ready for the nodes. But, just before you join any node to the master, run this command:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

STEP 4: Deploy a pod network

Next, you must install and configure a pod network for everything to function properly. Here we will install a Flannel pod network. Flannel offers a reliable Software Defined Network (SDN) via ipvlan modules and kernel’s overlay. Deploying Flannel can be achieved through two commands applied on the Kubernetes master. The first command:

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

The second command is:

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

Confirm the pod network is properly configured by running the following command: sudo kubectl get pods. If the Flannel pod network is properly installed, you will get the output below:

Step 5: Join a node

By now all the components are ready, and your kubernetes master is ready for node joining. Navigate to the terminal (of the node) and run the following command:

sudo kubeadm join --token TOKEN MASTER_IP:6443

This helps confirm the nodes have joined the master successfully;

Step 6: Deploy a service

At this point, everything is properly configured, and you can easily deploy a service on the kubernetes cluster. Run the command below from your Kubernetes master:

sudo kubectl run --image=nginx nginx-app --port=80 --env="DOMAIN=cluster"
sudo kubectl expose deployment nginx-app --port=80 --name=nginx-http

The command will help you deploy NGINX service exposed on port 80. Navigate to the node and issue the following command:

$sudo docker ps -a

The command will give you an output of the services deployed

Your Kubernetes is successfully installed on Ubuntu. The cluster comprises a single node and a master. However, it’s easy to scale the cluster by deploying more nodes using our instructions.

Check out the top 3 VPS services:

HostArmada
$1.79 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
IONOS
$1.00 /mo
Starting price
Visit IONOS
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.3
Ultahost
$2.90 /mo
Starting price
Visit Ultahost
Rating based on expert review
  • User Friendly
    4.3
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.0
  • Pricing
    4.8

How to Install the MEAN Stack on Your Ubuntu 17.10 Server

The article is step-to-step instruction that shows how to install the MEAN (Mong
3 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Configure Nginx and Apache on the same Ubuntu VPS or Dedicated Server

Nginx and Apache are great and powerful web servers. However, they both have dra
2 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Setup a Docker Swarm Cluster on a CentOS 7 VPS or Dedicated Server

This how-to article will help you install and configure Docker Swarm on CentOS 7
5 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How to install Django on a CentOS 7 VPS or Dedicated Server

When building a website, similar components are required, and you do not have to
3 min read
Mark Armistead
Mark Armistead
Author
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top