Installing Kubernetes for AWS in Ubuntu: step by step guide

Installing Kubernetes for AWS in Ubuntu: step by step guide

Kubernetes

images/flower.svg

Kubernetes, also known as K8s, is an open-source system for automating deployment, scaling, and management of containerized applications.

It distributes application workloads across a Kubernetes cluster and automates dynamic container networking needs. Kubernetes also allocates storage and persistent volumes to running containers, provides automatic scaling, and works continuously to maintain the desired state of applications, providing resiliency.

Prerequisites

Before moving forward there are some prerequisites that we need in place :

  1. An Ubuntu system( 18.044 or higher) ( you can use VM ).

  2. Root privileges

  3. Swap must be disabled for kubelet to work properly.

  4. Sufficient RAM and Storage ( 3.75 gb or more ram ).

So , lets move to the installation

Step 1 - Update Ubuntu

Before installing any software on the ubuntu , you must update the system packages to curent versions .

sudo apt update

sudo apt upgrade -y

Step 2 - Install Docker

Kubernetes requires an existing Docker installation. It uses Docker as the default container runtime. To install Docker on Ubuntu, run the following commands:

sudo apt install docker.io -y

Step 3 - Start and Enable docker

sudo systemctl enable docker

sudo systemctl start docker

now, verify that docker is running

sudo systemctl status docker

Step 4 - Disable Swap

Now before installing Kubernetes, it requires swap space to be disabled on your Ubuntu machine. To disable swap temporarily, execute the following command:

sudo swapoff -a

Step 5 - Install Kubernetes

As we are downloading Kubernetes from a non-standard repository, it is essential to ensure that the software is authentic. Kubernetes provides official repositories for Ubuntu. Add the Kubernetes repository and import the repository signing key with the following commands:

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

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

Step 6 - Add Software Repositories

Kubernetes is not included in the default repositories. To add them, enter the following:

echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

Step 7 - Kubernetes Installation Tools

Now, install the required Kubernetes components (kubelet, kubeadm, and kubectl) using the apt package manager. Kubernetes Admin or Kubeadm is a tool that helps initialize a cluster. Its fast-track setup by using community-sourced best practices. Kubelet is the work package, which runs on every node and starts containers. The tool gives you command-line access to clusters.

sudo apt install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl

Now verify the installation with :

kubeadm version

Step 8 - Initialize Kubernetes Master

On the machine designated as the Kubernetes master, initialize the cluster by running the following command:

sudo kubeadm init

Step 9 - Configure Kubernetes for Regular User

To run Kubernetes commands with your regular user account, enter the following to create a directory for the cluster:

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

Step 10 - Install Pod Network Add-on

To enable networking between pods in your Kubernetes cluster, you need to install a pod network add-on. One popular choice is Calico. Install Calico by running the following command:

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

Allow the process to complete.

Step 11 - Join Worker Nodes (optional)

If you have additional machines that you want to add as worker nodes to your Kubernetes cluster, run the kubeadm join command you noted in Step 6 on each worker node. This will connect them to the cluster.

Conclusion:

Congratulations! You have successfully installed Kubernetes on your Ubuntu machine. With Kubernetes up and running, you can now start deploying, managing, and scaling your containerized applications with ease. After following the steps mentioned in this article carefully, you should now have Kubernetes installed on Ubuntu. Kubernetes allows you to launch and manage Docker containers across multiple servers in the pod.

Remember to explore Kubernetes documentation and online resources to make the most of this powerful container orchestration platform.