https://www.coachdevops.com/2020/03/how-to-create-jenkinsfile-how-to.html

 


////////////////

//////////////////////////////////////////////////////////////////////////////////////////
CREDENTIAALS:

//////////////////////////////////////////////////////////////////////////////////////////
bitbucket:
https://bitbucket.org/dashboard/overview
rohit17jan@gmail.com
rohit17jan17jan

https://bitbucket.org/rohit17jan17jan/myawesomeangularapprepo/src/master/

//////////////////////////////////////////////////////////////////////////////////////////


https://www.coachdevops.com/2019/01/pre-requisites-before-starting-devops.html

Monday, January 14, 2019

Pre-requisites before starting the DevOps Coaching

Please Watch the video first before you get started:


1. Create an account in https://aws.amazon.com. Set that as basic free tier account (personal account). role as developer or anything. You need to enter credit card info. But that’s fine, they won’t charge you except $1.
Sign up free account.

Select Basic Plan..Do NOT select developer plan unless you would like to pay every month.


2. Create an account in https://www.bitbucket.org and https://github.com/
Sign up using your email.
3. Start learning Linux Basics 
    Sign up for Linux Basics courses in https://www.udemy.com/topic/linux-administration/

4. Learn Agile/DevOps

5. If you are using windows laptop, Install Git client on your laptop by downloading from http://www.git-scm.com/download


Click on download, once downloaded. Go to downloads directory and click on the EXE.
Choose all options by default by clicking on Next and NExt


6. Only if you are using Macbook pro or iMac desktop, please download iTerm from https://www.iterm2.com/downloads.html. for windows laptop, ignore this step.
Download the iTerm2**.zip file and install iTerm on Mac.


//////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////

https://www.coachdevops.com/2019/02/create-ec2-instance-how-to-create-ec2.html

Saturday, February 9, 2019

Create EC2 Instance - How to create EC2 instance in AWS console

Please follow the below steps to create an EC2 instance. EC2 instance is virtual server provided by AWS. We will be using this EC2 to install Java, Jenkins, Tomcat, Maven. We will be using this as a CI server.

Steps:

1: Go to AWS console. click on All services, Click on Compute -->  Click on EC2



2. Click on Launch instance. Choose an Amazon machine image (AMI), click next


3. select 
Ubuntu Server 16.04 LTS (HVM), SSD Volume Type


click next

4. choose an instance type as t2.small, 2GB memory. click next

5. Leave values to default in step 3 and step 4. click next


6. enter tag name in step 5. Click to add a Name tag. it can be something like JenkinsEC2click next:configure Security Group



7. Click create new security group, give name as MyJenkinsSecurityGroup, add custom rule for 8080, 8090 , allow 0.0.0.0/0 as source IP


8. Click on Review and launch


Click on Launch

09. Choose the existing key pair if you have one, otherwise create new one, give some name as my2020EC2Key. Make sure you download the key. Please do not give any space or any character in naming the key.


10. Click on launch instance, Scroll down and click on view instances.











Once instance is created. you can see it running..Please click the below link to understand the steps for connecting to EC2 instance from your local machine - windows or Apple laptop.



How to connect to EC2 using Git bash or ITerm in Mac? 

http://www.cidevops.com/2018/02/how-to-connect-to-ec2-instance-from.html

1. go to Downloaded location private key in your local machine.
2. Copy the url from Ec2 console by selecting the instance, click on actions, connect. Please use the above link to connect to EC2 from your local machine.

Watch here for live demo:




//////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////


//////////////

//////////////

https://www.youtube.com/watch?v=f0Rbk1iVhnc&list=PLJwvtUqYDmA77rUJ3a_SQgeNpzQka-NGU

Sunday, March 8, 2020

How to create Jenkinsfile | How to configure Declarative Pipeline | create Jenkins Pipeline As code

Please find steps below for configuring pipeline as a code - Jenkinsfile.

Pre-requistes:

1. Project setup in Bitbucket/GitHub/GitLab
2. Jenkins and Tomcat (web container) set up.
3. Maven installed in Jenkins
4. Sonarqube setup and integrated with Jenkins
5. Nexus configured and integrated with Jenkins
6. Slack channel configured an integrated with Jenkins

Create Jenkinsfile (pipeline code) to your MyWebApp

Step 1

Go to GitHub and choose the Repo where you setup MyWebApp in Lab exercise # 2

Step 2
Click on create new file.


Step 3 - Enter Jenkinsfile as a file name
 

Step 4

Copy and paste the below code and make sure what ever is highlighted in red color needs to be changed per your settings.

That's it. Pipeline as a code - Jenkinsfile is setup in GitHub.

pipeline {
  agent any
 
  tools {
  maven 'Maven3'
  }
  stages {
    stage ('Build') {
      steps {
      sh 'mvn clean install -f MyWebApp/pom.xml'
      }
    }
    stage ('Code Quality') {
      steps {
        withSonarQubeEnv('SonarQube') {
        sh 'mvn -f MyWebApp/pom.xml sonar:sonar'
        }
      }
    }
    stage ('JaCoCo') {
      steps {
      jacoco()
      }
    }
    stage ('Nexus Upload') {
      steps {
      nexusArtifactUploader(
      nexusVersion: 'nexus3',
      protocol: 'http',
      nexusUrl: 'nexus_url:8081',
      groupId: 'myGroupId',
      version: '1.0-SNAPSHOT',
      repository: 'maven-snapshots',
      credentialsId: 'fc0f1694-3036-41fe-b3e3-4c5d96fcfd26',
      artifacts: [
      [artifactId: 'MyWebApp',
      classifier: '',
      file: 'MyWebApp/target/MyWebApp.war',
      type: 'war']
      ])
      }
    }
    stage ('DEV Deploy') {
      steps {
      echo "deploying to DEV Env "
      deploy adapters: [tomcat9(credentialsId: '268c42f6-f2f5-488f-b2aa-f2374d229b2e', path: '', url: 'http://your_public_dns:8080')], contextPath: null, war: '**/*.war'
      }
    }
    stage ('Slack Notification') {
      steps {
        echo "deployed to DEV Env successfully"
        slackSend(channel:'your slack channel_name', message: "Job is successful, here is the info - Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
      }
    }

    stage ('DEV Approve') {
      steps {
      echo "Taking approval from DEV Manager for QA Deployment"
        timeout(time: 7, unit: 'DAYS') {
        input message: 'Do you want to deploy?', submitter: 'admin'
        }
      }
    }

     stage ('QA Deploy') {
      steps {
        echo "deploying to QA Env "
        deploy adapters: [tomcat9(credentialsId: '268c42f6-f2f5-488f-b2aa-f2374d229b2e', path: '', url: 'http://your_dns_name:8080')], contextPath: null, war: '**/*.war'
        }
    }
    stage ('QA Approve') {
      steps {
        echo "Taking approval from QA manager"
        timeout(time: 7, unit: 'DAYS') {
        input message: 'Do you want to proceed to PROD?', submitter: 'admin,manager_userid'
        }
      }
    }

    stage ('Slack Notification for QA Deploy') {
      steps {
        echo "deployed to QA Env successfully"
        slackSend(channel:'your slack channel_name', message: "Job is successful, here is the info - Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
      }
    }  

  }
}


Step 5
That's it. Pipeline as a code - Jenkinsfile is setup in GitHub.

Click on commit to save into GitHub.

Create Pipeline and Run pipeline from Jenkinsfile

1. Login to Jenkins
2. Click on New item, give some name and choose Pipeline and say OK


3. Under build triggers, choose Poll SCM,
Enter H/02 * * * *


4. Under Pipeline section. click on choose pipeline script from SCM

5. Under SCM, choose Git


6. Enter HTTPS URL of repo and choose credentials - enter user name/password of GitHub.
Script path as Jenkinsfile

7. Click on Apply and Save
8. Click on Build now.

You should see pipeline running and application is deployed to Tomcat.

Declarative Jenkins Pipeline YouTube Video is below:


///////////////////////////


///////////////////////////

Jenkins is an Open source, Java-based automation tool. This tool automates the Software Integration and delivery process called Continuous Integration and Continuous Delivery. Jenkins support various source code management, build, and delivery tools. Jenkins is #1 Continuous integration tool, especially new features like Jenkins Pipelines (Scripted and Declarative Pipeline) makes the delivery process very easy and help Team to adopt DevOps easily. https://www.cidevops.com/2018/12/crea...  What are Pipelines in Jenkins? Why we need to use them? - Pipelines are better than freestyle jobs, you can write a lot of complex tasks using pipelines when compared to Freestyle jobs. - You can see how long each stage takes time to execute so you have more control compared to freestyle. - Pipeline is groovy based script that have set of plug-ins integrated for automating the builds, deployment and test execution. - Pipeline defines your entire build process, which typically includes stages for building an application, testing it and then delivering it. - You can use snippet generator to generate pipeline code for the stages you don't know how to write groovy code. - Pipelines are two types - Scripted pipeline and Declarative pipeline. Click here to know the difference between them.

https://www.youtube.com/watch?v=nfmt4HWhp5k&list=PLJwvtUqYDmA77rUJ3a_SQgeNpzQka-NGU&index=2


Thursday, December 27, 2018

Jenkins Scripted Pipeline - Create Jenkins Pipeline for Automating Builds, Code quality checks, Deployments to Tomcat - How to build, deploy WARs using Jenkins Pipeline - Build pipelines integrate with Bitbucket, Sonarqube, Slack, JaCoCo, Nexus, Tomcat

What are Pipelines in Jenkins?

- Pipelines are better than freestyle jobs, you can write a lot of complex tasks using pipelines when compared to Freestyle jobs.
- You can see how long each stage takes time to execute so you have more control compared to freestyle.
- Pipeline is groovy based script that have set of plug-ins integrated for automating the builds, deployment and test execution.
- Pipeline defines your entire build process, which typically includes stages for building an application, testing it and then delivering it. 
 - You can use snippet generator to generate pipeline code for the stages you don't know how to write groovy code.
- Pipelines are two types - Scripted pipeline and Declarative pipeline. Click here to know the difference between them.

Pre-requistes:
Install plug-ins
1. Install Deploy to container, Slack, Jacoco, Nexus Artifact Uploader and SonarQube plug-ins (if already installed, you can skip it)

Steps to Create Scripted Pipeline in Jenkins

1. Login to Jenkins

2. Create a New item

3. Give name as MyfirstPipelineJob and choose pipeline

4. Click ok. Pipeline is created now

5. Under build triggers, click on poll SCM, schedule as

H/02 * * * *

6. Go to Pipeline definition section, click on Pipeline syntax link. under sample step drop down, choose checkout: Checkout from version control. enter bitbucket or GitHub Repository URL, and enter right credentials. Click here to learn to use PSA if you are using GitHub. scroll down, click on Generate Pipeline script. Copy the code.

7. Now copy the below pipeline code highlighted section into Pipeline section in the pipeline. Please copy stage by stage

8. Change Maven3, SonarQube variables and also Slack channel name as highlighted above in red as per your settings.

9. For Nexus Upload stage, You need to change the Nexus URL and credentials ID for Nexus (which you can grab from Credentials tab after login)

10. For Dev Deploy stage, you can copy credentials ID used for connecting to Tomcat.


Pipeline Code:

node {

    def mvnHome = tool 'Maven3'
    stage ("checkout")  {
       copy code here which you generated from step #6
    }

   stage ('build')  {
    sh "${mvnHome}/bin/mvn clean install -f MyWebApp/pom.xml"
    }

     stage ('Code Quality scan')  {
       withSonarQubeEnv('SonarQube') {
       sh "${mvnHome}/bin/mvn -f MyWebApp/pom.xml sonar:sonar"
        }
   }
  
   stage ('Code coverage')  {
       jacoco()
   }

   stage ('Nexus upload')  {
        nexusArtifactUploader(
        nexusVersion: 'nexus3',
        protocol: 'http',
        nexusUrl: 'nexus_url:8081',
        groupId: 'myGroupId',
        version: '1.0-SNAPSHOT',
        repository: 'maven-snapshots',
        credentialsId: '2c293828-9509-49b4-a6e7-77f3ceae7b39',
        artifacts: [
            [artifactId: 'MyWebApp',
             classifier: '',
             file: 'MyWebApp/target/MyWebApp.war',
             type: 'war']
        ]
     )
    }
   
   stage ('DEV Deploy')  {
      echo "deploying to DEV Env "
      deploy adapters: [tomcat9(credentialsId: '4c55fae1-a02d-4b82-ba34-d262176eeb46', path: '', url: 'http://your_tomcat_url:8080')], contextPath: null, war: '**/*.war'

    }

  stage ('Slack notification')  {
    slackSend(channel:'channel-name', message: "Job is successful, here is the info -  Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
   }

   stage ('DEV Approve')  {
            echo "Taking approval from Manager for QA Deploy"     
            timeout(time: 7, unit: 'DAYS') {
            input message: 'Do you approve to deploy into QA environment?', submitter: 'admin'
            }
     }

stage ('QA Deploy')  {
     echo "deploying into QA Env " 
deploy adapters: [tomcat9(credentialsId: '4c55fae1-a02d-4b82-ba34-d262176eeb46', path: '', url: 'http://your_tomcat_url:8080')], contextPath: null, war: '**/*.war'

}

stage ('QA Approve')  {
    echo "Taking approval from QA manager"
    timeout(time: 7, unit: 'DAYS') {
        input message: 'Do you want to proceed to PROD Deploy?', submitter: 'admin,manager_userid'
  }
}

stage ('PROD Deploy')  {
     echo "deploying into PROD Env " 
deploy adapters: [tomcat9(credentialsId: '4c55fae1-a02d-4b82-ba34-d262176eeb46', path: '', url: 'http://your_tomcat_url:8080')], contextPath: null, war: '**/*.war'

}
}

11. Click Apply, Save
12. Now click on Build. It should execute all the stages and show pipeline view like this.




You can watch the Scripted pipeline video in my YouTube channel:





////////////////////////////


////////////////////////////

3.93K subscribers
SUBSCRIBED
Create Jenkins pipeline for the following: - Automating builds - Automating Docker image creation - Automating Docker image upload into DockerHub - Automating Docker container provisioning https://www.coachdevops.com/2020/05/a... Bitbucket URL is - https://bitbucket.org/ananthkannan/my... Pre-requistes: 1. Jenkins is up and running 2. Docker installed on Jenkins instance and configured. 3. Docker plug-in installed in Jenkins 4. user account setup in https://cloud.docker.com 5. port 8096 is opened up in firewall rules.
////////////////////////////
https://www.youtube.com/watch?v=UTziA84ynvo&list=PLJwvtUqYDmA77rUJ3a_SQgeNpzQka-NGU&index=3

Sunday, May 3, 2020

Create Jenkins Pipeline for automating Docker image creation and push docker image into Docker Hub | Dockerize Python App

We will learn how to automate Docker builds using Jenkins. We will use Python based application. I have already created a repo with source code + Dockerfile. We will be creating Jenkins pipeline for automating builds.


- Automating builds
- Automating Docker image creation
- Automating Docker image upload
- Automating Docker container provisioning

Pre-requistes:
1. Jenkins is up and running
2. Docker installed on Jenkins instance and configured.
3. Docker plug-in installed in Jenkins
4. user account setup in https://cloud.docker.com
5. port 8096 is opened up in firewall rules.

Step #1 - Create Credentials for Docker Hub
Go to your Jenkins where you have installed Docker as well. Go to credentials -->


Click on Global credentials
Click on Add Credentials


Now Create an entry for Docker Hub credentials

Make sure you take note of the ID as circled below:


Step # 2 - Create a pipeline in Jenkins, name can be anything

Step # 3 - Copy the pipeline code from below
Make sure you change red highlighted values below:
Your docker user id should be updated.
your registry credentials ID from Jenkins from step # 1 should be copied

pipeline {
    agent any 
    environment {
        //once you sign up for Docker hub, use that user_id here
        registry = "your_docker_user_id/mypythonapp"
        //- update your credentials ID after creating credentials for connecting to Docker Hub
        registryCredential = 'fa32f95a-2d3e-4c7b-8f34-11bcc0191d70'
        dockerImage = ''
    }
    
    stages {
        stage('Cloning Git') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '', url: 'https://bitbucket.org/ananthkannan/mypythonrepo']]])       
            }
        }
    
    // Building Docker images
    stage('Building image') {
      steps{
        script {
          dockerImage = docker.build registry
        }
      }
    }
    
     // Uploading Docker images into Docker Hub
    stage('Upload Image') {
     steps{    
         script {
            docker.withRegistry( '', registryCredential ) {
            dockerImage.push()
            }
        }
      }
    }
    
     // Stopping Docker containers for cleaner Docker run
     stage('docker stop container') {
         steps {
            sh 'docker ps -f name=mypythonappContainer -q | xargs --no-run-if-empty docker container stop'
            sh 'docker container ls -a -fname=mypythonappContainer -q | xargs -r docker container rm'
         }
       }
    
    
    // Running Docker container, make sure port 8096 is opened in 
    stage('Docker Run') {
     steps{
         script {
            dockerImage.run("-p 8096:5000 --rm --name mypythonappContainer")
         }
      }
    }
  }
}

Step # 4 - Click on Build - Build the pipeline
Once you create the pipeline and changes values per your Docker user id and credentials ID, click on 

Steps # 5 - Access Python App
Once build is successful, go to browser and enter http://public_dns_name:8096
You should see page like below:




////////////////////////////


////////////////////////////
DevOps Coach
3.93K subscribers
SUBSCRIBED
https://www.coachdevops.com/2020/06/deploy-python-app-into-kubernetes.html We will learn how to automate Docker builds using Jenkins and Deploy into Kubernetes Cluster. We will use Python based application. I have already created a repo with source code + Dockerfile. The repo also have Jenkinsfile for automating the following: - Automating builds using Jenkins - Automating Docker image creation - Automating Docker image upload into Docker registry - Automating Deployments to Kubernetes Cluster Pre-requistes: 1. AKS Cluster is setup and running.Click here to learn how to create AKS cluster. 2. Jenkins Master is up and running. 3. Setup Jenkins slave, install docker in it. 4. Docker, Docker pipeline and Kubernetes Deploy plug-ins are installed in Jenkins

https://www.youtube.com/watch?v=5C6kzqeO4Ew&list=PLJwvtUqYDmA77rUJ3a_SQgeNpzQka-NGU&index=4

////////////////////////////

Tuesday, June 9, 2020

Deploy Python App into Kubernetes Cluster using Jenkins Pipeline | Containerize Python App and Deploy into AKS Cluster

We will learn how to automate Docker builds using Jenkins and Deploy into Kubernetes Cluster setup using AKS. We will use Python based application. I have already created a repo with source code + Dockerfile. The repo also have Jenkinsfile for automating the following:

- Automating builds using Jenkins
- Automating Docker image creation
- Automating Docker image upload into Docker registry
- Automating Deployments to Kubernetes Cluster

Pre-requistes:
1. AKS Cluster is setup and running. Click here to learn how to create AKS cluster.
2. Jenkins Master is up and running. 
3. Setup Jenkins slave to run Docker builds
4. Docker, Docker pipeline and Kubernetes Deploy plug-ins are installed in Jenkins



5. Docker hub account setup in https://cloud.docker.com


Step #1 - Create Credentials for Docker Hub
Go to Jenkins UI, click on Credentials -->


Click on Global credentials
Click on Add Credentials


Now Create an entry for your Docker Hub account. Make sure you enter the ID as dockerhub

Step #2 - Create Credentials for Kubernetes Cluster
Click on Add Credentials, use Kubernetes configuration from drop down.


execute the below command to get kubeconfig info, copy the entire content of the file:
sudo cat ~/.kube/config


Enter ID as K8S and choose enter directly and paste the above file content and save.

Step # 3 - Create a pipeline in Jenkins
Create a new pipeline job.


Step # 4 - Copy the pipeline code from below
Make sure you change red highlighted values below:
Your docker user id should be updated.
your registry credentials ID from Jenkins from step # 1 should be copied

pipeline {
     agent {
         label 'myslave'
     }
        environment {
        //once you sign up for Docker hub, use that user_id here
        registry = "your_docker_hub_user_id/mypython-app"
        //- update your credentials ID after creating credentials for connecting to Docker Hub
        registryCredential = 'dockerhub'
        dockerImage = ''
    }
    stages {

        stage ('checkout') {
            steps {
            checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/akannan1087/myPythonDockerRepo']]])
            }
        }
       
        stage ('Build docker image') {
            steps {
                script {
                dockerImage = docker.build registry
                }
            }
        }
       
         // Uploading Docker images into Docker Hub
    stage('Upload Image') {
     steps{   
         script {
            docker.withRegistry( '', registryCredential ) {
            dockerImage.push()
            }
        }
      }
    }
   
    stage ('K8S Deploy') {
        steps {
            script {
                kubernetesDeploy(
                    configs: 'k8s-deployment.yaml',
                    kubeconfigId: 'K8S',
                    enableConfigSubstitution: true
                    )           
               
            }
        }
    }
  
    }  
}

Step # 5 - Build the pipeline
Once you create the pipeline and changes values per your Docker user id and credentials ID, click on 

Step # 6 - Verify deployments to K8S

kubectl get pods


kubectl get deployments
kubectl get services

Steps # 7 - Access Python App in K8S cluster
Once build is successful, go to browser and enter master or worker node public ip address along with port number mentioned above
http://master_or_worker_node_public_ipaddress:port_no_from_above

You should see page like below:


Please watch the above steps in YouTube channel: 


////////////////////////////


////////////////////////////
https://www.coachdevops.com/2020/10/how-to-create-aks-cluster-using-aure.html

Thursday, October 1, 2020

How to create AKS cluster using Azure CLI | Create Kubernetes Cluster using Azure CLI

What is Azure Kubernetes Service (AKS)

AKS is a managed Kubernetes service that lets you quickly deploy and manage clusters. We will see how to create AKS cluster in Azure cloud using Azure CLI.

Pre-requistes:

  • Azure CLI is installed on your local machine.
  • Account setup in Azure.

Create Resource Group

Make sure you are login to Azure portal first.

az login

You need to create a resource group first.

az group create --name myResourceGroup --location southcentralus

Create AKS cluster with 2 worker nodes

az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 2 --enable-addons monitoring --generate-ssh-keys

az aks show --name myAKSCluster --resource-group myResourceGroup

The above command should display Cluster exists in Azure portal

Create Azure Container Registry

Run the below command to create your own private container registry using Azure Container Registry (ACR).

az acr create --resource-group myResourceGroup --name myacrrepo --sku Standard --location southcentralus

Connect to the cluster

 az aks get-credentials --resource-group myResourceGroup --name myAKSCluster --overwrite-existing

To verify the connection to your cluster, use the kubectl get command to return a list of the cluster nodes.

kubectl get nodes

 

 

 

# List all deployments in a specific namespace

kubectl get deployments --all-namespaces=true



 

 

Let's deploy some apps into AKS cluster. 

Deploy Nginx App

kubectl create -f https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/controllers/nginx-deployment.yaml

Once the deployment is created, use kubectl to check on the deployments by running this command: 

kubectl get deployments




Delete the cluster

To avoid Azure charges, you should clean up unneeded resources. When the cluster is no longer needed, use the az group delete command to remove the resource group, container service, and all related resources. 

az group delete --name myResourceGroup --yes --no-wait

Please watch the above steps in action in YouTube



////////////////////////////
https://www.coachdevops.com/2020/12/how-to-setup-jenkins-slave-node-to-run.html

Tuesday, December 8, 2020

How to setup Jenkins slave node to run Docker Builds | Setup Jenkins Slave and Install Docker

How to configure Jenkins Slave to run Docker builds?

Create User as Jenkins
sudo useradd -m jenkins
sudo -u jenkins mkdir /home/jenkins/.ssh




Steps for installing Docker
sudo apt-get update && sudo apt install docker.io -y
 
Install Maven
sudo apt-get install maven -y
 
Add Jenkins to Docker Group
sudo usermod -aG docker jenkins
sudo newgrp docker
sudo systemctl daemon-reload
 
Restart Docker service
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl restart docker


Login to Jenkins Master and restart Jenkins service
sudo service jenkins restart
(Make sure you execute this in Jenkins Master)

Add SSH Keys from Master to Slave 

Execute the below command in Jenkins master Ec2.
sudo cat ~/.ssh/id_rsa.pub

Copy the output of the above command:

Now go to Slave node and execute the below command
sudo -u jenkins vi /home/jenkins/.ssh/authorized_keys

This will be empty file, now copy the public keys from master into above file.
Once you pasted the public keys in the above file in Slave, come out of the file by entering wq!

 Login to master node and try to SSH from Master to Slave
ssh jenkins@slave_node_ip





this is to make sure master is able to connect slave node. once you are successfully logged into slave, type exit to come out of slave.



Now copy SSH keys into /var/lib/jenkins/.ssh folder also by executing below command in Jenkins master(make sure you exited from slave by typing exit command:

sudo cp ~/.ssh/known_hosts  /var/lib/jenkins/.ssh

Register slave node in Jenkins:
Now to go Jenkins Master, manage jenkins, manage nodes.









Click on new node. give name and check permanent agent.
give name and no of executors as 1. enter /home/jenkins as remote directory.
select launch method as Launch slaves nodes via SSH.
enter Slave node ip address as Host.











click on credentials. Enter user name as jenkinsMake jenkins lowercase as it is shown.
 Kind as SSH username with private key. enter private key of master node directly by executing below command:

sudo cat ~/.ssh/id_rsa
(Make sure you copy the whole key including the below without missing anything)
-----BEGIN RSA PRIVATE KEY-----
-----
-----END RSA PRIVATE KEY-----

click Save.
select Host key verification strategy as "manually trusted key verification strategy".

Click Save.
Click on launch agent..make sure it connects to agent node.

 
That's it! Jenkins Master and Slave is configured up!

////////////////////////////
I followed the same steps as mentioned by you. But get to see the below message(in master)

ubuntu@ip-172-31-58-13:~$ sudo service jenkins restart
ubuntu@ip-172-31-58-13:~$ sudo cat ~/.ssh/id_rsa.pub
cat: /home/ubuntu/.ssh/id_rsa.pub: No such file or directory
ubuntu@ip-172-31-58-13:~$


I googled and found that you missed to specify one command. Let me know if this is the case..

ubuntu@ip-172-31-58-13:~$ ssh-keygen -t rsa -C "MyEmailAddress" -f ~/.ssh/id_rsa -P ""
Generating public/private rsa key pair.
Your identification has been saved in /home/ubuntu/.ssh/id_rsa.
Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:pUlkEw5AXcRCKunGNI5n+BSOvy+S7bX99E6T651K2Q4 MyEmailAddress
The key's randomart image is:
+---[RSA 2048]----+
| .o+o+B. |
| . .o=.. |
| * . .o . |
| X + . + |
|+ X S |
| B + |
| oo . . E . |
|o oo o . + * . |
| oooo ...o*.+ |
+----[SHA256]-----+
ubuntu@ip-172-31-58-13:~$ sudo cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRiJyy7P7kHsHxgwW+5t9+BFMYxt995WVseE1nphQCV6BUXxXE74Y1OEuA2VP3dYGZJ33TKSS8OYH6D+AmSufwgmUZ4CkdbsUSKDeeo2SSbDu/z+eeeghmd5Ccmxx4oyx/A01Bwl4fbOumQoeTASxUbYdO0B3C1aXCF6+2sZJAJQ/2O5tOuwi3gbbAe/kJ+GkfjiHkhSC0UXg1wtjZ72XflNNGYo2bHYlFu8wpMRiYRhGGlVIXWjZEQFSR9TGF5V76d1ceJqoA/rRJfija8Wr8I2HX5VPMP62bkLWtP1y51fI+9atSH1+gUMAZERQ+U161P7eA+UEa/5j5AHt7PSjp MyEmailAddress
ubuntu@ip-172-31-58-13:~$


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
https://www.youtube.com/watch?v=XoX00V3yxys&list=PLJwvtUqYDmA77rUJ3a_SQgeNpzQka-NGU&index=5

Jenkins Pipeline for Microservices Deployment to EKS Cluster | Jenkins Kubernetes Deployment to EKS


DevOps Coach
3.93K subscribers
SUBSCRIBED
https://www.cidevops.com/2020/12/deploy-springboot-docker-app-into.html Source code url is https://bitbucket.org/ananthkannan/my... We will use Springboot Microservices based Java application. I have already created a repo with source code + Dockerfile. The repo also have Jenkinsfile for automating the following: - Automating builds using Jenkins - Automating Docker image creation - Automating Docker image upload into Docker Hub - Automating Deployments to Kubernetes Cluster Pre-requistes: 1. Amazon EKS Cluster is setup and running. Click here to learn how to create Amazon EKS cluster. 2. Jenkins Master is up and running 3. Setup Jenkins slave, install docker in it. 4. Docker, Docker pipeline and Kubernetes Deploy plug-ins are installed in Jenkins 5. Docker hub account setup in https://cloud.docker.com 6. Install kubectl on your instance
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Tuesday, December 15, 2020

Deploy Springboot Microservices App into Amazon EKS Cluster using Jenkins Pipeline | Containerize Springboot App and Deploy into EKS Cluster using Jenkins Pipeline

We will learn how to automate Docker builds using Jenkins pipelines and Deploy into AWS EKS - Kubernetes Cluster with help of Kubernetes Continuous Deploy plug-in.

We will use Springboot Microservices based Java application. I have already created a repo with source code + Dockerfile. The repo also have Jenkinsfile for automating the following:


- Automating builds using Jenkins
- Automating Docker image creation
- Automating Docker image upload into Docker Hub
- Automating Deployments to Kubernetes Cluster
 
 

Please watch the above steps in YouTube channel:
Pre-requistes:
1. Amazon EKS Cluster is setup and running. Click here to learn how to create Amazon EKS cluster.
3. Setup Jenkins slave, install docker in it.
4. Docker, Docker pipeline and Kubernetes Continuous Deploy plug-ins are installed in Jenkins



5. Docker hub account setup in https://cloud.docker.com
6. Install kubectl on your instance


Step #1 -Make sure Jenkins can run Docker builds after validating per pre-requistes

Step #2 - Create Credentials for Docker Hub
Go to Jenkins UI, click on Credentials -->


Click on Global credentials
Click on Add Credentials


Now Create an entry for your Docker Hub account. Make sure you enter the ID as dockerhub

Step #3 - Create Credentials for Kubernetes Cluster
Click on Add Credentials, use Kubernetes configuration from drop down.


execute the below command to get kubeconfig info, copy the entire content of the file:
sudo cat ~/.kube/config


Enter ID as K8S and choose enter directly and paste the above file content and save.

Step # 4 - Create Maven3 variable under Global tool configuration in Jenkins

Make sure you create Maven3 variable under Global tool configuration.
 
 
Step #5 - set a clusterrole as cluster-admin

By default, clusterrolebinding has system:anonymous set which blocks the cluster access. Execute the following command to set a clusterrole as cluster-admin which will give you the required access.

kubectl create clusterrolebinding cluster-system-anonymous --clusterrole=cluster-admin --user=system:anonymous

Step # 6 - Create a pipeline in Jenkins
Create a new pipeline job.


Step # 7-  Copy the pipeline code from below
Make sure you change red highlighted values below as per your settings:
Your docker user id should be updated.
your registry credentials ID from Jenkins from step # 1 should be copied


node ("slave") {
  def image
  def mvnHome = tool 'Maven3'
     stage ('checkout') {
        checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '', url: 'https://bitbucket.org/ananthkannan/myawesomeangularapprepo/']]])      
        }
   
    stage ('Build') {
            sh 'mvn -f MyAwesomeApp/pom.xml clean install'           
        }
       
       
    stage ('Docker Build') {
         // Build and push image with Jenkins' docker-plugin
            withDockerRegistry([credentialsId: "dockerhub", url: "https://index.docker.io/v1/"]) {
            image = docker.build("akdevopscoaching/mywebapp", "MyAwesomeApp")
            image.push()    
            }
        }

      stage ('K8S Deploy') {
       
                kubernetesDeploy(
                    configs: 'MyAwesomeApp/springboot-lb.yaml',
                    kubeconfigId: 'K8S',
                    enableConfigSubstitution: true
                    )               
        }
    
}

Step # 8 - Build the pipeline
Once you create the pipeline and changes values per your Docker user id and credentials ID, click on 


Step # 9 - Verify deployments to K8S

kubectl get pods



kubectl get deployments

kubectl get services



Steps # 10 - Access SpringBoot App in K8S cluster
Once build is successful, go to browser and enter master or worker node public ip address along with port number mentioned above
http://master_or_worker_node_public_ipaddress:port_no_from_above

You should see page like below:



////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////

https://www.coachdevops.com/2020/04/install-jenkins-ubuntu-1804-setup.html

Friday, April 10, 2020

Install Jenkins on Ubuntu 18.0.4 | Setup Jenkins on AWS EC2 Ubuntu instance | How to setup Jenkins in Ubuntu EC2 instance?

Please follow steps to install Java, Jenkins, Maven on Ubuntu 18.0.4 instance. 

Jenkins, Maven are Java based applications, so we need to install Java first. 

Perform update first
sudo apt update

Install Java 11
sudo apt-get install default-jdk -y

 
Once install java, enter the below command

Verify Java Version
java -version

Maven Installation
Maven is a popular build tool used for building Java applications. Please click here to learn more about Maven. You can install Maven by executing below command:

sudo apt install maven -y

you can type mvn --version
you should see the below output.



Now lets start Jenkins installation

Jenkins Setup

Add Repository key to the system

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
Append debian package repo address to the system

echo deb http://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list

Update Ubuntu package
sudo apt update
Install Jenkins
sudo apt install jenkins -y


The above screenshot should confirm that Jenkins is successfully installed.

Access Jenkins in web browser

Now Go to AWS console. Click on EC2, click on running instances link. Select the checkbox of EC2 you are installing Java and 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.

Unlock Jenkins
You may get screen, enter the below command in Git bash( Ubuntu console)
Get the initial password from the below file
sudo cat /var/lib/jenkins/secrets/initialAdminPassword


Copy the password and paste in the browser.
Then click on install suggested plug-ins. 
Also create user name and password.
enter everything as admin. at least user name as admin password as admin
Click on Save and Finish. Click on start using Jenkins. Now you should see a screen like below:


That's it. You have setup Jenkins successfully 😊Please watch the steps in action in our YouTube channel: 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Wednesday, September 1, 2021

How to install Terraform on Red Hat Linux | TerraForm Installation on Red Hat Linux

Terraform is an infrastructure as a code tool used for provisioning infrastructure on most of the cloud platforms. 

  • Open source
  • Can setup entire infrastructure by writing Terraform scripts/templates. 
  • Based on declarative model
  • Uses Hashi Corp Language(HCL) which is JSON format

You can watch this on YouTube channel:

Please find steps for installing Terraform On Enterprise Red Hat Linux.

Create a working directory
sudo mkdir -p /opt/terraform
cd /opt/terraform

Install wget utility
sudo yum install wget -y

Download Terraform from Hasicorp website
sudo wget https://releases.hashicorp.com/terraform/1.0.5/terraform_1.0.5_linux_amd64.zip

Install unzip utility
sudo yum install unzip -y

Unzip Terraform Zip file
sudo unzip terraform_1.0.5_linux_amd64.zip

Add terraform to PATH
sudo mv /opt/terraform/terraform /usr/bin/

terraform -version

Terraform v1.0.5
on linux_amd64

this should show version of Terraform.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
https://www.coachdevops.com/2020/10/create-eks-cluster-by-eksctl-how-to.html

Monday, October 12, 2020

Create Amazon EKS cluster by eksctl | How to create Amazon EKS cluster using EKSCTL | Create EKS Cluster in command line

What is Amazon EKS

Amazon EKS is a fully managed container orchestration service. EKS allows you to quickly deploy a production ready Kubernetes cluster in Azure, deploy and manage containerized applications more easily with a fully managed Kubernetes service. 

EKS takes care of Master node/Control plane. We need to manage worker nodes.

Please watch the steps in YouTube channel:

Pre-requistes:

You can use Windows, Macbook or any Ubuntu or Red Hat EC2 instance to setup the below tools.

  • 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. 

Once you install all of the above, you need to have AWS credentials configured in your environment. The aws configure command is the fastest way to set up your AWS CLI installation for general use. 

Make sure you do not have any IAM role attached to the EC2 instance. You can remove IAM role by going into AWS console and Detach the IAM role.

aws configure 

the AWS CLI prompts you for four pieces of information: access keysecret access keyAWS Region, and output format.

Create EKS Cluster using eksctl

eksctl create cluster --name demo-eks --region us-east-2 --nodegroup-name my-nodes --node-type t3.small --managed

the above command should create a EKS cluster in AWS, it might take 5 to 10 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. 

Connect to 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 Kuberneter cluster. The below command will create deployment:

kubectl create deployment nginx --image=nginx


View Deployments
kubectl get deployments

Delete EKS Cluster using eksctl

eksctl delete cluster --name demo-eks --region us-east-2 

the above command should delete the EKS cluster in AWS, it might take a few mins to clean up the cluster.

Errors during Cluster creation
If you are having issues when creating a cluster, try to delete the cluster by executing the below command and re-create it.

eksctl delete cluster --name demo-eks --region us-east-2 


or login to AWS console --> AWS Cloudformation --> delete the stack manually.

you can also delete the cluster under AWS console --> Elastic Kubernetes Service --> Clusters
Click on Delete cluster


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
https://www.coachdevops.com/2019/05/setup-repo-and-create-java-project-in.html

Saturday, May 18, 2019

How to setup SSH keys | How to setup Repo and Create Java Project in GitHub - How to add a project in GitHub

GitHub is one of the popular git-based version control systems. GitHub is very good example for Software-as-a-service, hosted on cloud. Let us learn how to setup a Java web project in GitHub.
Git is a purely distributed version control system. Click here to learn more about Git and its advantages over other SCMs.

Pre-requistes:
1. GitHub account
2. Git client installed

Step # 1 - Create private repository in GitHub.com

Click on New to create a new repo 
Also choose initialize with repository with a README option.

Step # 2 Create SSH keys from your source machine

Login to your Jenkins EC2 instance using Git bash. make sure you are connected to Ec2 instance by ssh url. Type  ssh-keygen (and then simply enter four times, do not give any password). ssh-keygen will generate two keys - public keys and private keys. We need to upload the public keys into GitHub.


copy the content of public key by executing below command in Git bash:
sudo cat ~/.ssh/id_rsa.pub


Step # 3 - Upload SSH Keys in GitHub

Go to GitHub, click on Settings.
Copy SSH keys Key section and then click on Add SSH key.


Step # 4 - Clone Repo locally

Now click on the Cat icon on your top left to go back to repo you just created.
Click on the repo you created in step # 1, click on Code, under SSH
 




Copy the SSH url and go to your EC2 instance using git bash and perform below command:

git clone <paste the ssh url >

type yes to connect

After you clone, you should see something below:







type below command to list the directory
ls -al
The above command should list the directory you have cloned.

Now go into repo folder(red circled like above) you have cloned.
cd MyApplicationRepo

Step # 5 - Create Java Web App using Maven
use below maven command to create Java Web App using Maven. Maven is the build for creating and building java projects. Click here to know more about Maven.

mvn archetype:generate -DgroupId=com.dept.app -DartifactId=MyWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Step # 6 - Push Java Web App using Git commands into GitHub

type below command to see the new folder called MyWebApp
ls -al

type  below command to see the newly created project in red color
git status

Now add the newly created folder by executing below command:
git add  *

Now make sure all the files are moved to staging area, when you execute below command:
git status


Perform below command to commit the changes to local repository first.
git commit -m "my first project check-in to GitHub"

Now perform below command to push from local repository to remote repository. 

git push

 

Verify code changes in GitHub

Now to GitHub and click on the repo, you will see your commits.


You can also watch the videos of the above lab exercise in my YouTube channel given below:





////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
https://www.coachdevops.com/2019/02/create-build-job-in-jenkins-how-to.html

Saturday, February 16, 2019

Create Freestyle job in Jenkins | How to create build job in Jenkins to automate build and deployment

Jenkins is popular open source Continuous integration tool. It was written entirely in Java. Jenkins is a self-contained automation server used for automating builds, tests and deployment.

See below the steps for configuring Jenkins to automate the build and deployment for the project we already set up in Bitbucket or Git Hub.
pre-requisites:(please do this first before you start)

1. Make sure you configure maven installation under Jenkins-->manage Jenkins-> Global Tool Configuration. under maven installation. enter Maven3 as name, enter path of maven installation --> /usr/share/maven and uncheck install automatically option.

2. Also install SonarQube scanner,  deploy to container Jacoco plugins under Jenkins --> Manage Jenkins --> Manage plug-ins

Click on Available, type Sonarqube, select SonarQube scanner. Click on Install without restart.

SonarQube

Deploy to container


JaCoCo

Click on without restart.

3. Generate Personal Access Token(PSA) if you are using GitHub. Click here to learn how to generate that in GitHub and you can use your token as password.

steps to automate MyWebApp project in Jenkins:

1. Login to Jenkins. Click on New item.

2. Enter an item name --> select Free style project.
enter name as myFirstAutomateJob. click OK.
3. under source code mgmt, click git. enter Bitbucket URL or GitHub URL
Click on your repo, Copy the url from the browser. Paste the url as Repository URL below.


under credentials --> click Add- > select Jenkins -->  enter your GitHub username and Personal Access Token as passwordDO NOT use Git Hub password as it is removed from August 13, 2021. Click to here to learn how to generate Personal Access Token. Add description as my SCM credentials.

Enter main as branch specifier or which ever branch you want to check out.

4. select that from drop down.
5. under build trigger click on poll scm, enter this value to check

for every 2 mins --> H/02 * * * *

6. Build --> Add build step --> invoke top level maven targets -->

select Maven3 from drop down and goal as clean install


7. Click on advanced, enter the path of POM file as --> MyWebApp/pom.xml


8. click on Add post build action, select Record Jacoco Code coverage report
  
9. click on Add post build action, select deploy war/ear to container.

      for WAR/EAR files enter as 
          **/*.war


in WAR/EAR files, leave context path empty

   10. click on Add container , select Tomcat 9.x

   11. click on add credentials, enter tomcat as user name and password as password.
      select it from drop down.
 


13. tomcat url should be --> http://your_public_dns_name:8080


click Apply, click Save
click on build now..It should build.
if there is any error, please check the console output. Most of the common error would be checking the path of Maven installation, valid credentials for GitHub or Tomcat. Also make sure you install the plug-ins.

After successful deployment, please make sure you check the output in Tomcat by going to browser and enter below URL

You should see Hello World!!!


This is how you automate the builds and deployments using Jenkins and migrate applications to AWS.

You can watch the video of this lab here:

  

////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////

https://www.coachdevops.com/2020/10/install-kubectl-on-ubuntu-instance-how.html

Tuesday, October 13, 2020

Install kubectl on Ubuntu Instance | How to install kubectl in Ubuntu

Kubernetes uses a command line utility called kubectl for communicating with the cluster API server.

It is tool for controlling Kubernetes clusters. kubectl looks for a file named config in the $HOME/

How to install Kubectl in Ubuntu instance

Download keys from google website
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

Create the below file
sudo touch /etc/apt/sources.list.d/kubernetes.list

echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list

Update package manager
sudo apt-get update

Install
sudo apt-get install -y kubectl

Verify if kubectl got installed
kubectl version --short --client
////////////////////////////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////////////////////////////////////
https://www.coachdevops.com/2019/02/install-java-jenkins-maven-tomcat-on.html

Tuesday, February 12, 2019

Jenkins setup - Install Java, Jenkins, Maven, Tomcat on Ubuntu EC2 - How to install Java, Jenkins, Maven, Tomcat on Ubuntu EC2

Please follow steps to install Java, Jenkins, Maven, Tomcat on Ubuntu EC2. Jenkins is a java based application, so you need to install Java first. 

Java Setup on Ubuntu

sudo apt-get update

Install Java 11

sudo apt-get install default-jdk -y


Now lets do Jenkins installation

Jenkins Setup

Add Repository key to the system

wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
Append debian package repo address to the system

echo deb http://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list

sudo apt-get update
Install Jenkins
sudo apt-get install jenkins -y



The above screenshot should confirm that Jenkins is successfully installed.

Access Jenkins in web browser

Now Go to AWS console.
  Click on EC2, click on running instances link. Select the checkbox of EC2 you are installing Java and 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.This is how to select public DNS name:


Unlock Jenkins
You may get screen, enter the below command in Git bash( Ubuntu console)
Get the password from the below file

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Copy the password and paste in the browser

Click on install suggested plug-ins.
Also create user name and password.
enter everything as admin. at least user name as admin password as admin
Click on Save and Finish. Click on Start to Use.

Maven
Maven is a build tool used for building Java applications. Please click here to learn more about Maven. You can install Maven by executing below command:

sudo apt install maven -y

you can type mvn --version
you should see the below output.


Tomcat Installation

Tomcat is a web server or web container where java web application can be deployed by developers. You can learn more about by clicking this URL.  Tomcat can be installed by executing below commands:

sudo apt-get update
sudo apt-get install tomcat8 -y


sudo apt-get install tomcat8-docs tomcat8-examples tomcat8-admin -y


sudo cp -r /usr/share/tomcat8-admin/* /var/lib/tomcat8/webapps/ -v

Click on this link to know how to make changes using Vi editor.


Change port no from 8080 to 8090
Tomcat default port is also 8080, since we have already used 8080 for Jenkins, we need to change from 8080 to 8090. You can change by modifying server.xml

sudo vi /var/lib/tomcat8/conf/server.xml


you need to scroll down by clicking down arrow button in this file change the port no from 8080 to 8090 at line starting with <Connector port="8080" protocol="HTTP/1.1"

setup an user in tomcat 

sudo vi /var/lib/tomcat8/conf/tomcat-users.xml

Scroll down all the way to the end of the file,
Add the below lines in second last line above (above </tomcat-users>)
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="tomcat" password="password" roles="manager-gui,manager-script"/>

Add more memory to JVM
sudo vi /etc/default/tomcat8

Look for the line starting JAVA_OPTS and comment that line by adding #.
Add the below line:
JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC"

sudo systemctl restart tomcat8

sudo systemctl status tomcat8


you may get message that says tomcat is active running.
press q for quitting from that window. Now go to browser, copy public DNS.

 
You should see a page that says.
It works!!!!

That's it. You have setup both Jenkins and Tomcat successfully!!

Please watch here for live demo:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////



Comments