Overview:
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.
Amazon EKS lets you run your Kubernetes applications on both Amazon Elastic Compute Cloud (Amazon EC2) and AWS Fargate. With Amazon EKS, you can take advantage of all the performance, scale, reliability, and availability of AWS infrastructure, as well as integrations with AWS networking and security services, such as application load balancers (ALBs) for load distribution, AWS Identity and Access Management (IAM) integration with role-based access control (RBAC), and AWS Virtual Private Cloud (VPC) support for pod networking.
Deploying an e-commerce web application on Amazon EKS using Terraform involves several steps. Below is a step-by-step guide to help you set up an EKS cluster and deploy a simple e-commerce web app.
Step 1: Set Up Terraform Configuration
Check the link below for the full terraform configurations.
Terraform Codes Repo
https://github.com/Samuel7050/EKS-Terraform--Project.git
Container Repo
https://hub.docker.com/r/ojosamuel/e-commerce
We will be using Terraform modules for this deployment. Modules are a key feature of Terraform that promotes modularity, reusability, and maintainability in infrastructure as code.
The following infrastructure will be deployed using the terraform Modules.
VPC– The Terraform codes in the vpc module will deploy a default VPC and default subnets in the selected region if it doesn’t exit already. If it does exist, it maintains the default VPC and Subnets.
Security Group– The Terraform codes in the security group module will deploy a security group for the EC2 instance opening port 22 for ssh. This will enable access into the EC2 instance for further interaction with the EKS cluster.
IAM Roles– The IAM Roles Module will deploy the required policy permissions for the EC2 instance, Amazon EKS Cluster and the EKS worker node group. These Roles and attached policies are very vital to ensure that our EKS cluster are working perfectly.
EKS and Worker Node Group– The Terraform codes in the EKS Module will deploy the EKS cluster and the Worker Node Group.
EC2 Instance– The Terraform codes in the EC2 module will deploy an EC2 instance that will serve as the K8-Client Server for interacting with our Amazon EKS Cluster and the Worker Nodes.
User Data– We will be using the script in ec2.sh to preinstall Docker, AWS CLI , Git and Kubectl on the Ec2 instance.
Step 2: Initialize and Apply Terraform Configuration
Run terraform Init – to initialize terraform.
Run terraform plan – To preview all resources to be deployed.
Run terraform apply – To deploy all resources.
Terraform will create the necessary AWS resources as indicated in the main.tf file.
*Checking our Resources on AWS *
IAM Roles
EKS Cluster and Worker Node Group
EC2 Instance
Step 3: Confirm Preinstalled tools and configure **kubectl to Use the EKS Cluster**
Connect to the EC2 instance: I will be connecting to EC2 instance with my VScode IDE. ( compare the internal IP of the EC2 as shared above)
Confirm preinstalled tools are up and running.
Authenticate with your AWS credentials.
Use your Access key ID and your secret access key with programmatic access to authenticate. Note- Do not share your secrets with anyone.
configure kubectl to Use the EKS Cluster
Run aws eks --region us-east-2 update-kubeconfig --name eks-cluster1
to configure kubectl
Run kubectl get nodes
command to confirm we have access to our EKS cluster worker nodes.
No resource currently running in the cluster.
Step 4: Deploy a Sample E-Commerce Web App
Create both deployment.yaml file and service.yaml file
Create Deployment: Run kubectl apply -f deployment.yaml
command. This will create a deployment , a ReplicaSet and the specified number of Pods.
Create Service: Run kubectl apply -f service.yaml command. This will create a Load balancer type of service. A load balancer will be deployed immediately on AWS.
To access our e-commerce website, copy the load balancer dns endpoint url and paste it on your web browser
Congratulations!!! We have successfully deployed our e-commerce website on Amazon EKS.
Thanks for Reading
Clean Up
Run terraform destroy to remove all infrastructures deployed to avoid unexpected bills
Top comments (0)