Jenkins Setup on AWS EC2 Instance

Architecture

Architecture

The provisioning process will incur costs and do not use following configuration for production setup.

Prerequisites

  • Personal AWS Account
  • AWS EC2 & VPC access

Below are the following AWS resources to be created during provisioning process.

AWS Resources

TypeDescription
EC2AWS EC2 Instance t3.medium (Jenkins Server)
EC2AWS EC2 Instance t3.small (Jenkins Slave)
EBS Root Volume50GB gp3 for Jenkins Server
EBS Root Volume50GB gp3 for Jenkins Slave
Public IPDynamic Public ip address for Jenkins Server
Public IPDynamic Public ip address for Jenkins Slave
Security Groupjenkins-server-cloud-workshop allow ports 80/443/22
Security Groupjenkins-slave-cloud-workshop allow ports 22
Key PairRSA Algorithm for SSH connection

Tools Used for this workshop

Tools
Bash Script
Terraform
Ansible
AWSCLI

Provisioning Process

To start the provisioning process.

  1. Login to you aws account through https://console.aws.amazon.com.

AWS Console Login

  1. After login, click the highlighted button (CloudShell)

Note: Make sure you are in ap-southeast-1 region on AWS console

AWS Cloud Shell Button

  1. After that, it will prepare your cloud shell environment

Cloud Shell Preparing

  1. Once cloudshell is ready. Clone the repository and navigate to the lab-src where our script is located.
## Clone the repository
git clone https://github.com/redopsbay/cloudworkshop-lab-source.git
cd cloudworkshop-lab-source//AWS/cicd/jenkins/jenkins-setup-ec2
  1. Make workshop.sh as executable file. So, we can execute it.
chmod +x workshop.sh
  1. Now, Execute the workshop.sh via:
./workshop.sh
  1. You will be prompt for the desired actions:
============= Choose target action =============

1) Setup CLI Binaries

2) Provision Jenkins

3) Cleanup Terraform Resources

Choose action:
  1. Choose 1 as desired action to install necessary package dependencies such as terraform cli.
============= Choose target action =============

1) Setup CLI Binaries

2) Provision Jenkins

3) Cleanup Terraform Resources

Choose action: 1

Setup CLI Dependencies

  1. Next, Provision the jenkins server via:
./workshop.sh

============= Choose target action =============

1) Setup CLI Binaries

2) Provision Jenkins

3) Cleanup Terraform Resources

Choose action: 2

The provisioning process will use your AWS default VPC for the sake of this workshop.

VPC details

Specify VPC Details

Provisioning

Provisioning

EC2 Instances

Jenkins Installation with Ansible

Jenkins Installation with Ansible

just wait for a few minutes. The Jenkins initial admin password will be provided at the console.

Jenkins initial admin password

Here, After a few minutes, the jenkins initial admin password has been displayed.

  1. Navigate to jenkins server by getting the server_public_dns value from terraform output. In my case http://ec2-13-212-62-187.ap-southeast-1.compute.amazonaws.com

Jenkins initial admin login

  1. Click Install Suggested Plugin.

  2. Then, setup your new Admin account.

Jenkins first admin user

Cleanup resources

To avoid such costs. We have to cleanup our AWS resources.

  1. Navigate again to your cloudshell and navigate to the cloudworkshop-lab-source/AWS/cicd/jenkins/jenkins-setup-ec2 directory.

  2. Next, run the workshop.sh script via:

./workshop.sh
  1. Choose 3 to cleanup terraform resources.

Cleanup Terminated Instances

Reference