DevOps 101 - Deploying & Configuring Jenkins on AWS server

Subscribe to my newsletter and never miss my upcoming articles

devops image.png

Hello!

In this series, we are going to learn how we can enable the entire devops CI/CD pipeline for a custom application that can be deployed to the production. The goal of this series to deploy our Next.js application on Kubernetes.

Our CI/CD pipeline build in our DevOps Bootcamp series can be used across all the NodeJs, Angular, React.Js and Vue.Js projects. It will enable a very minimal setup time with maximum output for the developers who want to spend more time working on the application features.

This is a hands-on guide featuring all the tools we would be using in our continuous integration and continuous deployment process, hence my recommendation is to practice, run commands while you go through the articles.

Let’s discuss some of the pros of continuous integration and continuous deployment.

  • Faster Release Cycle
  • Fewer Bugs
  • Less risk on the release
  • More Testing Reliability
  • Easy to maintain and update the software
  • Helps developers to focus more on building the product features better and faster

Tools used

Pre-Requisites

  1. Create an AWS account - aws.amazon.com
  2. Little knowledge of Next.js and Node.js would be great, but not necessary for our setup. CodeBase for the entire setup - https://github.com/desaijay315/kubernetes-with-nextjs-app

In this part, we would be focusing on installing and deploying Jenkins on the AWS server as our first step towards CI/CD pipeline.

Create an EC2 instance

  • Login to your AWS account
  • Go to services and select EC2 Instance
  • Choose an Amazon Linux Image. (You can also choose any other image as per your requirement)

Choose an amazon Linux image.png

  • Choose an Instance Type

step 2 - choose and instance type.png

  • Configure an Instance Type

Make sure you enable the auto-assign public IP or you will have to manually assign the elastic IP for your instance. It was disabled in my case.

Steps 3 - configure instance details.png

  • Add Tags

step 4  - add tags .png

- Configure the security group - As Jenkins runs on port 8080 by default, We need to enable to inbound traffic to port 8080. Secondly, add a rule for the SSH port 22, to access our server. To create a security group, refer below link -

https://djaytechdiary.com/creating-security-groups-in-aws-ckfpdurto002vxus1bxvmah7e

step 5 - security group.png

  • Review instance and launch

review and launch.png

  • Create a key, if you don’t have the existing keys with you, create a new one, store it on the machine and launch the instance. Most importantly, do not lose them or else you will lose your server access!

step 5 - security group.png

HOORAY!! Server launch is successful

launch status.png

  • Go to the EC2 instance and confirm the instance status. It should be up and running. Status check - 2/2 jenkins_server_instande.png

Installing Jenkins

  • Log in to ec2 instance with public IP - ssh -i jenkins_aws_key.pem ec2-user@your-server-public-IP
    • Switch to the root user
      sudo su -
      
    • By default our amazon image has java1.7 version, we would upgrade it to java1.8.
  • Vola!! Jenkins Unlocked!

jenkins up.png

  • Get the Admin password from the server -
cat /var/lib/jenkins/secrets/initialAdminPassword
  • We will skip the installation of the plugins for now and install the plugin as and when require to set up our code build process

skip the install plugins.png

  • Welcome to Jenkins

welcome to jenkins.png

  • To change the port from 8080 to 9090 - By default we have our Jenkins up and running on the port 8080. Let’s change it to 9090. We need to add an inbound rule for port 9090 in the security group which we created.

  • Open then Jenkins configurations

vi /etc/sysconfig/jenkins
  • The only part you need to change is:
JENKINS_PORT="8080"
  • There you need to change to the desired port. For example:
JENKINS_PORT="9090"
  • Finally, Restart Jenkins service
service Jenkins restart
  • You can now see the port is changed to 9090

port change.png

Installing GIT on Jenkins Server

We will integrate GIT with Jenkins, and enable them in our Jenkins job, this will help Jenkins to pull our code and build the latest code commits.

Open your terminal and run

 yum install git -y

Installing GIT Plugins Jenkins Server

  • Install Github from the manage plugins section. Go to the available section and install “Github”

manage plugins jenkins -1.png

  • Now go to global tool configuration

Change the name value from Default to GitHub and uncheck install automatically box

github global tool configuration.png

  • You’re ready with the Jenkins setup and WE'RE DONE!

Conclusion

In this article, we installed and deployed Jenkins on our AWS server. We learned how different plugins can be configured and installed, and how the default port of our Jenkins server can be changed.

In the next article, we will configure our NextJs app and dockerize the application.

Comments (5)

Rohan Büchner's photo

Thank you for this awesome set of articles. I've been using it to get my own CICD up. I did deviate a little from your set of articles, and added blue ocean. I'm however getting some issues where jenkins cant see docker. Do you perhaps know how to get past it?

This is the issue I'm seeing.

+ docker pull lts-alpine

Using default tag: latest

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.40/images/create?fromImage=lts-alpine&tag=latest: dial unix /var/run/docker.sock: connect: permission denied

script returned exit code 1

I have tried a few different articles suggested routes, but I'm not sure if I did it right or wrong / the solutions aren't correct for this use case?

Show +3 replies
Jay Desai's photo

Rohan Büchner, Do you two different instances running for Jenkins and Docker?

Jay Desai's photo

Rohan Büchner , If you are on the same server you can create the docker group and add your user to that group

sudo groupadd docker

sudo usermod -aG docker your-user

Logout and Login. Verfiy the docker commands are run without sudo