GithubHelp home page GithubHelp logo

jpmmota / aws-eks-cicd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mutoe/vue3-realworld-example-app

0.0 0.0 0.0 4.84 MB

Example of a complete DevOps CI/CD pipeline implementation to deploy an application on AWS EKS.

License: MIT License

HTML 0.52% Vue 25.85% Shell 0.04% TypeScript 63.70% JavaScript 9.64% Dockerfile 0.25%

aws-eks-cicd's Introduction

aws-eks-cicd

Example of a complete DevOps CI/CD pipeline implementation to deploy an application on AWS EKS.

Objective

  • Package the vue3 realworld frontend application into a Docker container image
  • Push it to AWS Elastic Container Registry (ECR)
  • Create an AWS Elastic Kubernetes Service (EKS) cluster
  • Use AWS CodeBuild to automate the CI/CD pipeline by:
    • Check for changes in the code repository
    • Create new docker image, tag it and push it to AWS ECR
    • Update deployment file with new image version and reload k8s cluster configuration

Steps

  1. Fork vue3 realworld, rename the repository to aws-eks-cicd and clone it to your local machine
git clone https://github.com/jpmmota/aws-eks-cicd.git
cd aws-eks-cicd
  1. Create Dockerfile in the project root folder

  2. Build the container image locally and test it

docker build -t jpmmota/aws-eks-cicd:latest .
docker run --rm -it -d -p 3000:80 jpmmota/aws-eks-cicd:latest
curl localhost:3000
  1. Create AWS Elastic Container Registry (ECR)
aws ecr create-repository --repository-name aws-eks-cicd
  1. Push docker image to AWS (ECR)
aws ecr get-login-password --region ca-central-1 | docker login --username AWS --password-stdin 577620766037.dkr.ecr.ca-central-1.amazonaws.com
docker build -t aws-eks-cicd:1.0 .
docker tag aws-eks-cicd:1.0 577620766037.dkr.ecr.ca-central-1.amazonaws.com/aws-eks-cicd:1.0
docker push 577620766037.dkr.ecr.ca-central-1.amazonaws.com/aws-eks-cicd:1.0
  1. Create AWS Elastic Kubernetes Service (EKS) cluster
eksctl create cluster --name eks-cicd --node-type t2.micro --nodes 2
  1. Create create-role.json file
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
      "Service": "codebuild.amazonaws.com"
    },
      "Action": "sts:AssumeRole"
    }
  ]
}
  1. Create put-role-policy.json file:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "CloudWatchLogsPolicy",
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Resource": "*"
    },
    {
      "Sid": "CodeCommitPolicy",
      "Effect": "Allow",
      "Action": [
        "codecommit:GitPull"
      ],
      "Resource": "*"
    },
    {
      "Sid": "S3GetObjectPolicy",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:GetObjectVersion"
      ],
      "Resource": "*"
    },
    {
      "Sid": "S3PutObjectPolicy",
      "Effect": "Allow",
      "Action": [
        "s3:PutObject"
      ],
      "Resource": "*"
    },
    {
      "Sid": "S3BucketIdentity",
      "Effect": "Allow",
      "Action": [
        "s3:GetBucketAcl",
        "s3:GetBucketLocation"
      ],
      "Resource": "*"
    },
    {
      "Sid": "ElasticContainerRegistryPolicy",
      "Effect": "Allow",
      "Action": [
        "ecr:*"
      ],
      "Resource": "*"
    },
    {
      "Sid": "CodeBuildAssumeRolePolicy",
      "Effect": "Allow",
      "Action": [
        "sts:AssumeRole"
      ],
      "Resource": "*"
    },
    {
      "Sid": "EKSPolicy",
      "Effect": "Allow",
      "Action": [
        "eks:*"
      ],
      "Resource": "*"
    }
  ]
}
  1. Apply policies
aws iam create-role --role-name CodeBuildServiceRole --assume-role-policy-document file://create-role.json
aws iam put-role-policy --role-name CodeBuildServiceRole --policy-name CodeBuildServiceRolePolicy --policy-document file://put-role-policy.json
  1. Add user to eks rbac configuration
eksctl create iamidentitymapping --cluster eks-cicd --arn <EKS_ROLE_ARN> --group system:masters --username CodeBuildServiceRole
  1. Create deployment.yaml and service.yaml files

  2. Create buildspec.yaml file that will be used by AWS CodeBuild

  3. Create AWS CodeBuild project

  • Project name: eks-cicd
  • Source provider: Github
  • Operating System: Ubuntu
  • Runtime: Standard
  • Image: aws/codebuild/standard:5.0
  • Privileged: check the box
  • Existing Service Role: selected
    • Provide Role ARN that was previously created
  • Allow AWS CodeBuild to modify this service role so it can be used with this build project: unselected
  1. Deploy service and get the load balancer URL to test the application (wait a few minutes until the load balancer becomes available):
kubectl apply -f service.yaml
kubectl get services eks-cicd

aws-eks-cicd's People

Contributors

mutoe avatar levchak0910 avatar dependabot[bot] avatar sajadhsm avatar plumrx avatar jpmmota avatar soerenmartius avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.