Application Deployments Using CodeBuild & CodePipeline on EKS Cluster

Ram Gopal K
Ankercloud Engineering
4 min readOct 6, 2021

Kubernetes is an open-source container orchestration platform that helps to solve several issues like speed, scalability, and resilience. Most of the customers are interested in dockerizing their applications and deploying them on the Kubernetes cluster.

In this blog, we will discuss the problem statement of one of our customers who is currently running their applications on standalone EC2 instances by running the docker inside the EC2 machine. The customer was maintaining around 12 to 14 environments for testing their applications end-to-end whenever a developer commits the code in GitHub, and deploys them manually on a specific environment using a third-party deployment tool.

After understanding the customer requirements, we came up with an architectural design of CI/CD flow which will fulfill their requirements and triggers the DevOps pipeline as and when developers create/merge the Pull Request in GitHub. Also, they wanted to containerize their applications which can be deployed on Kubernetes. We used some AWS native services like CodeBuild, CodePipeline, EKS (Elastic Kubernetes Service), S3, Lambda, ECR, Parameter Store, SNS, SES, Cloudwatch, Application Load balancer. We used GitHub for version control & terraform script to automate the infrastructure provisioning.

Below is the architecture which was proposed to our customer:

Continuous Integration & Continuous Deployment Flow: -

  • As soon as a developer creates/merges a Pull Request in the Git repository to review proposed changes to the code. When the pull request is merged into the respective branch in the Git repository, AWS CodeBuild automatically detects the changes to the branch and starts code build job which includes continuous inspection of code quality using Sonarqube which was deployed as a pod in the EKS cluster & building the image based on the buildspec.yml file which is available in each application repository.
  • As soon as the build is completed the image will be tagged as build tag and it will be pushed to the respective application ECR (Elastic Container Registry).
  • Once the image is pushed to ECR, codebuild will trigger the codepipeline job using AWS CLI command which consists of different stages like:-
  • Source Stage
  • NameSpace creation in the EKS node Stage
  • Deployment of all the three different types of applications like Java, ROR, and React in that namespace. After getting a confirmation back that the deployment is successful and the pod is in a ready state, we will tag the image with deploy_tag and if it is not successful, we will tag that image as failed_deploy so that developers can investigate and work on their part and start with a new image.
  • Regression Testing stage and sending the reports over email
  • Approval stage to clean up the resources and pushing the latest image with pre-prod/prod_ready tag to a Production ECR
  • Apart from the above-mentioned codebuild jobs and codepipeline we have created a dedicated codebuild cron job that will take the Postgres DBsnapshot shared in a specific location and restore it to the Postgres database pod and keep it ready before the day starts for the developers to test their applications with the latest database dump
  • We used Parameter store for storing credentials, SNS for sending autoscaling notifications and SES for sending regression test results to respective stakeholders, and Application Load Balancer to distribute the traffic across the nodes.
  • Lambda for triggering functions which will append the application URLs that are deployed in EKS nodes and surefire-reports to respective stakeholders.
  • S3 for storing custom files which we have used in later stages during the codepipeline execution.

This pipeline is fully extensible, we can add additional steps as per our requirements before the code gets shipped into the production cluster. I hope now you are clear on the application deployment using codebuild & codepipeline on EKS cluster.

Are you looking for technical support? Please contact our team at Ankercloud to help you in any project related to Cloud, AI/ML, Big Data, Cybersecurity, or Managed Services. You can write to us at info@ankercloud.com or visit our website https://www.ankercloud.com.

--

--