Installing Kubernetes on AWS EC2

Learn the basics of Kubernetes installation in this step-by-step tutorial of how to deploy cluster nodes of Kubernetes on AWS free tier ec2 instance and we will us t2.micro with Ubuntu 18+ operating system instance.

Image for post
Image for post

Kubernetes

· Open source container-orchestration system to automate deploying, scaling, and operating applications of Containers.

· Kubernetes run group or cluster/nodes of virtual machines in a given schedule. Deploy a multi-host container with scheduling through Kube-scheduler. Check resources, policies, and specifications before scheduling.

· Scaling and Availability

· Can be deployed in a highly available environment.

· Multi-region deployment

· Kubernetes works on its own Network called Pod Network

AWS - Amazon Web Services

AWS is an On-Demand Cloud platform provided by Amazon offering a mixture of infrastructure as a service (IaaS), platform as a service (PaaS) and packaged software as a service (SaaS).

Installation

Let’s see the Installation process of Kubernetes on AWS EC2 instance.

STEPS 1: - Launch EC2 instance

· Sign-in AWS management console, go to the AWS EC2 service.

· Before launching an instance always make sure that you are in your nearby ‘Region’ which is given at the top of the menu bar. In my case its ‘Mumbai’ you can find your nearby region from AWS global infrastructure.

· Then click on ‘Launch Instance’ highlighted at the center of the dashboard. Or you can go to instances sub menu present at the left-side menu bar, and then select Launch Instance in a blue box at the top.

· Then click on the ‘select’ option at Ubuntu image file (Free tier eligible image file of Ubuntu), in this tutorial I selected ‘Ubuntu’ AMI name as Ubuntu Server 18.04 LTS.

Image for post
Image for post

· On the next page, select ’t2.micro’ as the instance type and press ‘Configure Instance Details’.

· For more information about selecting the instance type, you should refer to the official Amazon documentation on Instance Type.

· T2.micro or T2 instances are a low-cost, general-purpose instance type that provides a baseline level of CPU performance with the ability to burst above the baseline when needed.

Image for post
Image for post

· I selected ‘Number of Instance’ 2 here. One for creating a Master node and another one is for Slave node. You may choose multiple slave nodes.

Image for post
Image for post

· Then just move on to the security group by keeping the remaining options default.

· In ‘Configure Security Group’ adds a rule type ‘ALL traffic’ in your security group. Or you can simply enter the details as per the image below. You can write anything in the ‘Security group name’ or in ‘description’. Then click on ‘Review and launch’.

Image for post
Image for post

· Next screen gives you the last step before launching your instance in your EC2 machine. ‘Review Instance Launch’ section allows you to look at all configurations before launching the EC2 instance. If you found everything ok as per given data, then click on the ‘Launch’ button given at the bottom of the screen.

Image for post
Image for post

· In the next step, it will ask you to create Key or use the existing one for connecting EC2 instance. In my case, I created a new one.

· ‘Download Key Pair’ before clicking on ‘Launch Instance’.

STEPS 2: — Connect with the Instance

· You can connect it in three ways: -

1.A Standard SSH connection

2.Session Manager

3.EC2 Instance Connect (browser-based SSH connection)

· Although all ways are secure and have their own advantages. But the easiest way to connect is through the ‘EC2 Instance Connect (browser-based SSH connection)’ connection which will open connection at your browser.

· I used Putty as ‘A Standard SSH Connection’ for both instances. Putty is a lightweight software for SSH connection.

Image for post
Image for post

· Here I used 172.31.43.114 as Master node and 172.31.36.135 as Slave Node.

Image for post
Image for post

STEPS 3: — Install/update Dependencies

Run Following Command: the following commands will install Docker container, curl, keys, Kubernetes, resources, and some Kubernetes tools.

# update operating system
sudo apt-get update

# Docker dependencies
sudo apt-get install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker

# ‘curl’ command is used to send request URL
sudo apt-get install -y curl

# download an add-key for Kubernetes from URL
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add

# add important dependencies for kubernetes
sudo chmod 777 /etc/apt/sources.list.d/
sudo cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF

# update dependencies
sudo apt-get update

# Installing kubeadm, kubelet and kubectl
sudo apt-get install -y kubelet kubeadm kubectl kubernetes-cni

sudo swapoff -a

You can get all above command in a single bash file from here. Then run file by the command: sudo bash Kubernetes-installation-Ubuntu18.0.sh

Why kubeadm, kubelet and kubectl?

· kubeadm: the command to bootstrap the cluster.

· kubelet: the component that runs on all of the machines in your cluster and does things like starting pods and containers.

· kubectl: the command line utile to talk to your cluster.

STEPS 4: - Initializing the Control plane node

After the installation of Kubernetes we have to initialize kubernetes so that all nodes or slaves node can able to connect with the master or control plane node. Kubernetes works on its own Network called Pod Network

Run Commands on Master Node terminal

· sudo kubeadm init

Image for post
Image for post

· In case if you get an above-highlighted warning, then run following command below, OR

You can get all above command in a single bash file from here. Then run file by the command: sudo bash Kubernetes-installation-Ubuntu18.0.sh

# (Install Docker CE)
## Install packages to allow apt to use a repository over HTTPS
apt-get update && apt-get install -y \
apt-transport-https ca-certificates curl software-properties-common gnupg2

# Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

# Add the Docker apt repository:
add-apt-repository \
“deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable”

# Install Docker CE
apt-get update && apt-get install -y \
containerd.io=1.2.13–2 \
docker-ce=5:19.03.11~3–0~ubuntu-$(lsb_release -cs) \
docker-ce-cli=5:19.03.11~3–0~ubuntu-$(lsb_release -cs)

# Set up the Docker daemon
cat > /etc/docker/daemon.json <<EOF
{
“exec-opts”: [“native.cgroupdriver=systemd”],
“log-driver”: “json-file”,
“log-opts”: {
“max-size”: “100m”
},
“storage-driver”: “overlay2”
}
EOF

mkdir -p /etc/systemd/system/docker.service.d

# Restart Docker
systemctl daemon-reload
systemctl restart docker
sudo systemctl enable docker

· Run: sudo kubeadm init

Image for post
Image for post

· In case if you get above ERROR:NumCPU error, which states that Kubernetes required at least 2 CPUs core for running.

· It can be simply ignored by adding --ignore-preflight-errors=NumCPU at the end of the previous command.

· sudo kubeadm init --ignore-preflight-errors=NumCPU

· After commands will execution it will give you a token that will use to connect with other nodes.

· Copy and paste the above token to other nodes terminal so that they can join or connect to the same network.

Image for post
Image for post

· After pasting token to the slave node

Image for post
Image for post

· Run following commands: , it will show all connected nodes but indiactes ‘Not Ready’

sudo mkdir -p $HOME/.kube

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

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

4. sudo kubectl get nodes

Image for post
Image for post

· Because we didn’t provide any network to the nodes, so it will show status NotReady.

STEPS 4: — Providing Network to the Nodes

Networking is a central part of Kubernetes, but it can be challenging to understand exactly how it is expected to work. There are 4 distinct networking problems to address:

1. Highly-coupled container-to-container communications: this is solved by Pods and localhost communications.

2. Pod-to-Pod communications

3. Pod-to-Service communications

4. External-to-Service communications

Kubernetes is all about sharing machines between applications. Sharing machines requires different ports. Every Pod gets its own IP address

There are a number of ways that the network model can be implemented.

· ACI

· Antrea

· AOS from Apstra

· AWS VPC CNI for Kubernetes

· Azure CNI for Kubernetes

· Big Cloud Fabric from Big Switch Networks

· Cilium

· CNI-Genie from Huawei

· cni-ipvlan-vpc-k8s

· Contiv

· Contrail / Tungsten Fabric

· DANM

· Flannel

· Google Compute Engine (GCE)

· Jaguar

· k-vswitch

· Knitter

· Kube-OVN

· Kube-router

· L2 networks and Linux bridging

· Multus (a Multi-Network plugin)

· OVN4NFV-K8s-Plugin (OVN based CNI controller & plugin)

· NSX-T

· Nuage Networks VCS (Virtualized Cloud Services)

· OpenVSwitch

· OVN (Open Virtual Networking)

· Project Calico

· Romana

· Weave Net from Weaveworks

In this tutorial we will use Flannel as a network channel for nodes. You can read more about Flannel from here.

Run the following command into the terminal to install Flannel network

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

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

Image for post
Image for post

Conclusion

You now have a basic grasp about Kubernetes, Kubernetes tools, and how to install it in Linux operating system. However, we’ve only just scratched the surface information about Kubernetes during this installation process.

References

· kubeadm Installation doc

· AWS

· Flannel

· Wikipedia

A Request from Writer:

Hi, I am Ayush Sharma in case if you find any mistake or if I inadvertently put something wrong, personal, or copyright data in my blog. Feel free to drop me your suggestions or requests to change at infoatayush@gmail.com. I will confirm and update it immediately.

Written by

❤Blogger❤ब्लॉगर❤بلاگر❤المدون❤ブロガー❤博主❤ব্লগার❤બ્લોગર❤ಬ್ಲಾಗರ್❤ബ്ലോഗർ❤ବ୍ଲଗର୍❤பதிவர்❤బ్లాగర్❤ਬਲੌਗਰ❤بلاگر❤

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store