This is a project aimed to build a working CI/CD pipeline with the following tools: Git, Jenkins, Docker, Kubernetes, and Ansible.
Putting it all together let's understand the workflow!
Here is a link to the presentation with more detailed information about the workflow and problems encountered.
- Developers will commit code to the application's repository on Github.
- A webhook configured in Github and Jenkins will notify Jenkins to start building the application.
- In the Jenkins pipeline job will start executing the steps listed in the Jenkinsfile.
- The build step in the Jenkinsfile creates a Docker image(kcharette/ec2-pipeline) using the provided Dockerfile.
- The image is given a tag and pushed to Docker Hub.
- Ansible playbook starts to deploy the Docker image to a Kubernetes cluster.
- The Ansible playbook will read all the Kubernetes definitions for deployment/servive and create required components in the cluster.
Step 1 : Set up Prerequisites (make sure to have ver JDK 1.8+)
Follow the documentation below on how to setup an account and create an EC2 instance:
- Sign up for AWS and create and IAM user name and password
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/get-set-up-for-amazon-ec2.html https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html
Step 2 : Launch an EC2 Instance
- Launch a EC2 Instance to host Jenkins.
- Create a Security Group
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/working-with-security-groups.html#creating-security-group
Step 3 : Install and Configure Jenkins
-
Check your version of java or install with:
sudo yum install java-1.8.0 -
Ensure your packages are up to date
sudo yum update -y -
Download and Install Jenkins following the documentation here:
https://www.jenkins.io/doc/book/installing/linux/#red-hat-centos -
Start the Jenkins service and check the status
Runsudo service jenkins startand thensudo service jenkins status
If there is an output similar to the image below then Jenkins is running! -
Now finally using the IP address of the instance followed by
8080You should see the Getting Started screen for Jenkins.
Note : Before running the Jenkins, make sure your 8080 port is available. Another option is running Jenkins on a different port. Inside the configuration file located /etc/sysconfig/jenkins just change JENKINS_PORT. (The location in Debian based linux is /var/default/jenkins)
Following the documentation here: https://plugins.jenkins.io/github/ and https://medium.com/faun/triggering-jenkins-build-on-push-using-github-webhooks-52d4361542d4
- Ensure Git is installed on the EC2 instance by running
sudo yum install git -y - From the Github repository go to Settings -> Webhooks -> Add webhook
- In the 'Payload URL' field, past the Jenkins environment URL. At the end of the URL add
/github-webhook/. In the 'Content type' selectapplication/jsonand leave the 'Secret' field empty. - Under 'Which events would you like to trigger this webhook?' I chose 'Just the push event' for this example, however you can select as many events as you want.
- From Jenkins create a new project and click on the Source Code Management tab.
- Click on Git and paste in your Github repository URL in 'Repository URL' field.
- Click on the Build Triggers tab, then on the 'Github hook trigger for GITScm polling' and Save!
Following the documentation here: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html
Following the documentation here: https://dzone.com/articles/building-docker-images-to-docker-hub-using-jenkins#
The video here gives details on how to install Ansible with Jenkins: https://www.youtube.com/watch?v=PRpEbFZi7nI&ab_channel=JavaHomeCloud
- Install the Ansible plugin on Jenkins
- Go to Global Tool Configuration and locate Ansible.
- Add the Name and Path to ansible executables directory
Following this video: https://www.youtube.com/watch?v=NSk0NHkTjDs&t=690s&ab_channel=DeekshithSN


