Blog

Blog

Building A Kubernetes App With Amazon EKS

Building A Kubernetes App With Amazon EKS

image 77

Building A Kubernetes App

Its common knowledge that Amazon Web Services(AWS) is a well-known provider of cloud services, while Kubernetes is quickly becoming the standard way to manage application containers in the production environment. While many developers would gladly use Kubernetes, the time-consuming cluster management process can be a turnoff. As a solution, developers can use Amazon Elastic Container Service for Kubernetes (Amazon EKS), which allows them to create Kubernetes clusters in the cloud very quickly and easily.

Let’s take a look at the topics covered in this article:

  1. Amazon EKS & its Benefits
  2. How does Amazon EKS work?
  3. Build a Kubernetes app with Amazon EKS

Let’s get started!

Amazon EKS 

Though containers have been around since the early days of Linux, Docker introduced the modern version of this technology. Kubernetes is open-source software that allows you to deploy and manage containerized applications at scale. It also provides portability and extensibility, enabling you to scale containers seamlessly. But, the downside of Kubernetes is that it takes a lot of time to deploy a cluster with a master and worker nodes. A turnaround for this is Amazon EKS.

Amazon Elastic Container Service for Kubernetes(Amazon EKS)

ekslogo -Amazon EKS - Edureka

Amazon Elastic Container Service for Kubernetes (Amazon EKS) is a managed service that makes it easy for users to run Kubernetes on AWS without needing to stand up or maintain their own Kubernetes control plane. Since Amazon EKS is a managed service it handles tasks such as provisioning, upgrades, and patching. 

Definition aside, let’s take a look at the benefits of Amazon EKS:

  • Amazon EKS runs the Kubernetes management infrastructure across multiple AWS Availability Zones, thereby freeing users from maintaining the Kubernetes control plane.
  • Infrastructure running on Amazon EKS is secure by default by setting up a secure and encrypted communication channel between worker nodes & Kubernetes endpoint.
  • AWS actively works with the Kubernetes community and makes contributions to the Kubernetes code base.
  • Applications managed by Amazon EKS are fully compatible with applications managed by any standard Kubernetes environment.

Kubernetes On AWS | AWS EKS Tutorial

This will help you understand how to deploy a containerized application onto a Kubernetes cluster managed by Amazon Elastic Container Service for Kubernetes (Amazon EKS).

So, the above reasons are convincing enough to start using Amazon EKS. Now, let’s take a look at how Amazon EKS actually works.

How does Amazon EKS work?

Working - Amazon EKS -Edureka

Getting started with Amazon EKS is easy fairly easy:

  1. First, create an Amazon EKS cluster in the AWS Management Console or with the AWS CLI or one of the AWS SDKs
  2. Then, launch worker nodes and enable them to join the Amazon EKS cluster which you created earlier
  3. When your cluster is ready, you can configure your favorite Kubernetes tools to communicate with your cluster
  4. Deploy and manage applications on your Amazon EKS cluster the same way that you would with any other Kubernetes environment

Now, let’s see how to deploy a containerized application onto a Kubernetes cluster using Amazon Elastic Container Service for Kubernetes.

Deploy a Kubernetes Application with Amazon EKS

Demo: In this demo, we will see how to launch a simple Nginx application on the Kubernetes cluster using Amazon EKS. Here are the steps you will follow:

    • Create an AWS IAM service role and an AWS VPC
    • Create an Amazon EKS cluster
    • Configure kubectl for the Amazon EKS cluster
    • Launch and configure Amazon EKS worker nodes
    • Launch a simple Nginx application
    • Cleaning up the application & assigned resources

Assumptions and Prerequisites

  • You should have an AWS account with an active subscription and be able to log in using AWS IAM account credentials.  If you don’t have either of these create an AWS account & create an IAM user in your AWS account. 
  • You should install the latest version of the AWS command-line interface (CLI), to a location in your system path. In case you haven’t, install it using these instructions.

Step 1: Create an AWS IAM service role and a VPC

 The first step is to create an IAM role that Kubernetes can assume to create AWS resources. To do this:

  • Navigate to AWS IAM Console & in the “Roles” section, click the “Create role” button
  • Select “AWS service” as the type of entity and “EKS” as the service
  • Enter a name for the service role and click “Create role” to create the role
image

Amazon EKS also requires a Virtual Private Cloud (VPC) to deploy the cluster. To create this VPC:

  • Navigate to the AWS CloudFormation console and click on “Create Stack”
  • On the “Select Template” page, select the option to “Specify an Amazon S3 template URL” and enter the URL
  • After specifying all the details, review and confirm them. Then click “Create” to proceed
image

Step 2: Create an Amazon EKS cluster

At this point, you are ready to create a new Amazon EKS cluster. To do this:

  • Navigate to the Amazon EKS console and click on the “Create cluster” button
  • Enter details into the EKS cluster creation form such as cluster name, role ARN, VPC, subnets, and security groups
  • Click “Create” to create the Amazon EKS cluster

image

Step 3: Configure kubectl for the Amazon EKS cluster

Kubernetes uses a command-line utility called Kubectl for communicating with the Kubernetes cluster. Amazon EKS clusters also require the AWS IAM Authenticator for Kubernetes to allow IAM authentication for your Kubernetes cluster. So, install both of these binaries. Instructions for downloading and setup are in the Amazon EKS documentation. 

Note: Ensure that you have at least one version of the AWS CLI installed and your system’s Python version must be Python 2.7.9 or greater. 

Next, you have to create a kubeconfig file for your cluster with the AWS CLI update-kubeconfig command as follows:

  • Use the AWS CLI update-kubeconfig command to create or update your kubeconfig for your cluster
  • Test your configuration

image

Step 4: Launch and configure Amazon EKS worker nodes

Note: Wait for your cluster status to show as ACTIVE. If you launch your worker nodes before the cluster is active, the worker nodes will fail to register with the cluster and you will have to relaunch them.

Once the control plane of your cluster has been activated, the next step is to add nodes to it. To do this:

  • Navigate to the AWS CloudFormation console and click on the “Create stack” option
  • On the “Select Template” page, select the option to “Specify an Amazon S3 template URL” and enter the URL
  • On the “Specify Details” page, enter details as shown below. Review the details and click on “Create”
  • Once stack creation is complete, select the stack name in the list of available stacks and select the “Outputs” section in the lower left pane. Make a note of Role ARN
image 1
Building A Kubernetes App With Amazon EKS 15

Now to enable worker nodes to join the Kubernetes cluster follow the below steps:

  • On your local system, create a file named aws-auth-cm.yaml and fill it with the content below. Replace the AWS-ARN with the node instance role that you copied from the stack output earlier
image 2
Building A Kubernetes App With Amazon EKS 16
  • Apply the configuration. This command may take a few minutes to finish.
  • Watch the status of your nodes and wait for them to reach the Ready state
image 3
Building A Kubernetes App With Amazon EKS 17

Step 5: Launch a simple Nginx application

To create an application you need to create a Kubernetes object of type Deployment. On your local system, create a file named nginx.yaml and fill it with the content below.

Now, as a backup for the application, you also need to create a Kubernetes object of Service type. A Kubernetes Service is an abstraction that defines a logical set of Pods running somewhere in your cluster, that all provide the same functionality as the ones that you created earlier. On your local system, create a file named nginx.yaml and fill it with the content below. 

image 4
Building A Kubernetes App With Amazon EKS 18
  • Create the Nginx application and Nginx service
  • List the running services and capture the external IP address & port
  • After your external IP address is available, point a web browser to that address at the respective port to view your Nginx application
image 5
Building A Kubernetes App With Amazon EKS 19
image 6
Building A Kubernetes App With Amazon EKS 20

Congratulations! Now you know how to deploy a containerized application onto a Kubernetes cluster using Amazon Elastic Container Service(Amazon EKS).

Step 6: Cleaning up the application & assigned resources

When you are finished experimenting with your application, you should clean up the resources that you created for it to avoid incurring unnecessary costs. You can do so using the following commands:

image 7
Building A Kubernetes App With Amazon EKS 21

I hope now you have a basic idea of what Amazon EKS is and how to use it to create and launch containerized applications on a Kubernetes cluster.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare

Subscribe to Newsletter

Stay ahead of the rapidly evolving world of technology with our news letters. Subscribe now!