This is the Capstone project of Udacity Nanodegree course on AWS Cloud DevOps Engineer. It will create the CI/CD pipeline for micro services applications.
In this project, I have developed a CI/CD pipeline for Nginx Hello world application with Blue/Green
deployment.
The blue branch has the code for blue
deployment and green branch for green
deployment.
All the screenshots are under Screenshots folder of this repository.
Application URL for my project: http://a7b112233bdbf4e48a83fe1955720164-1090219923.ap-south-1.elb.amazonaws.com:8000
- Launched EC2 instance - Installed Java, Jenkins, Docker, AWS CLI, Kubectl, eksctl, hadolint and tidy
- Installed
pipeline-aws
andBlue Ocean
plugins in Jenkins - Configure DockerHub and AWS credentials in Jenkins
- Created EKS cluster using
eksctl
- Created
Dockerfile
for docker image - Created Jenkins CI/CD pipeline
- Launched an EC2 free tier
ubuntu
instance with a Security Group allowing inbound connection on22
and8080
ports. I usedubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20201026 (ami-0a4a70bd98c6d6441)
image. - Login into EC2 instance using key/pair associated with instance . Install softwares using commands mentioned in
environment-setup.sh
file - Open Jenkins using
http://{public IP of EC2}:8080
in browser. - First time password is obtained using
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
- Select option to install suggested plugin. // Not required if you use 20.0 ubuntu image
- When installation is complete, you are prompted to set up the first admin user. Create the admin user and make note of both the user and password to use in the future. // Not required if you use 20.0 ubuntu image and default admin user is
admin
- Install
Blue Ocean
andpipeline-aws
plugins viaManage Jenkins => Manage Plugins => Search and install
. - Configure
AWS
andDockerHub
Credentials in Jenkins viaManage Jenkins => Manage Credentials => global => Add credentials
. These credentials will be used inJenkinsfile
. ForAWS
credentials SelectAWS Credentials
option in Kind dropdown and for DockerHub selectUsername with password
option. The value which you put inID
field is used inJenkinsfile
to get credentials. - Restart the jenkins using
sudo systemctl restart jenkins
- Open your Github repository and add webhook to allow Jenkins to pick the changes via
Settings => Webhooks => Add webhook
. URL would behttp://{public IP of EC2}:8080/github-webhook/
and content-typeapplication/json
- Open
Blue Ocean
view in Jenkins and create a new pipeline for Github repository. You will needGithub access token
which can be generated viaYour github-profile => settings => Developer settings => Personal access tokens => Generate new token
withrepo
anduser:email
scope. - Commit changes in the blue branch which will trigger Jenkins pipeline to create and deploy container in EKS cluster.
- Open the application using loadbalancer url: http://{loadbalancer dns}:8000/
- Commit changes in the green branch which will trigger Jenkins pipeline to create and deploy container in EKS cluster.
- Open the application using loadbalancer url: http://{loadbalancer dns}:8000/
Dockerfile
contains the data to prepare imagerun_docker.sh
file is used to create docker image. It is invoked fromMakefile
.upload_docker.sh
file is used to upload docker image. It is invoked fromMakefile
.index.html
file is deployed innginx
server as part of web applicationekscluster.yaml
file is used to create cluster usingeksctl
installed in EC2 instanceenvironment-setup.sh
file has all the commands to be run on EC2 instance for initial setupJenkinsfile
has the details of all the stages to be run as part of pipeline.Makefile
has the commands which are invoked fromJenkinsfile
blue-green-service.json
file is used to make the blue or green deployment to be available. It is invoked formJenkinsfile
. Note that the selector, in this file, decides which environment will be up i.e. blue or greenreplication-controller.json
file is used to deploy image on cluster. It is invoked formJenkinsfile
.
https://medium.com/@andresaaap/simple-blue-green-deployment-in-kubernetes-using-minikube-b88907b2e267
- Install
docker
,virtualbox
andminikube
at your local - Start
minikube
using command:minikube start
- Build docker image using
run_docker.sh
- Upload docker image using
upload_docker.sh
- Deploy image using command:
kubectl apply -f ./replication-controller.json
- Switch to blue environment using command:
kubectl apply -f ./blue-green-service.json
- Get the application url using commandL:
minikube service bluegreenlb --url
- Open
url
in browser.