Skip to main content

Command Palette

Search for a command to run...

Jenkins Master - Agent Setup for CI/CD

Continuous Integration and Continuous Delivery & Deployment

Updated
β€’4 min read
Jenkins Master - Agent Setup for CI/CD
S

πŸ‘‹Hello, Hashnode community! I'm subbaramireddy, a passionate DevOps Engineer with a relentless commitment to optimizing software development workflows and infrastructure management. πŸš€ Hands-on experience in the DevOps field, I've honed my skills in AWS cloud services, containerization, and CI/CD pipelines. As an AWS Certified Developer, I'm well-versed in leveraging cloud technologies to drive efficiency and innovation. πŸ’‘ I firmly believe in the power of continuous improvement. My journey began with an internship, where I immersed myself in the intricacies of DevOps, from deploying web applications to orchestrating containerized solutions. I've also delved into AWS CDK, enhancing security through RDS instance policies, and creating foundational infrastructure with precision. 🌐 My goal is to share insights, best practices, and the latest trends in the DevOps landscape. I'm excited to connect with like-minded professionals, engage in meaningful discussions, and learn from the diverse experiences of the Hashnode community. πŸ“ Let's explore the ever-evolving world of DevOps together. Feel free to connect with me, ask questions, or share your own insights. Together, we can drive innovation and efficiency in the tech world!

Jenkins is an open-source automation server that automates building, testing, and deploying software. It can automatically create, update, and delete jobs based on the repositories it identifies in your software configuration management system. Jenkins Pipeline plugin adds a powerful set of automation tools onto Jenkins using features of Pipeline:

  • Code: Pipelines are implemented in code and typically checked into source control, allowing teams to edit, review, and iterate upon their delivery pipeline.

  • Durable: Pipelines can survive the Jenkins controller's planned and unplanned restarts.

  • Pausable: Pipelines can optionally stop and wait for human input or approval before continuing the Pipeline run.

  • Versatile: Pipelines support complex real-world CD requirements, including the ability to fork/join, loop, and perform work in parallel.

  • Extensible: The Pipeline plugin supports custom extensions to its DSL [1] and multiple options for integration with other plugins.

Setting up the Jenkins Master and Slave Server

Open the AWS management console, search for the ec2 and click on it.

Click on the Launch instance

Launch the instance with the name Jenkins-master. configure it as follows

Launch the instance with the name Jenkins-agent. configure it as follows

connect the Jenkins-master instances as follows.

Connect the Jenkins-agent instances as follows.

Install Java on Jenkins-master and Jenkins-agent instances.

sudo apt update
sudo apt install fontconfig openjdk-17-jre
java -version

Install Jenkins in the Jenkins-master instance.

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
sudo systemctl status jenkins

Update the Jenkins-master instance security group with the Jenkins port 8080. To access the Jenkins in the browser.

Open the Jenkins with the Jenkins-master public address on port 8080.

Copy the path /var/lib/jenkins/secrets/initialAdminPassword and paste in the Jenkins-master.

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Copy the password from the initialAdminPassword file and paste it into the Unlock Jenkins.

Select the install suggested plugins option in the Customize Jenkins.

I will automatically install the required plugins. if some are not installed just click on the retry to install again.

Create an Admin User to log in to Jenkins.

we can see the Jenkins URL.

Jenkins is ready click on the Start using Jenkins.

We can view the Jenkins dashboard.

To connect the jenkins-master with jenkins-agent we require ssh key. Those keys can be generated using the ssh-keygen -t ed25519

Copy the generated public key from the Jenkins-master node.

In the Jenkins-agent node search for the authorized_keys

Paste the Jenkins-master generated public to the Jenkins-agent node in the authorized_keys

Click on the Manage Jenkins and select the nodes option.

we can view the list of nodes attached to the Jenkins server. To add the new node click on the New Node.

New node name as agent-node and Type as Permanent Agent. Click on Create

Configure the agent-node as follows

Add the Credentials in the Jenkins server as follows.

Select the created Credentials which are configured.

we can view the added agent in the Nodes

Install the docker and docker-compose in the Jenkins agent instance.

Add the Jenkins-agent instance user to the docker group.

sudo usermod -aG docker $USER
newgrp docker

Verify correct socket permissions:

Check the permissions of the Docker daemon socket by running:

ls -l /var/run/docker.sock

The output should show that the socket is owned by the "docker" group and has read and write permissions for the group.
If the permissions are incorrect, you can adjust them with the following command:

sudo chmod 666 /var/run/docker.sock

Click on the manage Jenkins and select the credentials in the security.

We can view the configured credentials and click on the System from the Credentials.

we can view the System store with the global credentials. Select the global credentials.

We can view the list of global credentials. Click on the Add credentials.

Add the docker hub credentials in the Global Credentials.

We can view the added docker hub credentials in the global credentials.

Thanks for reading! I hope you found this helpful and informative.

I'm always happy to connect with fellow tech enthusiasts and answer any questions you may have. Don't forget to follow me for more updates on tech, programming, and more.πŸ˜„πŸ˜„

Follow me on LinkedIn to see interesting posts like this : ) Linkedin