This is a demonstration of using aws pipeline and k8s in cicd
git clone https://github.com/haquocdat543/aws-cicd.git
cd aws-cicd
- Aws CodeCommit repo name. Line : 6,46
- Aws S3 bucket repo name. Line : 14, 50
- Region. Line : 32
- Account number. Line : 34
- Ecr repo name. Line : 36, 90
- Tag. Line : 38
aws cloudformation deploy --stack-name k8s --template-file k8s.yaml
aws cloudformation deploy --stack-name pipeline --template-file pipeline.yaml
aws cloudformation describe-stacks --query Stacks[].Outputs[*].[OutputKey,OutputValue] --output text
aws eks update-kubeconfig --name my-eks
Copy https url from Output
git clone <your-aws-codecommit-https-url>
Then enter your aws code commit username and password. aws-codecommit-account
cd <your-aws-codecommit-repo-name>
then create a frontend project inside it. In my case it is vue
Add Dockerfile
. In my case it is vue-dockerization
Add buildspec.yaml
at root
folder
Create a commit and push it to aws-codecommit-repo
Get codebuild-project-name
and Ecr-repo-name
from Output
:
aws codebuild start-build --project-name <your-codebuild-project-name>
Wait a little bit and check image :
aws ecr describe-images --repository-name <your-ecr-repo-name>
Find compatible version and platform here. kubectl-argo-rollouts
curl -LO https://github.com/argoproj/argo-rollouts/releases/latest/download/kubectl-argo-rollouts-linux-amd64
chmod +x ./kubectl-argo-rollouts-linux-amd64
sudo mv ./kubectl-argo-rollouts-linux-amd64 /usr/local/bin/kubectl-argo-rollouts
kubectl argo rollouts version
kubectl create namespace argo-rollouts
kubectl apply -n argo-rollouts -f https://github.com/argoproj/argo-rollouts/releases/latest/download/install.yaml
You need to replace variables before execute following commands :
- $AWS_DEFAULT_REGION
- $AWS_ACCOUNT_ID
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
Or you can go to AWS
> ECR
> Private Registry
> Repositories
> Your Repo
> View Push Commands
> copy and execute first command
cat ~/.docker/config.json | base64
Copy the output and paste to secret.yaml
file :
kubectl create secret generic my-registry-key \
--from-file=.dockerconfigjson=.docker/config.json \
--type=kubernetes.io/dockerconfigjson
kubectl create secret generic my-registry-key --from-file=.dockerconfigjson=.docker/config.json --type=kubernetes.io/dockerconfigjson
kubect get secret
kubectl create secret docker-registry my-registry-key \
--docker-server=https://private-repo \
--docker-username=user \
--docker-password=pwd
kubectl create secret docker-registry my-registry-key --docker-server=https://private-repo --docker-username=user --docker-password=pwd
Modify your imagePullSecret to Your registry secret
kubectl apply -f bluegreen-rollout.yaml
kubectl patch svc bluegreen-demo -n default -p '{"spec": {"type": "LoadBalancer"}}'
kubectl patch svc bluegreen-demo-preview -n default -p '{"spec": {"type": "LoadBalancer"}}'
kubectl get svc
Copy both Loadbalancer-dns
and open it in your browser
- Update frontend app to version 2
- Update image version in
buildspec.yml
- Start new build
Change image version tag in bluegreen.yml
kubectl apply -f bluegreen-rollout.yaml
Copy both LoadbalancerDNS
and open it in browser
kubectl argo rollouts promote bluegreen-demo