How to create EC2 instance in AWS console using new UI experience?
What is EC2 instance?
It is virtual server provided by AWS. We will be using this EC2 to setup both Jenkins and Tomcat. Please follow the below steps to create an EC2 instance.
click on All services, Click on Compute --> Click on EC2
2. Click on Launch instance
3. Enter Name as EC2 and enter 2 as number of instances
4. Select Ubuntu and choose Ubuntu server 18.0.4 as AMI
5. Enter t2.small as instance type
6. Click on Create new Key Pair
7. Choose the existing key pair if you have one, otherwise create new one, give some name as myJenkinsKey. Make sure you download the key in your local machine.Please do NOT give space or any character while naming the key.
8. Under Network settings, Click Edit
Add port range as 8080 and select AnyWhere as Source Type, that should enter 0.0.0.0/0 as Source
9. Enter 10 GB as storage
And then make sure in Summary, values appear as below:
10. Click on Launch Instance.
Click on View instances
Now you should be able to view instances in AWS console.
Connect to EC2 instance from local machine: Please click the below link to understand the steps for connecting to EC2 instance from your local machine - windows or Apple laptop.
(If you already have a WebApp setup in Azure cloud, move to next step)
You need to create WebApp in Azure Cloud. WebApp is an App service (mostly Platform as a Service) provide by Azure Cloud to migrate any web applications.
Click here to learn how to create WebApp in Azure Portal.
Create Azure Build YAML pipeline in Azure DevOps
Login to Azure DevOps, go to your project dashboard.
Click on Pipelines --> new pipeline
Select GitHub or where ever your source code is
Select your code repo
Choose the below option --> Maven package Java project web app to Linux on Azure
Choose the azure subscription, click on continue
Enter your Microsoft account details for Azure pipelines to authenticate with Azure cloud for deploying WebApp into App service.
Now choose web app name from the drop down
Click on validate and configure
Now Review Azure pipeline code
and make sure path of mom.xml is added properly as MyWebApp/pom.xml
Click on Save and Run
Once you save the file, you can confirm by logging into your GitHub repo.
Now Build must be running. Once build is successful, we need to give permission for deployment into Azure. Click on Review
This confirms that webapp is deployed successfully in Azure cloud.
Verify the webapp deployment into Azure cloud
go to App settings of WebApp, copy the URL and enter /MyWebApp
https://enteryourwebappurl/MyWebApp
that's it..that is how you deploy Web App from Azure pipelines into Azure cloud.
Please follow the steps to install Jenkins using Docker compose on Ubuntu 18.0.4 instance.
What is Docker Compose?
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.
The purpose of docker-compose is to function as docker cli but to issue multiple commands much more quickly. To make use of docker-compose, you need to encode the commands you were running before into a docker-compose.yml file
Run docker-compose up and Compose starts and runs your entire app.
Change Host Name to Jenkins sudo hostname Jenkins
Perform update first sudo apt update
Now lets start Docker. compose installation first:
Install Docker-Compose
sudo apt-get install docker-compose -y
Add current user to docker group
sudo usermod -aG docker $USER
Create directory
mkdir ~/jenkins
Jenkins Setup
Create docker-compose.yml
this yml has all configuration for installing Jenkins
sudo vi docker-compose.yml
version: '3.3'
services:
jenkins:
image: jenkins/jenkins:lts
restart: unless-stopped
privileged: true
user: root
ports:
- 8080:8080
container_name: jenkins
volumes:
- ~/jenkins:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
- /usr/local/bin/docker:/usr/local/bin/docker
Now execute the compose file using Docker compose command:
Now Go to AWS console. Click on EC2, click on running instances link. Select the checkbox of EC2 you installed Jenkins. Click on Action. Copy the value from step 4 that says --> Connect to your instance using its Public DNS:
Now go to browser. enter public dns name or public IP address with port no 8080.
One of the amazing features of Terraform is, it tracks the infrastructure that you provision. It does this through the means of state. By default, Terraform stores state locally in a file named terraform.tfstate. This does not work well in a team environment where if any developer wants to make a change he needs to make sure nobody else is updating terraform in the same time. You need to use remote storage to store state file.
With remote state, Terraform writes the state data to a remote data store, which can then be shared between all members of a team. Terraform supports storing state in many ways including the below:
Terraform Cloud
HashiCorp Consul
Amazon S3
Azure Blob Storage
Google Cloud Storage
Alibaba Cloud OSS
Artifactory or Nexus
We will learn how to store state file in Azure Blob storage. We will be creating Azure storage account and container.
Amazon EKS is a fully managed container orchestration service. EKS allows you to quickly deploy a production ready Kubernetes cluster in AWS, deploy and manage containerized applications more easily with a fully managed Kubernetes service.
EKS takes care of master node/control plane. We need to create worker nodes.
EKS cluster can be created in following different ways
1. AWS console
2. AWS CLI
3. eksctl command
4. using Terraform
We will create EKS cluster using eksctl command line tool.
Please watch the steps in YouTube channel:
Pre-requistes:
This Lab is using Jenkins EC2 instance. Jenkins EC2 instance needs to have following configured:
Install AWS CLI– Command line tools for working with AWS services, including Amazon EKS.
Install eksctl– A command line tool for working with EKS clusters that automates many individual tasks.
Install kubectl – A command line tool for working with Kubernetes clusters.
Create IAM Role with Administrator Access
You need to create an IAM role with AdministratorAccess policy. Go to AWS console, IAM, click on Roles. create a role
Select AWS services, Click EC2, Click on Next permissions.
Now search for AdministratorAccess policy and click
Skip on create tag. Now give a role name and create it.
Assign the role to EC2 instance Go to AWS console, click on EC2, select EC2 instance, Choose Security. Click on Modify IAM Role
Choose the role you have created from the dropdown. Select the role and click on Apply.
Switch to Jenkins user
sudo su - jenkins
Create EKS Cluster with two worker nodes using eksctl
the above command should create a EKS cluster in AWS, it might take 15 to 20 mins. The eksctl tool uses CloudFormation under the hood, creating one stack for the EKS master control plane and another stack for the worker nodes.
Once EKS cluster is created, kubeconfig file be created under /var/lib/jenkins/.kube folder.
you can view the kubeconfig file by entering the below command:
cat /var/lib/jenkins/.kube/config
Connect to EKS cluster using kubectl commands
To view the list of worker nodes as part of EKS cluster.
kubectl get nodes
kubectl get ns
Deploy Nginx on a Kubernetes Cluster Let us run some apps to make sure they are deployed to Kubernetes cluster. The below command will create deployment: