This repository shows how to how to provision an Amazon EKS cluster, set up a CI/CD pipeline(GitHub Actions) to create and publish a Docker image to Amazon ECR, and use Helm to deploy an NGINX container.
The first step in the project is to setting up the infrastructure for the application with the help of CloudFormation, The below resouces will be created on the execution of CloudFormation script.
- VPC
- EKS Cluster
- S3 Bucket
- AWS CLI is installed and configured with the appropriate credentials.
- You have access to the CloudFormation template file.
- The repository contains the CloudFormation template under the
Technical-test/Infrastructuredirectory.
Open your terminal and navigate to the Technical-test/Infrastructure directory where the CloudFormation template is located:
cd path-to-your-repo/Technical-test/InfrastructureBefore creating the EKS cluster, the first step is to bring up the required VPC.
aws cloudformation create-stack \
--region us-east-1 \
--stack-name my-eks-vpc \
--template-body file://eks-vpc-stack.yamlNow we can create the Cluster with the help of Below command and it will setup the cluster with the necessary configuration and IAM roles.
aws cloudformation create-stack \
--region us-east-1 \
--stack-name my-eks-cluster \
--capabilities CAPABILITY_NAMED_IAM \
--template-body file://eks-stack.yamlIn this task we will create helm chart to deploy it on NGIX Conatiner on EKS Cluster formed in the above task. This deployment is configured to expose the NGINX service with the help of K8s LoadBalancer, it will be accessible from external traffic. This task Involves
- Creating a Helm chart for NGINX Deployment.
- Installing Helm Chart on K8s Cluster.
- Exposing the service via a LoadBalancer - This make sures that NGINX Container is accessed from the internet.
EKS Cluster is already created and configured via CDK/CloudFormation. kubectl is configured to interact with the EKS cluster (ensure that the kubeconfig is set up correctly).
- kubectl version --client
### Verify Installation of AWS CLI
- aws --version
### Configure AWS CLI with your AWS credentials (if not done already):
- aws configure
### Setup kubeconfig for EKS cluster
- aws eks update-kubeconfig --region us-east-1 --name my-eks-cluster
### If the connection to EKS is properly established the the below command will be showing the nodes in the EKS Cluster
- kubectl get nodes
### Check AWS CLI authentication: Ensure your AWS CLI is authenticated properly by running:
- aws sts get-caller-identityInstall Helm on Machine If not, follow the Helm Installation Guide.
#### Initialize helm
First you need to run the below command to generate a basic helm chart
helm create nginx-deployment
This will create a new directory named nginx-deployment
#### Install the Helm Chart on the EKS Cluster:
helm install nginx-release ./nginx-deployment
#### Verify the Deployment:
kubectl get pods
#### Check the LoadBalancer URL:
kubectl get svc nginx-release-nginx-deployment
#### The output will **look** like this:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-release-nginx-deployment LoadBalancer 10.100.48.144 a47776a-1960.us-east-1.elb.amazonaws.com 80:30267/TCP 31mOpen a web browser and navigate to the EXTERNAL-IP from the previous step. You should see the default NGINX welcome page.
Here is the screenshot of NGINX Deployment
This section shows the simple setup of an CI/CD pipeline using GitHub Actions to Automate the process of building and Deploying the image to Amazon ECR. The pipeline has 2 steps.
- Build Docker Image
- Push the Docker image to AmazonECR
- Amazon ECR Repository
- AWS CLI
- GitHub Secrets
- AWS Secrets: Store AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_ACCOUNT_ID, and ECR_REPOSITORY_NAME
CI/CD Pipeline triggers when changes are pushed on the main branch.
- Checkout Code: this step retries the lates code form the repo.
- Setup AWS CLI: It configures the AWS CLI with the help of AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and Region
- Login to ECR: Authenticates Docker CLI to connect withe the ECR by using the AWS credentials.
- Build Docker image: It builts the Image based on the Dockerfile located in the repository.
- Tag Image: The above built image is tagged with appropriate ECR Repo URL.
- Push to Amazon ECR: Pushes the above tagged to image to ECR Registry.