AWS EKS CI - CD With AWS CodeCommit + AWS CodeBuild + AWS CodePipeline - Final
AWS EKS CI - CD With AWS CodeCommit + AWS CodeBuild + AWS CodePipeline - Final
➔ Secure by default
sh prereqs.sh
➔ Install kubectl
https://docs.aws.amazon.com/eks/latest/user
guide/install-kubectl.html
➔ Install aws-iam-authenticator
https://docs.aws.amazon.com/eks/latest/user
guide/install-aws-iam-authenticator.html
➔ Install eksctl
https://docs.aws.amazon.com/eks/latest/user
guide/getting-started-eksctl.html or
https://eksctl.io/introduction/installation/
Create AWS EKS Cluster
Create Cluster:
cluster.yaml
eksctl create cluster -f cluster.yaml
eksctl delete cluster -f cluster.yaml - name: ng-1 #cluster node group name
instanceType: t2.medium #desired instance type
Note: Running delete command will remove all the
desiredCapacity: 3 #desired nodes count / capacity
resources
ssh:
allow: false
Build the docker image using Dockerfile
EXPOSE 3000
CMD [ "node", "index.js" ]
Publishing Image to AWS ECR
It’s just like Docker Hub, where we can push and Pull image and we can
use it with AWS ECR same way. To get the docker login and auto execute
The image: (All command are already given in AWS ECR UI, just use the same)
While Configuring AWS CodeBuild , make sure to set the build spec file
properly and to enter the required environment variables as follow:
AWS_DEFAULT_REGION
AWS_CLUSTER_NAME
AWS_ACCOUNT_ID
IMAGE_REPO_NAME
IMAGE_TAG
https://eksctl.io/usage/iam-identity-mappings/
Configuring AWS EKS Cluster for CI/CD
Option 2: aws-auth.yaml sample file
aws eks update-kubeconfig --name eks-cluster-name --region aws-region apiVersion: v1
kubectl get configmaps aws-auth -n kube-system -o yaml > kind: ConfigMap
aws-auth.yaml metadata:
Now, edit your aws-auth.yaml, and add the following under
name: aws-auth
data.mapRoles namespace: kube-system
data:
-rolearn: arn:aws:iam::510442909921:role/role-name
mapRoles: |
username: role-name - rolearn:
groups: arn:aws:iam::11122223333:role/EKS-Worker-NodeInstance
-system:masters Role-1I00GBC9U4U7B
username: system:node:{{EC2PrivateDNSName}}
Apply this configuration from your terminal:
kubectl apply -f aws-auth.yaml groups:
- system:bootstrappers
- system:nodes
If face any issue, follow this debug steps: - rolearn:
https://aws.amazon.com/premiumsupport/knowledge-center/am arn:aws:iam::11122223333:role/designated_role
azon-eks-cluster-access/ username: designated_role
groups:
- system:masters
Clean up everything
Delete cluster:
Behind the scene the cloud formation stack will get deleted and accordingly resources will be deleted as well, must do it if you are doing in
development or test as a temporary deployment otherwise it will cost you a lot
There are few more things you need to know
This demo is just the start points of CICD and there is a lot more out there, the more you use it , the more
experience you will gather, so I will highly suggest try by yourself and deploy your own AWS EKS Cluster.
After trying the basic app deployments , the next thing you might be interested to learn are: