The Kubernetes Current Blog

Getting started with Amazon Elastic Kubernetes Service (EKS)

Amazon Elastic Kubernetes Service (Amazon EKS) is a managed Kubernetes to deploy, scale and monitor containerized applications on AWS. Amazon EKS auto-scales worker nodes, including the API servers and back-end persistence layer, across multiple AWS availability zones for high availability and fault tolerance. It automatically detects and replaces unhealthy worker nodes and provides patching for the control plane. Amazon EKS removes some of the operational burden for developers and administrators.

Overview

This guide is designed to help you get started with Amazon EKS, and covers the following:

  • Prerequisites
  • Deploying a Sample Microservices-based Application
  • Configuring  Continuous Delivery (CD)
  • Building a Code Change
  • Scaling Applications On-Demand

Initially, you will setup a sample Node.js application on EKS cluster.

Pre-requisites

Before starting, make sure you have the following prerequisites. This guide helps you to setup from a Linux terminal.

1. Install an EC2 instance with Kubectl and Kublet binaries.

Prerequisits 1

2. Attach an IAM role with ‘Administrator’ access to the EC2 instance. For example, create a role “eksworkshop-admin” role and attach it to the EC2 instance where you have installed Kubectl.

Prerequisits 2

 

3. Select the EC2 instance. Go to Actions -> Instance Settings -> Attach and Replace IAM Role.

Prerequisits 3

 

4. Select the IAM role “eksworkshop-admin” -> Apply.

Prerequisits 4

 

5. Configure the Bash Profile with AWS Account ID and Region. For example:

Prerequisits 5

 

 

Basic Setup

To begin the basic setup, fork a Node.js sample application on GitHub and clone the repository to your local environment. required This is so you can deploy and make modifications to the application. Then you can launch an EKS cluster.

1. On GitHub, fork a Github repository by clicking on the top-right corner button on the page.
Basic Setup

Basic Setup 1

2. Copy the URLs from GitHub.

Basic Setup 2

 

3. Next, execute the commands below on your local machine to checkout the sample application and go to the new directory.

Basic Setup 3

 

Now, you have a local copy of the GitHub repository on which you can you can make modifications and deploy. Next, setup the EKS cluster.

4. First, download the eksctl binary:

Now Local Copy 1

 

5. Confirm the eksctl command is working:

Now Local Copy 2

 

6. Create an EKS cluster:

Now Local Copy 3

 

7. Test the cluster by getting the values of nodes.

Now Local Copy 4

 

8. Check the status of the Cluster on the AWS Console.

Now Local Copy 5

Congratulations! You have setup a fully working Amazon EKS cluster that can host a micro services-based application.

 

Get Familiar with the Kubernetes Dashboard

The Kubernetes Dashboard in AWS is not available by default. To gain access to it:

  1. Deploy the dashboard by executing the following command:Get familiar with Kubernetes Dashboard 1aGet familiar with Kubernetes Dashboard 1b
  2. The dashboard is then deployed in your private cluster. You will need to access it via proxy. Kube-proxy is available to proxy requests to the dashboard service by running the following command:Get familiar with Kubernetes Dashboard 2aGet familiar with Kubernetes Dashboard 2b
  3. To access the dashboard, open ingress port 8080 in security groups of the EC2 instance.Get familiar with Kubernetes Dashboard 3
  4. On your browser open the link and, on the terminal, generate a token to login.Get familiar with Kubernetes Dashboard 4
  5. Login to the Kubernetes dashboard by the generated token.Get familiar with Kubernetes Dashboard 5
  6. Congratulations!  You have successfully installed a Kubernetes Dashboard.Get familiar with Kubernetes Dashboard 6

Deploying a Sample Microservices-based Application

Now, you will setup a Nodejs application to the EKS cluster using the CLI interface.

  1. To bring up the NodeJS Backend API, run the following commands on your  EC2 command line:Deploying a Sample Microservices-based Application 1aTo watch the status of the deployment:Deploying a Sample Microservices-based Application 1b
  2. To bring up the Crystal Backend API, run the following commands.Deploying a Sample Microservices-based Application 2
  3. Ensure the ELB service role exists:Deploying a Sample Microservices-based Application 3a
  4. To bring up the ruby front-end service, run the following commands.Deploying a Sample Microservices-based Application 4
  5. Now, you have a running service. However you need to find the ELB’s address to access the web page.Deploying a Sample Microservices-based Application 5
  6. This confirms that you have successfully deployed a nodejs app Amazon EKS.Deploying a Sample Microservices-based Application 6

Configure Continuous Delivery (CD)

In an AWS CodePipeline, you are going to use AWS CodeBuild to deploy a sample Kubernetes service. This requires an AWS Identity and Access Management (IAM) role capable of interacting with the EKS cluster.

In this step, you will create an IAM role and add an inline policy that will be used in the CodeBuild stage to interact with the EKS cluster via kubectl.

Setting up the CD Pipeline

  1. Create an IAM role by running the following commands:Configure CD- Setting Up CD Pipeline 1aConfigure CD- Setting Up CD Pipeline 1b
  2. Now that the IAM role is created, add the role to the AWS-auth ConfigMap for the EKS cluster. Once the ConfigMap includes this new role, kubectl in the CodeBuild stage of the pipeline will be able to interact with the EKS cluster via the IAM role.Configure CD- Setting Up CD Pipeline 2aConfigure CD- Setting Up CD Pipeline 2b
  3. Fork a sample Kubernetes GitHub repository so that you can modify the repo and trigger builds. Login to GitHub and fork the repo to your own account:Configure CD- Setting Up CD Pipeline 3aConfigure CD- Setting Up CD Pipeline 3b
  4. In order for CodePipeline to receive callbacks from GitHub, you will need to generate a personal access token.Configure CD- Setting Up CD Pipeline 4
  5. Copy the personal access token and save it in a secure place for the next step.Configure CD- Setting Up CD Pipeline 5
  6. Next, you will create the AWS CodePipeline using AWS CloudFormation. CloudFormation is an infrastructure as code (IaC) tool that provides a common language for you to describe and provision all the infrastructure resources in your cloud environment. CloudFormation allows you to use a simple text file to model and provision, in an automated and secure manner, all the resources needed for your applications across all regions and accounts.Use the following template to create the CloudFormation stack in the AWS Management Console.Configure CD- Setting Up CD Pipeline 6
  7. After the console is open, enter your GitHub username, personal access token (created in the previous step), check the acknowledge box and then click the “Create stack” button located at the bottom of the page.Configure CD- Setting Up CD Pipeline 7
  8. Wait for the status to change from “CREATE_IN_PROGRESS” to CREATE_COMPLETE before moving on to the next step.Configure CD- Setting Up CD Pipeline 8
  9. Open CodePipeline in the Management Console. You will see a CodePipeline that starts with eks-workshop-codepipeline. Click this link to view the detailsConfigure CD- Setting Up CD Pipeline 9
  10. Congratulations! You have successfully built the CI/CD pipeline for Amazon EKS.Configure CD- Setting Up CD Pipeline 10

 

Building a Code Change

Next, push the modified code to the application.

  1. On your local desktop, use an editor to modify the GitHub code for the file (eks-workshop-sample-api-service-go/main.go
  2. Make some changes that will be visible from your application. For instance, change the title on line 17:Building a Code Change 2
  3. Commit the changes to GitHub and push the changes to master.
  4. If your webhooks are configured correctly, your eks Codepipeline project will rebuild and deploy itself. To view the Automated builds, check the history.Building a Code Change 4
  5. Validate changes by clicking on the ELB URL in your browser and refresh to confirm the update.

 

Scaling Applications On-Demand

You will now add additional pods to your Node.js service to accommodate additional traffic volumes.

  1. To scale the backend services, run the following command:Scaling Apps on Demand 1
  2. To scale the frontend services, run the following command:Scaling Apps on Demand 2

Conclusion

In this guide, we have seen how easy it is to build, deploy and scale a Nodejs application using Amazon EKS. But this is just the first part of your Application Lifecycle Journey. There are plenty more steps involved. In the next installment, we’ll dig deeper to help you understand how Rafay and Amazon EKS work together.

Author

Tags:
Amazon Elastic Kubernetes Service , AWS , Cluster Management , Containers , EKS , Getting Started Guides , Kubernetes

Trusted by leading companies