How to build a High-Availability Cluster using EKS without having to be an expert in managing Kubernetes clusters?

Reading Time: 9 minutes

As end users of web applications, we always expect that the applications must be available 24/7. And to make it possible, developers are expected to keep deploying new versions of these applications several times a day!! Yes, you read it right! What can help developers to make it possible? The answer is Containerization!! In this blog, we will discuss how Containerization can help in High Availability! 

Kubernetes is one of the widely accepted tools that help developers in making sure these containerized applications run where and when they want and help them find the resources and tools they need to work. Amazon Elastic Kubernetes Service (Amazon EKS) gives the flexibility to start, run, and scale Kubernetes applications in the AWS cloud or on-premises. Let’s explore Kubernetes and Amazon EKS in this blog.

In this blog, we will cover:

  • What is Container orchestration? 
  • What are the Container orchestration tools?
  • How to choose right Container orchestration tool?
  • Kubernetes – an open-source container-orchestration system
  • Amazon Elastic Container Service (ECS) 
  • Companies using Amazon EKS
  • Hands-On – How to launch a fully managed EKS cluster in a few minutes using eksctl 

What is Container orchestration? 

Modern software development is no longer monolithic. Instead, it creates component-based applications that reside inside multiple containers. Container orchestration is about managing the life cycles of containers in large and dynamic environments. Software teams use container orchestration to control and automate many tasks including:

  • Provisioning and deployment of containers
  • Availability and redundancy of containers
  • Moving containers from one host to another in the situation like a host dies or there is a storage of resources
  • Allocation of resources between containers
  • Scaling up or removing containers to spread application load evenly across host infrastructure
  • Health monitoring of containers and hosts
  • External exposure of services running in a container with the outside world
  • Load balancing of service between containers

What are the Container orchestration tools?

When complex systems are developed as containers, proper organization and prioritization are required when clustering them for deployment. This role can be played by Container Orchestration tools! There are many tools available in the market as shown in the below image:

Container orchestration tools

Advantages of using Container orchestration tools:

  • Adaptability and portability
  • Higher scalability
  • Effortless deploying and managing
  • Availability and redundancy.
  • Stabler virtualization of OS resources
  • Handles load evenly across the system
  • Improved networking within the application

How to choose the right container orchestration tool?

Before deploying software into containers, the question is about which software container, and complimentary set of container orchestration tools, an organization should adopt. Options such as Kubernetes, Swarm, Cloud Foundry and Mesos make strong arguments for themselves so the container technology landscape is a difficult one to navigate.

Kubernetes has been compared favorably with other container orchestration solutions before, with one of its big selling points the vendor-agnostic nature of its open source availability. Kubernetes is extremely popular within DevOps communities because tools like Docker offer Kubernetes as Platform as a Service (PaaS) or infrastructure as a Service (IaaS). In this blog, we will be discussing Kubernetes. We will also discuss the Amazon Elastic Kubernetes Service (Amazon EKS). 

Kubernetes – an open-source container-orchestration system

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

It is developed by Google as an offshoot of its Borg project, Kubernetes has established itself as the de facto standard for container orchestration. It’s the flagship project of the Cloud Native Computing Foundation, which is backed by such key players as Google, Amazon Web Services (AWS), Microsoft, IBM, Intel, Cisco, and RedHat.

Kubernetes Basics Modules

Kubernetes Basics Modules

Key Features of Kubernetes:

  • Automated deployment, rollouts, and rollbacks
  • Automatic scalability and controllability
  • Isolation of containers.
  • Ability to keep track of service health
  • Service discovery and load balancing
  • It works as a platform providing service

Advantages of Kubernetes:

  • Provide complete enterprise-level container and cluster management services
  • Adjust the workload without redesigning the application
  • Cost Effective
  • Provide flexibility in deploying and managing
  • Enhanced portability due to container isolation

Many cloud providers use Kubernetes to give managed solutions as it’s the current standard for container orchestration tools. In this blog, we will discuss Kubernetes managed solution by Amazon – Elastic Container Service (ECS).

Amazon Elastic Container Service (ECS) 

EKS makes it easy to standardize operations across every environment. You can run fully managed EKS clusters on AWS. 

You can have an open source, proven distribution of Kubernetes wherever you want for consistent operations with Amazon EKS Distro. 

You can host and operate your Kubernetes clusters on-premises and at the edge with AWS Outposts and AWS Wavelength, and have a consistent cluster management experience with Amazon EKS Anywhere as shown in the image below

Amazon EKS

You can run fully managed EKS clusters on AWS. You can have an open source, proven distribution of Kubernetes wherever you want for consistent operations with Amazon EKS Distro. 

 Amazon EKS

Companies using Amazon EKS

Companies using Amazon EKS

Hands-on

In this hands-on, we will use eksctl command line tool to launch a fully managed EKS cluster within a few minutes.

The following image is the overall flow of the implementation:

Amazon EKS

What is eksctl?

eksctl is a simple CLI tool for creating clusters on EKS – Amazon’s new managed Kubernetes service for EC2. It is written in Go, uses Cloudformation, was created by Weaveworks and it welcomes contributions from the community.

Let’s set up a workstation from where we can access our EKS cluster. Here, we are using an EC2 instance.

We need to install below components in workstation machine:

kubectl – A command line tool for working with Kubernetes clusters. This implementation requires version 1.17 or later. 

  • Download the Amazon EKS vended kubectl binary for your cluster’s Kubernetes version from Amazon S3

https://amazon-EKS.s3.us-west-2.amazonaws.com/1.17.12/2020-11-02/bin/linux/amd64/kubectl

IAM Authentication with kubectl
  • Type the following commands to install kubectl:

curl -o kubectl 

  • Apply execute permissions to the binary.

chmod +x ./kubectl

  • Copy the binary to a folder in your PATH. If you have already installed a version of kubectl, then we recommend creating a $HOME/bin/kubectl and ensuring that $HOME/bin comes first in your $PATH.

mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin

  • Add the $HOME/bin path to your shell initialization file so that it is configured when you open a shell.

echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc

  • After you install kubectl , you can verify its version with the following command:

kubectl version --short --client

eksctl– A command line tool for working with EKS clusters that automates many individual tasks. This implementation requires version 0.38.0 or later.

Required IAM permissions – The IAM security principal that you’re using must have permissions to work with Amazon EKS IAM roles and service linked roles, AWS CloudFormation, and a VPC and related resources.

Open IAM console and click Create role button as shown in the below screenshot

Select EKS, as shown in the below screenshot

Select the EKS cluster and click Next permissions button, as shown below:

Provide a role Name and then click Create role button, as shown in the below screenshot

We need to attach more policies to our EKS-role since it will be managing worker nodes and other services.

Go to the role and click attach policies button, as shown below:

Select the following policies by searching the EKS keyword in the search button, as shown below:

Click the Attach Policy button as shown in the above image.

Now, let’s start building our very first cluster using eksctl

First, we will need to create a configuration file that will have all the necessary data required for creating a cluster.

Create a config file named cluster.yaml, as shown in the below screenshot:

You’ll need to create a SSH key for your nodegroup instances. Follow the below commands to generate one quickly.

Run the following commands, as shown below:

·         ssh-keygen

·         enter name as ec2_id_rsa

Copy it to the path following path, as shown below:

cp ec2_id_rsa.pub ~/.ssh/ec2_id_rsa.pub

Run below command:

eksctl create cluster -f cluster.yaml

Now wait for a few minutes, AWS is creating your cluster and it will take approximately 10-15 mins to be ready. Below are the sample screenshots for reference:

You can see in the above image, that the cluster is successfully created. 

Let’s go to the AWS console and verify:

Go to EKS > Cluster, as shown below. We can see our cluster is created successfully.

Go to Cloudformation > Stacks, as shown below. We can see three stacks have been automatically configured by eksctl.

Go to EC2 console > Instances, as shown below. We can see two instances have been launched.

Let’s get back to our workstation and perform some kubectl commands to interact with our cluster.

Type the below command, as shown below:

kubectl get nodes

Type the below command to see cluster information, as shown below:

kubectl cluster-info

As we can see our cluster is ready and successfully deployed.

Let’s deploy a sample application to verify and test our cluster. Here we are using the application provided by Kuberenetes.io on their official website.  Below is the link to access the application code

https://kubernetes.io/docs/tutorials/stateless-application/guestbook/

Let’s clone this application from the GitHub repo. Below is the command for cloning:

git clone https://github.com/kubernetes/examples.git

Type the below command to deploy the application:

kubectl create -f guestbook/all-in-one/guestbook-all-in-one.yaml

NOTE: In the guestbook-all-in-one.yaml, change the type to load balancer to access the application via loadbalancer service, refer below image:

Type the following command to list all the services created:

kubectl get svc

In the above image, we can see the load balancer address under the external ip column.

Let’s access the application via load balancer: 

Yeah, the application is deployed successfully!!!

We have successfully created an EKS cluster and launched a demo application.

Let’s submit some messages to check the service’s status. As shown below, click submit after the message.

Close the browser and open again. Type the loadbalancer address and see the results. We can see data is persisted and our application is running smoothly, as shown below.

Let’s delete our cluster,if not needed, to keep our credit bills low. Type the following command in the terminal:

eksctl delete cluster -f cluster.yaml

Reference image when the cluster is deleted successfully:

Conclusion

In this blog, we have explored K8s and AWS EKS. We have successfully created a fully managed K8s cluster using AWS EKS service and learnt how to deploy a sample application in K8s. We will discuss more on EKS security & other advanced features and its other implementations in our upcoming blogs. Stay tuned to keep getting all updates about our upcoming new blogs on AWS and relevant technologies. 

Meanwhile …

Keep Exploring -> Keep Learning -> Keep Mastering

This blog is part of our effort towards building a knowledgeable and kick-ass tech community. At Workfall, we strive to provide the best tech and pay opportunities to AWS-certified talents. If you’re looking to work with global clients, build kick-ass products while making big bucks doing so, give it a shot at workfall.com/partner today.

Back To Top