Learning Jenkins on AWS EC2
I have followed the steps below to achieve a fully functional Jenkins setup on an AWS EC2 instance, including Docker configuration as an agent. This guide will help you set up your own CI/CD environment, ready for deploying applications to Kubernetes and more.
Installation on EC2 Instance
Steps I Followed to Install Jenkins on AWS EC2
Launch an EC2 Instance on AWS:
- I went to the AWS Console, navigated to Instances (running), and selected Launch instances to create a new EC2 instance.
Install Java:
Since Jenkins requires Java, I installed Java with the following commands:
bashCopy codesudo apt update sudo apt install openjdk-11-jre
I verified the Java installation:
bashCopy codejava -version
Install Jenkins:
Next, I added Jenkins to the package repository and installed it:
bashCopy codecurl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null sudo apt-get update sudo apt-get install jenkins
Open Port 8080 on EC2:
- To allow external access, I configured the security group to open port 8080 (TCP). This allows Jenkins to be accessed from outside AWS.
Access Jenkins:
- I accessed Jenkins using the EC2 instance’s public IP at
http://<ec2-instance-public-ip>:8080
.
- I accessed Jenkins using the EC2 instance’s public IP at
Login to Jenkins:
I retrieved the initial admin password with:
bashCopy codesudo cat /var/lib/jenkins/secrets/initialAdminPassword
Then, I logged in to Jenkins and selected Install suggested plugins.
Create an Admin User:
- I created my first admin user, which is recommended for securing future use cases with this Jenkins instance.
Install Docker Pipeline Plugin:
- To integrate Docker with Jenkins, I went to Manage Jenkins > Manage Plugins, searched for "Docker Pipeline" under the Available tab, installed the plugin, and restarted Jenkins.
Docker Configuration on EC2:
I installed Docker on the instance:
bashCopy codesudo apt update sudo apt install docker.io
Then, I granted Docker permissions to the Jenkins and Ubuntu users:
bashCopy codesudo usermod -aG docker jenkins sudo usermod -aG docker ubuntu systemctl restart docker
Finally, I restarted Jenkins to complete the Docker configuration:
http://<ec2-instance-public-ip>:8080/restart
Success!
Following these steps, I set up Jenkins with Docker as an agent on an EC2 instance. You’re now ready to start building and deploying applications with Jenkins on AWS!
Subscribe to my newsletter
Read articles from Aakanchha Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Aakanchha Sharma
Aakanchha Sharma
👋 Welcome to my Hashnode blog! I'm a tech enthusiast and cloud advocate with expertise in IT, backup solutions, and cloud technologies. Currently, I’m diving deep into Python and exploring its applications in automation and data management. I share insights, tutorials, and tips on all things tech, aiming to help fellow developers and enthusiasts. Join me on this journey of learning and innovation!