├── .gitignore ├── code ├── Docker │ └── Dockerfile ├── Kubernetes │ ├── deploy.sh │ ├── deployment.yaml │ ├── namespace.yaml │ ├── secret.yaml │ └── service.yaml ├── ansible │ ├── hosts │ ├── jenkins-master-setup.yaml │ ├── v1-jenkins-slave-setup.yaml │ └── v2-jenkins-slave-setup.yaml └── terraform │ ├── eks │ ├── eks.tf │ ├── output.tf │ └── variables.tf │ ├── sg_eks │ ├── output.tf │ ├── sg.tf │ └── variables.tf │ └── vpc │ └── v1-ec2.tf └── lab-docs ├── L1-terraform_install.md ├── L10-Publish_docker_image.md ├── L11-Kuberentes_setup_using_terraform.md ├── L12-Integrate_build_server_with_Kubernetes_cluster.md ├── L13-Kubernetes_secrets.md ├── L14-Helm_setup.md ├── L15-Helm_chart_for_ttrend.md ├── L16-Prometheus_and_Grafana_setup.md ├── L2-Connect_to_AWS.md ├── L3-Write_your_1st_terraform_file.md ├── L4-terraform_VPC_with_EC2.md ├── L5-terraform_foreach.md ├── L6-Ansible_setup.md ├── L7-Jenkins_master_and_slave_setup.md ├── L8-GitHub_webhook.md └── L9-Jfrog_Artifactory.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.tfstate 2 | *.tfstate.* 3 | **/.terraform/* 4 | **/.terraform.lock.hcl -------------------------------------------------------------------------------- /code/Docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8 2 | ADD jarstaging/com/valaxy/demo-workshop/2.0.2/demo-workshop-2.0.2.jar ttrend.jar 3 | ENTRYPOINT ["java", "-jar", "ttrend.jar"] -------------------------------------------------------------------------------- /code/Kubernetes/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | kubectl apply -f namespace.yaml 3 | kubectl apply -f secret.yaml 4 | kubectl apply -f deployment.yaml 5 | kubectl apply -f service.yaml -------------------------------------------------------------------------------- /code/Kubernetes/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: valaxy-rtp 5 | namespace: valaxy 6 | spec: 7 | replicas: 1 8 | selector: 9 | matchLabels: 10 | app: valaxy-rtp 11 | template: 12 | metadata: 13 | labels: 14 | app: valaxy-rtp 15 | spec: 16 | imagePullSecrets: 17 | - name: jfrogcred 18 | containers: 19 | - name: valaxy-rtp 20 | image: valaxy01.jfrog.io/valaxy-docker/ttrend/2.0.2 21 | imagePullPolicy: Always 22 | ports: 23 | - containerPort: 8000 24 | env: 25 | - name: CONSUMER_KEY 26 | value: "G6lmKhsi0V9TvXt6oKTfjRBCr" 27 | - name: CONSUMER_SECRET 28 | value: "bEyDk8X0p8SQd4376eoNV4nH8To22sHcJOoFt0ZqOKS37hhI4q" 29 | - name: ACCESS_TOKEN 30 | value: "9703354-52rXHD6EeOQeYyhtNz1w8UVOgbcLcgOo4O7MB6WV3" 31 | - name: ACCESS_TOKEN_SECRET 32 | value: "zBThlZDEp8qnu7NwwdHNth8eg3Rf9zqbvUEFUTaZtN2SF" 33 | -------------------------------------------------------------------------------- /code/Kubernetes/namespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: valaxy -------------------------------------------------------------------------------- /code/Kubernetes/secret.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Secret 3 | metadata: 4 | name: cred 5 | namespace: valaxy 6 | data: 7 | .dockerconfigjson: WVhKemNtRjJhWE5BWjIxaGFXd3VZMjl0T2xaaGJHRjRlVUF4TWpNPQ== 8 | type: kubernetes.io/dockerconfigjson -------------------------------------------------------------------------------- /code/Kubernetes/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: valaxy-rtp-service 5 | namespace: valaxy 6 | spec: 7 | type: NodePort 8 | selector: 9 | app: valaxy-rtp 10 | ports: 11 | - nodePort: 30082 12 | port: 8000 13 | targetPort: 8000 -------------------------------------------------------------------------------- /code/ansible/hosts: -------------------------------------------------------------------------------- 1 | [jenkins-master] 2 | 10.1.1.196 3 | [jenkins-master:vars] 4 | ansible_user=ubuntu 5 | ansible_ssh_private_key_file=/opt/dpo.pem 6 | 7 | [jenkins-slave] 8 | 10.1.1.72 9 | 10 | [jenkins-slave:vars] 11 | ansible_user=ubuntu 12 | ansible_ssh_private_key_file=/opt/dpo.pem 13 | -------------------------------------------------------------------------------- /code/ansible/jenkins-master-setup.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: jenkins-master 3 | become: true 4 | tasks: 5 | - name: download Jenkins repo key 6 | apt_key: 7 | url: https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key 8 | state: present 9 | 10 | - name: Add Jenkins repo 11 | apt_repository: 12 | repo: 'deb https://pkg.jenkins.io/debian-stable binary/' 13 | state: present 14 | 15 | - name: install java 16 | apt: 17 | name: openjdk-11-jre 18 | state: present 19 | 20 | - name: install jenkins 21 | apt: 22 | name: jenkins 23 | state: present 24 | 25 | - name: start jenkins service 26 | service: 27 | name: jenkins 28 | state: started 29 | 30 | - name: enable jenkins service to start at boot time 31 | service: 32 | name: jenkins 33 | enabled: yes 34 | -------------------------------------------------------------------------------- /code/ansible/v1-jenkins-slave-setup.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: jenkins-slave 3 | become: true 4 | tasks: 5 | - name: install java-11 6 | apt: 7 | name: openjdk-11-jre 8 | state: present 9 | 10 | - name: Download maven packages 11 | get_url: 12 | url: https://dlcdn.apache.org/maven/maven-3/3.9.1/binaries/apache-maven-3.9.1-bin.tar.gz 13 | dest: /opt 14 | 15 | - name: Extract packages 16 | unarchive: 17 | src: /opt/apache-maven-3.9.1-bin.tar.gz 18 | dest: /opt 19 | remote_src: yes -------------------------------------------------------------------------------- /code/ansible/v2-jenkins-slave-setup.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: jenkins-slave 3 | become: true 4 | tasks: 5 | - name: install java-11 6 | apt: 7 | name: openjdk-11-jre 8 | state: present 9 | 10 | - name: Download maven packages 11 | get_url: 12 | url: https://dlcdn.apache.org/maven/maven-3/3.9.1/binaries/apache-maven-3.9.1-bin.tar.gz 13 | dest: /opt 14 | 15 | - name: Extract packages 16 | unarchive: 17 | src: /opt/apache-maven-3.9.1-bin.tar.gz 18 | dest: /opt 19 | remote_src: yes 20 | 21 | - name: Install Docker 22 | apt: 23 | name: docker.io 24 | state: present 25 | 26 | - name: start docker service 27 | service: 28 | name: docker 29 | state: started 30 | 31 | - name: give 777 permission on /var/run/docker.sock 32 | file: 33 | path: /var/run/docker.sock 34 | state: file 35 | mode: "0777" 36 | 37 | - name: enable docker service to start at boot time 38 | service: 39 | name: docker 40 | enabled: yes 41 | 42 | -------------------------------------------------------------------------------- /code/terraform/eks/eks.tf: -------------------------------------------------------------------------------- 1 | resource "aws_iam_role" "master" { 2 | name = "valaxy-eks-master" 3 | 4 | assume_role_policy = < search "edit the environment variables" and click on it 11 | Under the advanced tab, chose "Environment variables" --> under the system variables select path variable 12 | and add terraform location in the path variable. system variables --> select path 13 | add new --> terraform_Path 14 | in my system, this path location is C:\Program Files\terraform_1.3.7 15 | 16 | 1. Run the below command to validate terraform version 17 | ```sh 18 | terraform -version 19 | ``` 20 | the output should be something like below 21 | ```sh 22 | Terraform v1.3.7 23 | on windows_386 24 | ``` 25 | 26 | ### Install Visual Studio code 27 | 28 | Download vs code latest version from [here](https://code.visualstudio.com/download) and install it. 29 | 30 | ### AWSCLI installation 31 | 32 | 33 | Download AWSCLI latest version from [here](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) and install it. 34 | 35 | or you can run the below command in powershell or the command prompt 36 | 37 | -------------------------------------------------------------------------------- /lab-docs/L10-Publish_docker_image.md: -------------------------------------------------------------------------------- 1 | ## Build and Publish a Docker image 2 | 3 | 1. Write and add dockerfile in the source code 4 | ```sh 5 | FROM openjdk:8 6 | ADD jarstaging/com/valaxy/demo-workshop/2.0.2/demo-workshop-2.0.2.jar demo-workshop.jar 7 | ENTRYPOINT ["java", "-jar", "demo-workshop.jar"] 8 | ``` 9 | `Check-point:` version number in pom.xml and dockerfile should match 10 | 1. Create a docker repository in the Jfrog 11 | repository name: valaxy-docker 12 | 1. Install `docker pipeline` plugin 13 | 14 | 1. Update Jenkins file with the below stages 15 | ```sh 16 | def imageName = 'valaxy01.jfrog.io/valaxy-docker/ttrend' 17 | def version = '2.0.2' 18 | stage(" Docker Build ") { 19 | steps { 20 | script { 21 | echo '<--------------- Docker Build Started --------------->' 22 | app = docker.build(imageName+":"+version) 23 | echo '<--------------- Docker Build Ends --------------->' 24 | } 25 | } 26 | } 27 | 28 | stage (" Docker Publish "){ 29 | steps { 30 | script { 31 | echo '<--------------- Docker Publish Started --------------->' 32 | docker.withRegistry(registry, 'artifactory_token'){ 33 | app.push() 34 | } 35 | echo '<--------------- Docker Publish Ended --------------->' 36 | } 37 | } 38 | } 39 | ``` 40 | 41 | Check-point: 42 | 1. Provide jfrog repo URL in the place of `valaxy01.jfrog.io/valaxy-docker` in `def imageName = 'valaxy01.jfrog.io/valaxy-docker/ttrend'` 43 | 2. Match version number in `def version = '2.0.2'` with pom.xml version number 44 | 3. Ensure you have updated credentials in the field of `artifactory_token` in `docker.withRegistry(registry, 'artifactory_token'){` 45 | 46 | Note: make sure docker service is running on the slave system, and docker should have permissions to /var/run/docker.sock -------------------------------------------------------------------------------- /lab-docs/L11-Kuberentes_setup_using_terraform.md: -------------------------------------------------------------------------------- 1 | ## Setup Kubernetes cluster using terraform 2 | 1. EKS module code is available over [here](https://github.com/ravdy/RTP-03/tree/main/terraform/v7-EC2_VPC_and_EKS/eks) 3 | Through this eks module we are creating 4 | - IAM Roles 5 | - IAM Policies 6 | - EKS Cluster 7 | - Node Group 8 | 9 | 1. Copy eks and sg_eks modules onto terraform folder 10 | 2. Create vpc folder and move existing files inside to this 11 | 12 | 3. Add one extra subnet in vpc.tf file 13 | 14 | ```sh 15 | // Create 2nd a Subnet 16 | resource "aws_subnet" "dpw-public_subnet_02" { 17 | vpc_id = aws_vpc.dpw-vpc.id 18 | cidr_block = "10.1.2.0/24" 19 | map_public_ip_on_launch = "true" 20 | availability_zone = "us-east-1b" 21 | tags = { 22 | Name = "dpw-public_subnet_02" 23 | } 24 | } 25 | ``` 26 | 27 | 4. Add additional subnet association in the vpc.tf file 28 | 29 | ```sh 30 | resource "aws_route_table_association" "rtp03-rta-public-subnet-2" { 31 | subnet_id = aws_subnet.dpw-public_subnet_02.id 32 | route_table_id = aws_route_table.dpw-public-rt.id 33 | 34 | } 35 | ``` 36 | 37 | 6. Add sg_eks module and eks modules in the vpc.tf file 38 | ```sh 39 | module "sgs" { 40 | source = "../sg_eks" 41 | vpc_id = aws_vpc.dpw-vpc.id 42 | } 43 | 44 | module "eks" { 45 | source = "../eks" 46 | vpc_id = aws_vpc.dpw-vpc.id 47 | subnet_ids = [aws_subnet.dpw-public_subent_01.id,aws_subnet.dpw-public_subent_02.id] 48 | sg_ids = module.sgs.security_group_public 49 | } 50 | ``` 51 | by this time we are ready with our terraform modules to create a cluster -------------------------------------------------------------------------------- /lab-docs/L12-Integrate_build_server_with_Kubernetes_cluster.md: -------------------------------------------------------------------------------- 1 | ## Integrate build server with Kubernetes cluster 2 | 3 | 1. Setup kubectl 4 | ```sh 5 | curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.24.9/2023-01-11/bin/linux/amd64/kubectl 6 | chmod +x ./kubectl 7 | mv ./kubectl /usr/local/bin 8 | kubectl version 9 | ``` 10 | 11 | 1. Make sure you have installed awscli latest version. If it has awscli version 1.X then remove it and install awscli 2.X 12 | ```sh 13 | yum remove awscli 14 | curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" 15 | unzip awscliv2.zip 16 | sudo ./aws/install --update 17 | ``` 18 | 19 | 1. Configure awscli to connect with aws account 20 | ```sh 21 | aws configure 22 | Provide access_key, secret_key 23 | ``` 24 | 25 | 1. Download Kubernetes credentials and cluster configuration (.kube/config file) from the cluster 26 | 27 | ```sh 28 | aws eks update-kubeconfig --region us-east-1 --name valaxy-eks-01 29 | ``` 30 | -------------------------------------------------------------------------------- /lab-docs/L13-Kubernetes_secrets.md: -------------------------------------------------------------------------------- 1 | ## Integrate Jfrog with Kubernetes cluster 2 | 3 | 1. Create a dedicated user to use for a docker login 4 | user menu --> new user 5 | `user name`: jfrogcred 6 | `email address`: valaxytech@gmail.com 7 | `password`: 8 | 9 | 2. To pull an image from jfrog at the docker level, we should log into jfrog using username and password 10 | ```sh 11 | docker login https://valaxy01.jfrog.io 12 | ``` 13 | 1. Kubernetes uses credentials as part of the deployment process to pull the image; for this, we must create a secret at the Kubernetes level 14 | ```sh 15 | kubectl create secret docker-registry jfrogcred \ 16 | --docker-server=valaxy01.jfrog.io \ 17 | --docker-username=kubernetes_admin \ 18 | --docker-password=Admin@123 \ 19 | --docker-email=valaxytech@gmail.com \ 20 | -n valaxy 21 | ``` 22 | 23 | alternatively, you can also run the below command to create secret file 24 | ```sh 25 | kubectl create secret generic jfrogcred --from-file=.dockerconfigjson=/root/.docker/config.json --type=kubernetes.io/dockerconfigjson -n valaxy -o yaml > secret.yaml 26 | ``` 27 | 28 | anotherway is, genarate encode value for ~/.docker/config.json file 29 | ```sh 30 | cat ~/.docker/config.json | base64 -w0 31 | ``` 32 | 33 | `Note:` For more refer to [Kuberentes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/) 34 | Make sure secret value name `regcred` is updated in the deployment file. 35 | 36 | `copy auth value to encode` 37 | cat ~/.docker/config.json | base64 -w0 38 | `use above command output in the secret` 39 | ``` 40 | -------------------------------------------------------------------------------- /lab-docs/L14-Helm_setup.md: -------------------------------------------------------------------------------- 1 | # Helm setup 2 | 3 | 1. Install helm 4 | ```sh 5 | curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 6 | chmod 700 get_helm.sh 7 | ./get_helm.sh 8 | ``` 9 | 1. Validate helm installation 10 | ```sh 11 | helm version 12 | helm list 13 | ``` 14 | 1. Download .kube/config file to build the node 15 | ```sh 16 | aws eks update-kubeconfig --region ap-south-1 --name ed-eks-01 17 | ``` 18 | 19 | 1. Setup helm repo 20 | ```sh 21 | helm repo list 22 | helm repo add stable https://charts.helm.sh/stable 23 | helm repo update 24 | helm search repo 25 | helm search repo stable 26 | ``` 27 | 28 | 1. Install msql charts on Kubernetes 29 | ```sh 30 | helm install demo-mysql stable/mysql 31 | ``` 32 | 1. To pull the package from repo to local 33 | ```sh 34 | helm pull stable/mysql 35 | ``` 36 | 37 | *Once you have downloaded the helm chart, it comes as a zip file. You should extract it.* 38 | 39 | In this directory, you can find 40 | - templates 41 | - values.yaml 42 | - README.md 43 | - Chart.yaml 44 | 45 | If you'd like to change the chart, please update your templates directory and modify the version (1.6.9 to 1.7.0) in the chart.yaml 46 | 47 | then you can run the command to pack it after your update 48 | ```sh 49 | helm package mysql 50 | ``` 51 | 52 | To deploy helm chat 53 | ```sh 54 | helm install mysqldb mysql-1.6.9.tgz 55 | ``` 56 | 57 | Above command deploy MySQL 58 | To check deployment 59 | ```sh 60 | helm list 61 | ``` 62 | To uninstall 63 | ```sh 64 | helm uninstall mysqldb 65 | ``` 66 | 67 | To install nginx 68 | ```sh 69 | helm repo search nginx 70 | helm install demo-nginx stable/nginx-ingress -------------------------------------------------------------------------------- /lab-docs/L15-Helm_chart_for_ttrend.md: -------------------------------------------------------------------------------- 1 | # Create a custom Helm chart 2 | 3 | 1. To create a helm chart template 4 | ```sh 5 | helm create ttrend 6 | ``` 7 | 8 | by default, it contains 9 | values.yaml 10 | templates 11 | Charts.yaml 12 | charts 13 | 14 | 2. Replace the template directory with the manifest files and package it 15 | ```sh 16 | helm package ttrend 17 | ``` 18 | 3. Change the version number in the 19 | ```sh 20 | helm install ttrend ttrend-0.1.0.tgz 21 | ``` 22 | 23 | 4. Create a jenkins job for the deployment 24 | ```sh 25 | stage(" Deploy ") { 26 | steps { 27 | script { 28 | echo '<--------------- Helm Deploy Started --------------->' 29 | sh 'helm install ttrend ttrend-0.1.0.tgz' 30 | echo '<--------------- Helm deploy Ends --------------->' 31 | } 32 | } 33 | } 34 | ``` 35 | 36 | 5. To list installed helm deployments 37 | ```sh 38 | helm list -a 39 | ``` 40 | 41 | Other useful commands 42 | 1. to change the default namespace to valaxy 43 | ```sh 44 | kubectl config set-context --current --namespace=valaxy 45 | ``` -------------------------------------------------------------------------------- /lab-docs/L16-Prometheus_and_Grafana_setup.md: -------------------------------------------------------------------------------- 1 | # Prometheus setup 2 | ### pre-requisites 3 | 1. Kubernetes cluster 4 | 2. helm 5 | 6 | ## Setup Prometheus 7 | 8 | 1. Create a dedicated namespace for prometheus 9 | ```sh 10 | kubectl create namespace monitoring 11 | ``` 12 | 13 | 2. Add Prometheus helm chart repository 14 | ```sh 15 | helm repo add prometheus-community https://prometheus-community.github.io/helm-charts 16 | ``` 17 | 18 | 3. Update the helm chart repository 19 | ```sh 20 | helm repo update 21 | helm repo list 22 | ``` 23 | 24 | 4. Install the prometheus 25 | 26 | ```sh 27 | helm install prometheus prometheus-community/kube-prometheus-stack --namespace monitoring 28 | ``` 29 | 30 | 5. Above helm create all services as ClusterIP. To access Prometheus out side of the cluster, we should change the service type load balancer 31 | ```sh 32 | kubectl edit svc prometheus-kube-prometheus-prometheus -n monitoring 33 | 34 | ``` 35 | 6. Loginto Prometheus dashboard to monitor application 36 | https://:9090 37 | 38 | 7. Check for node_load15 executor to check cluster monitoring 39 | 8. 40 | 9. We check similar graphs in the Grafana dashboard itself. for that, we should change the service type of Grafana to LoadBalancer 41 | ```sh 42 | kubectl edit svc prometheus-grafana 43 | ``` 44 | 45 | 10. To login to Grafana account, use the below username and password 46 | ```sh 47 | username: admin 48 | password: prom-operator 49 | ``` 50 | 11. Here we should check for "Node Exporter/USE method/Node" and "Node Exporter/USE method/Cluter" 51 | USE - Utilization, Saturation, Errors 52 | 53 | 12. Even we can check the behavior of each pod, node, and cluster -------------------------------------------------------------------------------- /lab-docs/L2-Connect_to_AWS.md: -------------------------------------------------------------------------------- 1 | ## Connect to AWS Cloud 2 | 3 | You must have an AWS account to proceed with the below steps. 4 | 1. Create an IAM programmatic user with administrator access 5 | 2. Configure credentials 6 | ```sh 7 | aws configure --profile 8 | ``` 9 | 3. Test the connection 10 | ```sh 11 | aws s3 ls 12 | ``` 13 | -------------------------------------------------------------------------------- /lab-docs/L3-Write_your_1st_terraform_file.md: -------------------------------------------------------------------------------- 1 | ## Write your 1st terraform file 2 | 3 | Let's create an EC2 instance as part of our 1st terraform file 4 | 5 | To create an ec2 instance, We should connect to aws account first 6 | 7 | in terraform file 8 | we can connect to AWS cloud using 'provider block' 9 | to create an ec2 instance, should use 'resource block' 10 | 1. In the provider block, mention the cloud name, and region name 11 | ```sh 12 | provider "aws" { 13 | project = "acme-app" 14 | region = "us-central1" 15 | } 16 | ``` 17 | 18 | 1. In the resource block, We should mention information to create an instance. 19 | 2. To create an EC2 instance (object), we should have the below information 20 | - Instance name 21 | - Operating system (AMI) 22 | - instance Type 23 | - Keypair 24 | - VPC 25 | - Storage 26 | 27 | But among these, AMI id, instance type, and keypair are required arguments. 28 | These should be defined in the resource block 29 | ```sh 30 | resource "aws_instance" "web" { 31 | ami = "ami-a1b2c3d4" 32 | instance_type = "t2.micro" 33 | keypair = "demo_key" 34 | } 35 | ``` 36 | 37 | So the final file looks [like this](v1-ec2.tf) 38 | -------------------------------------------------------------------------------- /lab-docs/L4-terraform_VPC_with_EC2.md: -------------------------------------------------------------------------------- 1 | # Terraform file to create VPC and EC2 2 | So far, we have created an EC2 instance with the Security group. Now let's create these in a separate VPC. 3 | For that, we need to create VPC first. 4 | 5 | In VPC, there are various steps involved. 6 | 1. Create VPC 7 | 2. Create a Subnet 8 | 3. Create Internet Gateway 9 | 4. Create RouteTable 10 | 5. Route Table Association 11 | 12 | ## let's create one by one 13 | 14 | ### 1. Create VPC 15 | 16 | To create a VPC, we need a CIDR block. So the resource block looks like the below. 17 | ```sh 18 | resource "aws_vpc" "dpw-vpc" { 19 | cidr_block = "10.1.0.0/16" 20 | tags = { 21 | Name = "dpw-vpc" 22 | } 23 | } 24 | ``` 25 | 26 | ### 2. Create Subnet 27 | We should create a subnet under VPC. So we should mention VPC's name over here. But we get VPC once the resource is created right. so to pull up name dynamically, we can use "resource_name.resource_label.id" In this case, it is going to be 28 | `aws_vpc.dpw-vpc.id` 29 | 30 | So the subnet snippet looks like the one below. 31 | 32 | ```sh 33 | //Create a Subnet 34 | resource "aws_subnet" "dpw-public_subent_01" { 35 | vpc_id = aws_vpc.dpw-vpc.id 36 | cidr_block = "10.1.1.0/24" 37 | map_public_ip_on_launch = "true" 38 | availability_zone = "us-east-1a" 39 | tags = { 40 | Name = "dpw-public_subent_01" 41 | } 42 | } 43 | ``` 44 | 45 | ### 3. Create Internet Gateway 46 | 47 | We should create an internet gateway and add this to VPC for this 48 | 49 | ```sh 50 | //Creating an Internet Gateway 51 | resource "aws_internet_gateway" "dpw-igw" { 52 | vpc_id = aws_vpc.dpw-vpc.id 53 | tags = { 54 | Name = "dpw-igw" 55 | } 56 | } 57 | ``` 58 | 59 | #### 4. Create route table 60 | 61 | ```sh 62 | // Create a route table 63 | resource "aws_route_table" "dpw-public-rt" { 64 | vpc_id = aws_vpc.dpw-vpc.id 65 | route { 66 | cidr_block = "0.0.0.0/0" 67 | gateway_id = aws_internet_gateway.dpw-igw.id 68 | } 69 | tags = { 70 | Name = "dpw-public-rt" 71 | } 72 | } 73 | ``` 74 | # 5. Route table association 75 | 76 | ```sh 77 | // Associate subnet with route table 78 | 79 | resource "aws_route_table_association" "dpw-rta-public-subent-1" { 80 | subnet_id = aws_subnet.dpw-public_subent_01.id 81 | route_table_id = aws_route_table.dpw-public-rt.id 82 | } 83 | ``` 84 | 85 | after this [terraform v3 file]() looks like this -------------------------------------------------------------------------------- /lab-docs/L5-terraform_foreach.md: -------------------------------------------------------------------------------- 1 | # for_each in terraform 2 | 3 | To create multiple EC2 instances in a single file we can use for_each 4 | 5 | we can added below code snippet to the existing terraform file to create 3 instances as per our requirement. 6 | 7 | ```sh 8 | for_each = toset(["master", "slave"]) 9 | tags = { 10 | Name = "${each.key}" 11 | } 12 | ``` 13 | 14 | after this [terraform v4 file]() looks like this -------------------------------------------------------------------------------- /lab-docs/L6-Ansible_setup.md: -------------------------------------------------------------------------------- 1 | 2 | # Setup Ansible 3 | 1. Install ansibe on Ubuntu 22.04 4 | ```sh 5 | sudo apt update 6 | sudo apt install software-properties-common 7 | sudo add-apt-repository --yes --update ppa:ansible/ansible 8 | sudo apt install ansible 9 | ``` 10 | 11 | 2. Add Jenkins master and slave as hosts 12 | Add jenkins master and slave private IPs in the inventory file 13 | in this case, we are using /opt is our working directory for Ansible. 14 | ``` 15 | [jenkins-master] 16 | 18.209.18.194 17 | [jenkins-master:vars] 18 | ansible_user=ec2-user 19 | ansible_ssh_private_key_file=/opt/dpo.pem 20 | [jenkins-slave] 21 | 54.224.107.148 22 | [jenkins-slave:vars] 23 | ansible_user=ec2-user 24 | ansible_ssh_private_key_file=/opt/dpo.pem 25 | ``` 26 | 27 | 1. Test the connection 28 | ```sh 29 | ansible -i hosts all -m ping 30 | ``` 31 | -------------------------------------------------------------------------------- /lab-docs/L7-Jenkins_master_and_slave_setup.md: -------------------------------------------------------------------------------- 1 | # Jenkins Master and Slave Setup 2 | 3 | 1. Add credentials 4 | 2. Add node 5 | 6 | ### Add Credentials 7 | 1. Manage Jenkins --> Manage Credentials --> System --> Global credentials --> Add credentials 8 | 2. Provide the below info to add credentials 9 | kind: `ssh username with private key` 10 | Scope: `Global` 11 | ID: `maven_slave` 12 | Username: `ec2-user` 13 | private key: `dpo.pem key content` 14 | 15 | ### Add node 16 | Follow the below setups to add a new slave node to the jenkins 17 | 1. Goto Manage Jenkins --> Manage nodes and clouds --> New node --> Permanent Agent 18 | 2. Provide the below info to add the node 19 | Number of executors: `3` 20 | Remote root directory: `/home/ec2-user/jenkins` 21 | Labels: `maven` 22 | Usage: `Use this node as much as possible` 23 | Launch method: `Launch agents via SSH` 24 | Host: `` 25 | Credentials: `` 26 | Host Key Verification Strategy: `Non verifying Verification Strategy` 27 | Availability: `Keep this agent online as much as possible` -------------------------------------------------------------------------------- /lab-docs/L8-GitHub_webhook.md: -------------------------------------------------------------------------------- 1 | # Enable Webhook 2 | 1. Install "multibranch scan webhook trigger" plugin 3 | From dashboard --> manage jenkins --> manage plugins --> Available Plugins 4 | Search for "Multibranch Scan webhook Trigger" plugin and install it. 5 | 6 | 2. Go to multibranch pipeline job 7 | job --> configure --> Scan Multibranch Pipeline Triggers --> Scan Multibranch Pipeline Triggers --> Scan by webhook 8 | Trigger token: `` 9 | 10 | 3. Add webhook to GitHub repository 11 | Github repo --> settings --> webhooks --> Add webhook 12 | Payload URl: `:8080/multibranch-webhook-trigger/invoke?token=` 13 | Content type: `application/json` 14 | Which event would you like to trigger this webhook: `just the push event` 15 | 16 | 17 | Once it is enabled make changes to source to trigger the build. 18 | -------------------------------------------------------------------------------- /lab-docs/L9-Jfrog_Artifactory.md: -------------------------------------------------------------------------------- 1 | ## Publish jar file onto Jfrog Artifactory 2 | 1. Create Artifactory account 3 | 2. Generate an access token with username (username must be your email id) 4 | 3. Add username and password under jenkins credentials 5 | 4. Install Artifactory plugin 6 | 5. Update Jenkinsfile with jar publish stage 7 | ```sh 8 | def registry = 'https://valaxy01.jfrog.io' 9 | stage("Jar Publish") { 10 | steps { 11 | script { 12 | echo '<--------------- Jar Publish Started --------------->' 13 | def server = Artifactory.newServer url:registry+"/artifactory" , credentialsId:"artifactory_token" 14 | def properties = "buildid=${env.BUILD_ID},commitid=${GIT_COMMIT}"; 15 | def uploadSpec = """{ 16 | "files": [ 17 | { 18 | "pattern": "jarstaging/(*)", 19 | "target": "libs-release-local/{1}", 20 | "flat": "false", 21 | "props" : "${properties}", 22 | "exclusions": [ "*.sha1", "*.md5"] 23 | } 24 | ] 25 | }""" 26 | def buildInfo = server.upload(uploadSpec) 27 | buildInfo.env.collect() 28 | server.publishBuildInfo(buildInfo) 29 | echo '<--------------- Jar Publish Ended --------------->' 30 | 31 | } 32 | } 33 | } 34 | ``` 35 | 36 | Check-point: 37 | Ensure below are update 38 | 1. your jfrog account details in place of `https://valaxy01.jfrog.io` in the defination of registry `def registry = 'https://valaxy01.jfrog.io'` 39 | 2. Credentials id in the place of `jfrogforjenkins` in the `def server = Artifactory.newServer url:registry+"/artifactory" , credentialsId:"artifactory_token"` 40 | 3. Maven repository name in the place of `libs-release-local` in the `"target": "ttrend-libs-release-local/{1}",` 41 | 42 | --------------------------------------------------------------------------------