Create an EKS Cluster with Nginx Application on AWS

A Cloud Enthusiast
Introduction
Amazon Elastic Kubernetes Service (Amazon EKS) is a managed Kubernetes service that makes it easy for you to run Kubernetes on AWS and on-premises. Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. Amazon EKS is certified Kubernetes-conformant, so existing applications that run on upstream Kubernetes are compatible with Amazon EKS.
Amazon EKS automatically manages the availability and scalability of the Kubernetes control plane nodes responsible for scheduling containers, managing application availability, storing cluster data, and other key tasks.
In this blog, I will step you through the process of deploying an nginx web server on EKS cluster.
Pre-requisites
- AWS Account
Step 1: Creating an IAM User with Admin Permissions
Go to
IAM > Usersand click on "Add users"Specify the username for example
k8s-admin, enable Programmatic access, and hit Next.Click on
Attach existing policies directlyand select theAdministratorAccesspolicy.Proceed till the end and click on
Create userCopy both Access key ID and Secret access key and save them for later use.
Step 2: Launching an EC2 Instance and Configuring the required CLI Tools
In this step, we will start by creating an EC2 instance, updating the AWS CLI version, and configuring the AWS CLI using the credentials of the user created in the previous step. We will then install both eksctl and kubectl on that EC2 instance. This instance will act as an admin workstation to run all administrative commands from.
Go to
EC2service and click onLaunch instance.Follow below instructions:
Set Name:
k8s-adminSelect AMI:
Amazon Linux 2 AMIKeep the default Instance Type
t2.microCreate new key pair with you preferred name and download it (Note: Select
.ppkformat if you are using Putty)Edit
Network Settingsand enableAuto-assign public IPKeep other settings as is and click
Launch instance
Wait till the Status check turns into
2/2 checks passedand then click onConnect. ChooseEC2 Instance Connectand press onConnectbutton to access the EC2 instance terminal.Follow the instructions from the AWS documentation here or follow the below steps to update the AWS CLI version:
- Download the latest AWS CLI version
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- Unzip the installer
unzip awscliv2.zip
- Run following to update the current version:
sudo ./aws/install --bin-dir /usr/bin --install-dir /usr/local/aws-cli --update
- Verify version is updated
aws --version

Run
aws configureand set below values:AWS Acsess Key ID and AWS Secret Access Key from previous step
Default Region name:
us-east-1Default output format:
json
Install
kubectlwith following commands:
curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.16.8/2020-04-16/bin/linux/amd64/kubectl
chmod +x ./kubectl
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
- Ensure
kubectlis installed
kubectl version --short --client
- Install and configure
eksctl
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/bin
- Ensure
eksctlis installed
eksctl version
Step 3: Provisioning an EKS Cluster
- Provision an EKS cluster with three worker nodes in
us-east-1
eksctl create cluster --name dev --region us-east-1 --nodegroup-name standard-workers --node-type t3.medium --nodes 3 --nodes-min 1 --nodes-max 4 --managed
It will take 10–15 minutes since it's provisioning the control plane and worker nodes, attaching the worker nodes to the control plane, and creating the VPC, security group, and Auto Scaling group.
- After the process is fully completed, check the cluster status by running the following command
eksctl get cluster

- Enable connecting to the cluster
aws eks update-kubeconfig --name dev --region us-east-1
Step 4: Creating an Nginx Deployment on the EKS Cluster
- Install Git
sudo yum install -y git
- Download the configuration files
git clone https://github.com/noweder/EKS-with-Nginx.git
- Move to the directory with configuration files
cd EKS-with-Nginx
- Create the Load Balancer service
kubectl apply -f ./nginx-svc.yaml
- Check the Load Balancer service status and copy the external DNS hostname of the load balancer, and paste it into a text file for later use
kubectl get service

- Create the deployment of 3 pods (3 Nginx containers)
kubectl apply -f ./nginx-deployment.yaml
- Check the deployment status
kubectl get deployment

- View the created pods
kubectl get pod

- View the ReplicaSets
kubectl get rs

- View the EC2 worker nodes
kubectl get node

- Finally, you can access the Nginx application using the load balancer DNS address previously copied on a web browser, or by running the below command in CLI replacing
<LOAD_BALANCER_DNS_HOSTNAME>with your specific Load Balancer DNS address
curl <LOAD_BALANCER_DNS_HOSTNAME>


If you get above results, it means that you have successfully accessed the Nginx application running in container which is deployed in the EKS cluster and exposed to the internet via the load balancer service.
Thank you for reading!

