Devops for Begineers

Topics

Prerequisites:

Overview of DevOps:

  • Understanding the fundamentals of DevOps
  • History and evolution of DevOps
  • Key principles and goals of DevOps
  • DevOps culture and its importance

AWS cloud Overview

Create a Linux VM

  • Login to Aws cloud using your user and Password
  • Select the Region of your choice Region
  • Create a Ec2 instance with ubuntu OS
  • Open a port using in Security Group
  • Install Webserver and test connectivity
apt update -y
apt install apache2 -y
  • Check the service of apache2
systemctl status apache2
  • Start if not started
systemctl start apache2
  • Open Webserver in Browser
publicip
  • If Webserver does not open make sure to open port: 80 as 80 is the default port used by Webserver

Linux Basics Overview:

  • Linux Basics Commands
  • Linux File Structure
  • Linux file management

Basic Linux Commands

  • whoami: Print currenlty logged in user
  • pwd: Print working directory, shows the current directory you’re in.
  • ls: List directory contents, shows files and directories in the current directory.
  • cd: Change directory, move to a different directory.
    • cd directory_name: Move to a specific directory.
    • cd ..: Move up one directory level.
  • mkdir: Make directory, create a new directory.
    • mkdir directory_name: Create a directory with the specified name.
  • touch: Create a new empty file.
    • touch file_name: Create a file with the specified name.
  • rm: Remove files or directories.
    • rm file_name: Remove a file.
    • rm -r directory_name: Remove a directory and its contents recursively.
  • cp: Copy files or directories.
    • cp source_file destination_file: Copy a file to a new location.
    • cp -r source_directory destination_directory: Copy a directory and its contents to a new location.
  • mv: Move or rename files or directories.
    • mv source destination: Move a file or directory to a new location.
    • mv old_name new_name: Rename a file or directory.
  • cat: Concatenate and display file content.
    • cat file_name: Display the contents of a file.
  • echo: Display a line of text.
    • echo "Hello, World!": Display “Hello, World!” in the terminal.
  • grep: Search for a pattern in files.
    • grep pattern file_name: Search for the specified pattern in a file.
  • chmod: Change file permissions.
    • chmod permissions file_name: Change the permissions of a file.
  • chown: Change file owner and group.
    • chown new_owner:new_group file_name: Change the owner and group of a file.
  • sudo: Execute a command as the superuser (root).
    • sudo command: Run a command with superuser privileges.
  • man: Display the manual for a command.
    • man command_name: Display the manual page for the specified command.

Infrastructure as Code (IaC):

  • Introduction to Infrastructure as Code (IaC) principles
  • Tools for IaC (e.g., Terraform)
  • Writing infrastructure code
  • Provisioning and managing infrastructure using IaC tools
    • Installation of Terraform
      terraform -v
      
    • Create a file on your Laptop using Terraform
    • Create a provider.tf file
    terraform {
    required_providers {
      local = {
        source = "hashicorp/local"
        version = "2.5.1"
      }
    }
    }
    
      provider "local" {
        # Configuration options
      }
    
  • Download Terraform Provider plugins
terraform init
  • Verify provider
terraform providers
  • Craete a file for local file
resource "local_file" "file01" {
  content  = "Welcome to Terraform Training"
  filename = "file.txt"
}
  • Check the plan
terraform plan
  • now execute the code
terraform apply

Use Terraform to create resources on AWS Cloud

  • Configure AWS credentials for Terraform
  • Create Provide file awsprovider.tf
terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "5.41.0"
    }
  }
}

provider "aws" {
  # Configuration options
}
  • Set AWS credentials with environment variables
 export AWS_ACCESS_KEY_ID="anaccesskey"
 export AWS_SECRET_ACCESS_KEY="asecretkey"
 export AWS_DEFAULT_REGION="us-west-2"
  • Execute terraform init to download aws provider plugins
terraform init 
  • Create a tf file for vm creation
resource "aws_instance" "web" {
 ami           = "ami-007020fd9c84e18c7" This image is in ap-south-1
 instance_type = "t2.micro"

 tags = {
   Name = "HelloWorld"
 }
}
  • Check plan and apply
terraform plan
terraform apply
  • Check the vm in AWS console
  • Now you can try to change image and other settings as well
  • Delete the vm now
terraform destroy

Maven a Build tool

  • Install maven on Ubuntu Os
apt install maven -y
  • Check the version of maven
mvn -v
  • Download Java code
git clone https://github.com/Ramkhushi/java-code1.git
cd java-code1/
  • Compile Code
mvn compile
  • Perfomr unit test
mvn test
  • Create Build Artifacts
mvn package
  • Run the below command if you get any error
apt install openjdk-11*
  • Check the war file if exists now
ls -l target

Containerization with Docker

  • Introduction to containerization and Docker
  • Docker architecture and components
  • Building and managing Docker images
  • Docker containers
    • Install Docker on Linux Vm
    • Create a container and run basics commands of Docker
    • Host a website on Docker and access that

LAB 01: Compile ,package and deploy java app.

  • Download Java code
git clone https://github.com/Ramkhushi/java-code1.git
cd java-code1/
  • Create a build
docker run -it --rm --name my-maven-project -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn clean install
  • Check newly created war file
ls -l target/*.war
  • Run the Application
docker run -dit --rm -p 8080:8080 -v "$(pwd)/target":/usr/local/tomcat/webapps tomcat:9.0
  • Check if the Application Opening
IP:8080/studentapp-2.5-SNAPSHOT/

Version Control Systems (VCS)

  • Introduction to Version Control Systems ( Git)
  • Basic Git commands and workflows
  • Branching and merging strategies
  • Collaborative development with Git

Continuous Integration (CI):

  • Introduction to Continuous Integration (CI) concepts
  • Setting up CI pipelines with popular tools using Jenkins
  • Integrating version control with CI
    • Create a Vm(ubuntu) and Install Jenkins
    • Update os
    sudo apt update -y
    
    • Install jenkins
    • Make sure to open port: 8080 to access Jenkins
    • Login to Jenkins Server
    • Get initial Password for Admin
    cat /var/lib/jenkins/secrets/initialAdminPassword
    
    • Create a first test job
    • Integrate Github and Jenkins
    • Deploy to Docker using Jenkins
    • Add jenkins user if you want to run command from Jenkins
    • Add below permission if you want to run docker command by any user
    chmod 777 /var/run/docker.sock
    systemctl restart docker
    

Projects

Project 1

  • Create a vm using Terraform on AWS cloud

Project 2

  • Craete a war file
  • Install Tomcat server
  • Deploy Application to tomcat server

Project 3

  • Run the same project on Docker
  • Deploy the same project using Jenkins