DevOps 101 - Deploying & Configuring Jenkins on AWS server
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
- Create an AWS account - aws.amazon.com
- 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 Instance Type
- 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.
- Add Tags
- 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 -
- Review instance and launch
- 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!
HOORAY!! Server launch is successful
- Go to the EC2 instance and confirm the instance status. It should be up and running. Status check - 2/2
- 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.
- Switch to the root user
- Vola!! Jenkins Unlocked!
- Get the Admin password from the server -
- 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
- Welcome to Jenkins
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
- The only part you need to change is:
- There you need to change to the desired port. For example:
- Finally, Restart Jenkins service
service Jenkins restart
- You can now see the port is changed to 9090
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”
- Now go to global tool configuration
Change the name value from Default to GitHub and uncheck install automatically box
- You’re ready with the Jenkins setup and WE'RE DONE!
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.
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?