APIEKSconnectivity
EKS API Gateway Demo
This project provides a fully automated solution to deploy a simple Node.js application to Amazon Elastic Kubernetes Service (EKS), expose it via an Application Load Balancer (ALB), and integrate it with AWS API Gateway.
Architecture
The architecture consists of the following components:
- AWS API Gateway: Acts as the single entry point for all incoming API requests.
- Application Load Balancer (ALB): Routes traffic from API Gateway to the EKS service.
- Amazon EKS Cluster: Hosts the containerized Node.js application.
- Amazon ECR: Stores the Docker image of the application.
Here is a visual representation of the architecture:
+-----------------+ +-----------------+ +-----------------------+ +----------------+
| API Gateway |----->| ALB |----->| EKS Service (Node) |----->| EKS Pods |
+-----------------+ +-----------------+ +-----------------------+ +----------------+
Project Structure
app.js: The Node.js Express application with multiple endpoints.package.json: Defines project metadata and dependencies for the Node.js application.Dockerfile: Defines the Docker image for the Node.js application.kubernetes-manifests.yaml: Kubernetes Deployment and Service definitions for deploying the application to EKS.README.md: This file, providing detailed instructions.
Application Endpoints
The Node.js application exposes the following endpoints:
GET /: Returns "Hello, World!"GET /info: Returns basic application information (appName, version, description).GET /greet/:name: Takes a name as a path parameter and returns a personalized greeting.
Prerequisites
Before you begin, ensure you have the following installed and configured:
- AWS CLI: Configured with appropriate credentials and default region.
- kubectl: Command-line tool for Kubernetes.
- Docker: For building and pushing Docker images.
- eksctl (Optional but recommended): A simple CLI tool for creating and managing EKS clusters.
- Node.js and npm: If you want to run the application locally for testing.
Automated Setup and Deployment
This project is fully automated using the setup.sh script. This script will provision all the necessary AWS resources, build and push the Docker image, and deploy the application to EKS.
Prerequisites
Before you begin, ensure you have the following installed and configured:
- AWS CLI: Configured with appropriate credentials and default region.
- kubectl: Command-line tool for Kubernetes.
- Docker: For building and pushing Docker images.
- eksctl: A simple CLI tool for creating and managing EKS clusters.
- helm: The Kubernetes package manager.
Running the Script
-
Clone the repository:
bash git clone <repository-url> cd <repository-directory> -
Make the script executable:
bash chmod +x setup.sh -
Run the setup script:
bash ./setup.shThe script will perform the following actions:
- Create an ECR repository.
- Build and push the Docker image to ECR.
- Create an EKS cluster with an associated IAM OIDC provider.
- Install the AWS Load Balancer Controller.
- Deploy the Node.js application to the EKS cluster.
- Create an Ingress resource to expose the application via an ALB.
- Create an API Gateway and integrate it with the ALB.
At the end of the script, it will output the API Gateway Invoke URL.
Accessing the Endpoint
Once the script is complete, you can access your application through the API Gateway URL provided in the output.
- Root Endpoint:
https://<api-id>.execute-api.<region>.amazonaws.com/dev/ - Info Endpoint:
https://<api-id>.execute-api.<region>.amazonaws.com/dev/info - Greet Endpoint:
https://<api-id>.execute-api.<region>.amazonaws.com/dev/greet/JohnDoe(replaceJohnDoewith any name)
Cleaning Up
To avoid incurring future charges, you should clean up the resources created by the script. A cleanup.sh script is provided for this purpose.
-
Make the cleanup script executable:
bash chmod +x cleanup.sh -
Run the cleanup script:
bash ./cleanup.sh
This script will:
- Delete the API Gateway.
- Delete the EKS cluster.
- Delete the ECR repository.