Day 40 of #90DaysOfDevOps
Task1:
Create a launch template with Amazon Linux 2 AMI and t2.micro instance type with Jenkins and Docker setup.
Create 3 Instances using Launch Template, there must be an option that shows the number of instances to be launched.
You can go one step ahead and create an auto-scaling group.
Solution:
To create a launch template, follow the steps:
Go to the EC2 dashboard and click on the "Launch templates" under instances
Click on "Create launch template"
Enter the name and description of the template. Make sure to check the auto-scaling guidance.
Next, Choose Amazon Linux 2 AMI and instance type (t2.micro)
Create/Select Key pair for login.
Choose network settings.
After that in the Advance section, scroll down to user data and enter the below data.
#!/bin/bash # Update system sudo yum update -y # Install Apache Server sudo yum install httpd -y sudo systemctl start httpd sudo systemctl enable httpd cd /var/www/html/ sudo touch index.html sudo chmod 666 index.html sudo echo '<div style="text-align:center;font-family:arial;"><h1>New instance created by Neel - Your DevOps Guy</h1></div>' > index.html # Install Java for Jenkins sudo amazon-linux-extras install java-openjdk11 -y # Install Jenkins sudo wget -O /etc/yum.repos.d/jenkins.repo \ https://pkg.jenkins.io/redhat-stable/jenkins.repo sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key sudo yum update -y sudo yum install jenkins -y sudo systemctl enable jenkins sudo systemctl start jenkins # Install Jenkins sudo yum install docker -y sudo systemctl enable docker sudo systemctl start docker
Finally, click on Create launch template to create.
Now to launch the template, select the template and click on Actions and then launch instance from template.
Next, you need to enter the number of instances you want to create. Enter 3 and launch.
In the dashboard, you will find new 3 instances running.
Create an Auto-Scaling group from the template
From the launch template dashboard, click on actions and then "create auto-scaling group"
In the next step, you need to fill up the form to setup the auto-scalling.
First, Enter the name and choose the template.
Then select the vpc and the availability zones.
Next, in the load balancer, click on attach new.
At the bottom, check the monitoring option
Now configure the group size and scaling policy.
Next, in the notification, click on add and then create one.
After setting up the email for SNS, review the whole setup. Finally, Click on Create the auto-scaling group.
After successfully creating it, you can find it on the auto-scaling dashboard.
To confirm, go to the instance dashboard to find out running instances.
You will also receive emails from AWS after each successful launch of the instance.
Thank You.