Deploy an application using CodeCommit, CodeBuild, ECR, and EKS

In this tutorial, what I’m going to do is pushing my existing application code to the AWS CodeCommit. Then I’m going to build my docker image and push it into ECR. After that, I’m going to create a Kubernetes cluster and deploy my build image into that cluster.

Please follow the every step I mentioned here.

Section 01: CodeCommit

  1. Go to the IAM (Identity Access Management) section in the AWS management console. (Make sure, you have CodeCommit full access in the permission category.)

Section 02: CodeBuild

Let’s move to the CodeBuild, in here you should need to create a file called buildspec.yaml. In that file, you should need to add pre-build commands, build commands, and post-build commands as a single script. By using that buildspec file you’re going to build your docker image and push it to the ECR (Elastic Container Registry). To make this file and do the above work you should need to follow the below steps.

  1. Once again go to the IAM section in the AWS management console, then create a role for the CodeBuild and attach the below policies;

i. AWS CodeCommit full access

ii. AWS EC2 Container Registry full access

iii. AWS CodeBuild Admin access

2. Go back to the AWS management console then under services search AWS CodeBuild.

3. Create a build project.

4. Put an appropriate project name.

5. Put the source provide as CodeCommit.

6. Select the correct repository.

7. Select the correct branch.

8. In the environment section, select the image as manage image, then the operating system as ubuntu.

9. Put the role name that you created.

10. Then select use a build spec file.

11. Click on the Create Build Project button.

Then successfully build your project with AWS CICD.

Sample buildspec.yaml file I’ve used;

Section 03: ECR

Once we done the AWS CICD part, it will trigger and push your docker image to your ECR. In the above file I’ve added every step you should add to your buildspec.yaml.

Section 04: EKS

Once we have pushed our docker image to ECR; we are able to deploy it on EKS. For that, you need to follow below file.

Now you have successfully deployed your container image to Kubernetes!! 🎉🎉

If you have any questions; please drop them in the comments section.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store