Upload Application

Once the CDK stack creation has completed, you would need to upload your local application directory to the newly created CodeCommit Repository: CdkStackEksALBBg-repo As the repository is empty, the CodePipeline will show a failure in the Source CodeCommit repository stage.

EKS Cluster Configuration:

Now, we will carry out some setup configuration of the EKS cluster to configure ingress controller, start the blue and green service and launch an ALB. Access the EKS cluster from your Cloud9 Terminal and run the command that is provided in the output of the CloudFormation under the field "ClusterConfigCommand". Copy-paste this command so that your kubectl commands will point to the required EKS Cluster. dashboard
Once the config command is run, execute the following commands and you should see 2 worker nodes:

kubectl get nodes

Change directory to k8s (amazon-eks-cicd-codebuild-eks-alb-bg/flask-docker-app/k8s) and run following setup script. You may collect the Clustername from the CloudFormation Output and the Worker node instance role from the EC2 dashboard.

cd ../flask-docker-app/k8s
ls setup.sh
chmod +x setup.sh
INSTANCE_ROLE=$(aws cloudformation describe-stack-resources --stack-name CdkStackALBEksBg | jq .StackResources[].PhysicalResourceId | grep CdkStackALBEksBg-ClusterDefaultCapacityInstanceRol | tr -d '["\r\n]')
CLUSTER_NAME=$(aws cloudformation describe-stack-resources --stack-name CdkStackALBEksBg | jq '.StackResources[] | select(.ResourceType=="Custom::AWSCDK-EKS-Cluster").PhysicalResourceId' | tr -d '["\r\n]')

./setup.sh us-west-2 CdkStackALBEksBg-ClusterDefaultCapacityInstanceRol-1O55DDIPVO3VV Cluster9EE0221C-2e048a043ddf4cb1b53ed9a0975afbc1

Check the files for updated values:

Modify Security Group:

Modify the Security Group for the newly spawned Application Load Balancer to add an incoming rule to allow http port 80 for the
Services -> EC2 -> Load Balancer -> Select the latest created ALB -> Click Description Tab -> Scroll down to locate the Security Group Edit this security group to add a new rule with following parameters: http, 80,

Review Load Balancer Config:

Now, check the newly created LoadBalancer and review the listener routing rules: Services -> EC2 -> Load Balancer -> Select the latest created ALB -> Click Listeners Tab -> View/Edit Rules You would see the below settings shown: dashboard

Check the Load Balancer Target-groups and ensure the healthy hosts have registered and health check is consistently passing as shown below: dashboard dashboard

Upload code to CodeCommit Repo:

Note: For Windows based git clients, you may need to clear the cache if a different user was being used or to reset the credentials. To do that: Control Panel -> All Control Panel Items -> Credential Manager and delete git user. If you have Keychain Access App based credentials caching in your client device, you may need to search and edit the required credential item.

To upload your application, use the following commands (please copy-paste after changing the region below accordingly). Navigate to the directory as shown below to amazon-eks-cicd-codebuild-eks-alb-bg and run git commands:

Note: Please substitute the region below and then paste the commands provided below.

cd ../.. 
pwd => confirm your current directory is amazon-eks-cicd-codebuild-eks-alb-bg

git add flask-docker-app/k8s/alb-ingress-controller.yaml
git add flask-docker-app/k8s/flaskALBIngress_query.yaml
git add flask-docker-app/k8s/flaskALBIngress_query2.yaml
git add flask-docker-app/k8s/iam-policy.json
git commit -m "Updated files"
git remote add codecommit https://git-codecommit.$AWS_REGION.amazonaws.com/v1/repos/CdkStackALBEksBg-repo
git push -u codecommit master

This will push the last commit we carried out in our preparation section, which in turn will trigger the CodePipeline.