
Devops Session 2
Git and Github -
Git - It is software that can help to maintain repository
Github is repository
Steps to setup repository
1. install git in linux machine (yum install git)
2. Create account on github
3. generate key in linux machine (ssh-keygen)
4. copy the exact content from .ssh/id_rsa.pub in github ssh key setting (clickon dropdown on right side and click on setting and click on ssh) note- choose ssh rather than https
4. Click on new button after sign in and enter repo name and click on create repository
echo "# sample" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/aaftabhamdani/sample.git
git push -u origin main
addinf anothew file (sample2.txt)
git add sample2.txt
git commit -m "commit msg"
git push -u origin main
DevOps Session 3
Git architecture
https://intellipaat.com/blog/wp-content/uploads/2020/04/Git-4.jpg
Git commands
1. git push - push code from local repository to remote repository
2. git add - add code to staging area
3. git status- check the status of files and folders
4. git commit - add code local repository
5. git clone - download entire repository on local
6. git checkout test - to change banch to test
7. git pull - new changes will be pool from remote to local
8. git diff sample.txt - check file content difference from local repository to workspace
Devops Session 4
containerization- it is software base virtualization which does not require VM for every application
Docker- It is software layer on the top of base OS so that we can container on the top of docker
Setup to setup docker
1 sudo apt-get update
2. sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
3. sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
4. echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
5. sudo apt-get update
6. sudo chmod a+r /etc/apt/keyrings/docker.gpg
sudo apt-get update
7. sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
To run the container we require image files (dockerhub)
Commands to run docker
1. docker pull httpd - it will use to download the docker image (httpd)
2. docker image list - it will use to see the image which is downloaded
3. docker ps - it is used to see the running container
4. To run container we used - docker run -d -it httpd -p 80:80
-d -- run in background
-p -- port
-it -- interative
5. docker logs - to see the list of logs
6. docker rm xyz - it use to delete docker container (whicg is not running)
7. docker start xyz - start container
8. docker stop xyz - stop container
9. docker restart xyz - restart container
10. docker kill xyz - delete running container
DevOps Session 5
Run multiple sites in different containers
1. Download sample html code
2. copy it in aws instance
3. create resume folder and extract website data into it
4. Create Dockerfile and insert content
From httpd:latest
COPY . /usr/local/apache2/htdocs/
5. docker build -t resume_image .
6. docker run -p 80:80 -d -it resume_image
7. Create hotel folder and extract website into it
8. Create Dockerfile and insert content
From httpd:latest
COPY . /usr/local/apache2/htdocs/
9. docker build -t hotel_image .
10.docker run -p 8080:80 -d -it hotel_image
Commands in docker file
1. FROM - it will use to refer the another image from docker hub
2. COPY - copy the content from local machine to the container
3. ADD - add the content from local machine to the container but it will extract tar files and download content if url is present
4. WORKDIR - it will select the directory in which we want to work
5. CMD - when you want to run any command
6. RUN - it will help to build your container
7. ENTRYPOINT - it will execute command on startup
8. CMD - it will execute command on startup
DevOps Session 6
#!/bin/bash
echo "1. Run hotel website"
echo "2. Delete hotel website"
read var
case $var in
1)
docker build -t hotel_image $HOME
docker run --name hotel -p 80:80 -d -it hotel_image
break;;
2)
docker kill hotel
docker rm hotel
docker rmi hotel_image
break;;
*)
echo "enter correct choice"
esac
docker run -d -p 8000:8000 -p 9443:9443 --name portainer \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
portainer/portainer-ce:2.9.3
DevOps session 7
Cluster - It is not posssible to depend on single system so we setup multiple systems in such a way that if first is down then second will work without downtime
Docker swarm - it is cluster service odf docker
Steps to create cluster
1. docker swarm init --advertise-addr ip_add_1st
2. docker swarm join --token SWMTKN-1-6adyuvs4e2mxrlxs4p8so1amheyfj2uzgkp3ar69pg3k6scvfa-dgxoe1vhevkcau2ufxshyp17f 172.31.46.142:2377
3. docker node ls
4.docker service create -p 80:80 --name sample --replicas=6 httpd:latest
5. Launch portrainer to check on gui
6. docker service scale sample=10
DevOps Session 8
Docker compose
It is use to handle multiple containers in once
Steps to run docker compose
1. Install Docker file and docker-compose
2. Create 2 different folders and create 2 docker files
3. Create dcker compose file (docker-compose.yml)
version: '3.3'
services:
hotel:
restart: always
build:
dockerfile: Dockerfile
context: ./hotel
ports:
- '80:80'
resume:
restart: always
build:
dockerfile: Dockerfile
context: ./resume
ports:
- '8080:80'
version: '3.3'
services:
hotel:
restart: always
build:
dockerfile: Dockerfile
context: ./hotel
ports:
- '80:80'
resume:
restart: always
build:
dockerfile: Dockerfile
context: ./resume
ports:
- '8080:80'
portainer:
image: portainer/portainer-ce:latest
ports:
- '9443:9443'
- '8000:8000'
volumes:
- portainer_data:/data
- /var/run/docker.sock:/var/run/docker.sock
restart: unless-stopped
volumes:
portainer_data:
DevOps Session 9
Ansible- It is a tool of redhat which is use for deployment
Step to setup Ansible
1. Launch 3 Instance with 1 is Ansible server another is general server
2. Setup passwordless key from ansible server to another servers
generate ssh-keygen on ansible server and place the id_rsa.pub to another servers authorized_keys file
3. write sample.yml file
---
- hosts: all
become: yes
tasks:
- name: install yum package
yum:
name: http*
state: present
- name: start service
service:
name: httpd
state: started
- name: sample website
copy:
src: index.html
dest: /var/www/html/index.html
4. execute-
ansible-playbook sample.yaml
ansible all -m yum -a "name=unzip state=present" --become
DevOps session 10
https://docs.ansible.com/ansible/2.9/modules/list_of_all_modules.html
https://opensource.com/article/19/9/must-know-ansible-modules
https://github.com/aaftabhamdani/sample
Yaml - Its is human readable language and extension is .yaml or .yml
Ansible- Yaml is used to write playbook.
---
hosts: all
become: yes
tasks:
- name: package update
yum:
name:
- a
- b
- c
- d
state: latest
when: ansible_os_family == "RedHat"
- name: package update apt
apt:
name: '*'
state: latest
when: ansible_os_family == "Debian"
4. execute-
ansible-playbook sample.yaml
DevOps session 11
https://www.devopsschool.com/blog/example-code-of-ansible-variable-with-playbook/
Inventory files- It is the file which contain the list of machines in which IP address or hostname is .
Dynamic Inventory- It is custome inventory file
You can pass custom inventory file using below command
ansible-playbook -i mydb patch.yaml
Variable- It is used to change custom value for different deployment
vars:
VAR1: 8080
VAR2: 8081
example-
---
- hosts: all
become: yes
vars:
pkg_name: "httpd"
tasks:
- name: PAckage update
yum:
name: "{{ pkg_name }}"
state: latest
---------------------------------------------------------
---
- hosts: all
become: yes
vars:
pkg_name: "ssh"
tasks:
- name: PAckage update
yum:
name: "{{ pkg_name }}"
state: latest
- name: print variable
debug:
msg: "My variable is {{ pkg_name }}"
Devops Session 12
Loops- It is use to do the multiple task in one
---
- hosts: all
become: true
tasks:
- name: add users
user:
name: '{{ item }}'
state: present
loop:
- user11
- user12
- user13
- user14
- user15
- user16
- user17
- user18
Either we can use loop or with_items:
Roles- Roles provide a framework for fully independent, or interdependent collections of variables, tasks, files, templates, and modules.
DevOps Session 14
Terraform- It is a infrastrcuture as a code (IaaC). It support more than 100 clouds. We used HCL. Develop by hashicorp.
Steps to install terraform on windows
1. Download terraform on windows
2. Open powershell or command prompt
3. ./terraform version
DevOps Session 15
Terraform output block is used to show specific output after infrastructure deployment
output "my_block" {
description = "my description"
value = ["${aws_resource.resource_name.resource_value}"]
}
terraform namespace- It is use to deploy the tf file in different enviornment
DevOps Session 16
Terraform variables
Example-
provider "aws" {
region = "ap-south-1"
}
variable "ami_id" {
description = "Insert ami id"
default = "ami-0fdea1353c525c182"
}
resource "aws_instance" "test" {
ami = var.ami_id
instance_type = "t2.micro"
key_name = "test_key"
}
output "My_instance_ElasticIP" {
description = " Public IP of project VPC"
value = ["${aws_instance.test.public_ip}"]
}
create terraform.tfvars file
ami_id = "ami-0fdea1353c525c183"
note if your terraform var file is not terraform.tfvars the you should use below command
terraform apply -var-file="testing.tfvars"
provider "aws" {
region = "ap-south-1"
}
variable "ins_type" {
description = "Insert instance type"
default = "t3.micro"
}
variable "key_name" {
description = "Insert key name"
default = "test_t"
}
data "ami_id" "inst1" {
most_recent = true
owners = ["self"]
filter {
name = "name"
values = ["ami-0fdea1353c525c182"]
}
}
resource "aws_instance" "test" {
ami = "${ami_id.inst1.id}"
instance_type = var.ins_type
key_name = var.key_name
}
output "My_instance_ElasticIP" {
description = " Public IP of project VPC"
value = ["${aws_instance.test.public_ip}"]
}
This course is for anybody who wants to get started with DevOps:
As there are many tools & technologies in DevOps, it has become difficult for people to choose the right technologies.
This course starts from very basics of command line, hands on demonstrations of many tools & technologies.
Also most importantly it will show you how various technologies in DevOps work together by setting up your own projects.
Step 1
Version control system = Git & GitHub
Build Tools | Build & Test Java Code = Maven
Continuous Integration Intro
Jenkins
Jenkins as a Build Server
Jenkins Jobs | Build , Test, Deploy, Notify
Jenkins Master/Slave, Nexus, Sonarqube
Jenkins CI Pipeline
Jenkins Administration
Project
Continuous Integration Using Jenkins, Nexus, Sonarqube & Slack
Step 2
Ansible Intro
Ad Hoc commands
Modules
YAML into
Playbooks
vars, conditions, loops,
handlers, templates etc etc etc
Variables deep dive
Roles
Ansible for AWS
Project
Continuous Delivery and Configuration Management [Jenkins plus Ansible]
Step 3
AWS Part 2
VPC in depth
Log management and custom metrics
Project
Vprofile on Beanstalk & RDS
Code Commit, Code Build & Code Pipeline
CI & CD on AWS Cloud for Vprofile Project
Beanstalk, RDS, CodePipeline etc
Step 4
Docker Intro
Understanding and Implementing Containers
Volumes, Network, logs etc
Building Images for Vprofile project
Docker compose to run vprofile multi containers
Kubernetes Intro
Kubernetes setup for production Env
Kubernetes objects
Pods, Services, Controllers, Deployment
Replication, Autoscaling, Resource quotas, secret, configmap, namespace.