Lpi Devops
Lpi Devops
Brahim HAMDI
[email protected]
Juillet 2023
Plan
Module 1 : Modern Software Development
Module 2 : Components, platforms and cloud deployment
Module 3 : Source code management
Module 4 : System image creation and VM Deployment
Module 5 : Container usage
Module 6 : Container Infrastructure
Module 7 : Container Deployment and Orchestration
Module 8 : Ansible and configuration management tools
Module 9 : CI / CD whith Jenkins
Module 10 : IT monitoring
Module 11 : Log management and analysis
Brahim HAMDI 2
LPI DevOps Tools Engineers
Module 1
Modern Software
Development
Brahim HAMDI 3
Plan
●
Agile
●
Service based applications
●
RESTful APIs
●
Application security risks
Brahim HAMDI 4
Agile
What is Agile ?
●
Software development methodology.
●
A set of values and principles
●
Adaptive planning
●
Evolutionary and iterative development
●
Continuous improvement
●
Rapid and flexible response to change
●
Scrum is the most widely used Agile method.
●
Others agile methods and practices :
– Kanban
– Extreme Programming (XP)
– Feature-Driven Development (FDD)
– Test-Driven Develoment (TDD)
– DevOps
Brahim HAMDI 5
Agile
The Manifesto for Agile Software
Development
●
Individuals and Interactions more than processes and tools.
●
Working Software more than comprehensive documentation.
●
Customer Collaboration more than contract negotiation.
●
Responding to Change more than following a plan.
Brahim HAMDI 6
Agile
Agile development
Brahim HAMDI 7
Agile
Agile vs DevOps
Agile DevOps
Brahim HAMDI 8
Agile
TDD Cycle
Brahim HAMDI 9
Service based applications
Application architecture
●
Why does application architecture matter?
– Build a product can scale.
– To distribute.
– Helps with time to market
●
Application architectures:
– Monolithic Architecture
– SOA Architecture
– Microservices Architecture
Brahim HAMDI 10
Service based applications
Monolithic vs. SOA vs. Microservices
●
Monolithic:
– Single Unit
– Tightly coupled
●
Service Oriented Architecture:
– Coarse-grained
– Loosely coupled
●
Microservices:
– Fine-grained
– Loosely coupled
Brahim HAMDI 11
Service based applications
What is SOA ?
●
Service Oriented Architecture
●
An approach to distributed systems architecture:
– Loosely coupled services
– Standard interface and protocol
●
Communicates over an enterprise service bus (ESB)
Brahim HAMDI 12
Service based applications
SOA architecture
Brahim HAMDI 13
Service based applications
SOA properties
●
A service has four properties:
– It logically represents a business activity with a specified outcome
– It is autonomous
– It is a black box for its consumers
– It may consist of other underlying services
Brahim HAMDI 14
Service based applications
What are Microservices?
●
A microservice architecture breaks an application up into a collection
of small, loosely-coupled services
●
The opposite of monolithic architecture
●
Microservices are small
●
Microservices are loosely coupled
●
Services should be fine-grained
●
Protocols should be lightweight
Brahim HAMDI 15
Service based applications
Microservices architecture
Brahim HAMDI 16
Service based applications
What do microservices look like?
●
There are many different ways to structure and organize a
microservice architecture
●
Services are independent:
– Codebase
– Running process
– Built independently
– Deployed independently
– Scaled independently
Brahim HAMDI 17
Service based applications
Why use Microservices?
●
Modularity
●
Flexibility : take advatages of différent technologies
●
Scalability
●
Maintainability
●
Suited Cloud-native deployment
●
Small autonomous teams
●
Enable continuous integration and delivery
Brahim HAMDI 18
Service based applications
Choosing application architecture
●
Each architecture has had its utility during its time and might still serve a need.
●
Monolithic architecture :
– new product with limited resources and programming talent.
●
Microservices architecture :
– Run multiple copies of the application on multiple machines in order to
satisfy scalability and availability requirements
– Take advantage of emerging technologies (frameworks, programming
languages, etc).
– Support a variety of different clients including desktop browsers, mobile
browsers and native mobile applications.
– Integrate with other applications via either web services or a message
brokers.
– Exchanging messages with other systems; and returning a
HTML/JSON/XML response.
Brahim HAMDI 19
RESTful APIs
What is REST ?
●
REpresentational State Transfer
●
Separation of client and server
●
Stateless
●
Communication between clients and servers
Brahim HAMDI 20
RESTful APIs
Requests and Responses
●
REST requires that a client make a request to the server
●
Send a Request:
– HTTP verb
– Header
– Resource path
– Message Body (optional)
●
Get a Response:
– Content Type
– Response Code
Brahim HAMDI 21
RESTful APIs
HTTP verbs
●
There are 4 basic HTTP verbs:
– GET - reads data and doesn’t change application state
– POST - creates resources
– PUT - updates resources
– DELETE - removes resources
Brahim HAMDI 22
RESTful APIs
Headers
●
The client sends the type of content that it is able to receive:
– Accept
– MIME:
●
application/json
●
application/xml
Brahim HAMDI 23
RESTful APIs
Paths
●
Requests must contain a path to a resource
●
Path should be the plural:
– /customers
●
Append an id to the path when accessing a single resource:
– /customers/:id
– /customers/:id/orders/:id
Brahim HAMDI 24
RESTful APIs
Status codes
●
200: OK: This is a successful request.
●
201: Created: A resource has been created.
●
202: Accepted: The request has been accepted but it hasn't been
completed.
●
204: No Content: Successful HTTP requests, where nothing is being
returned in the response body.
●
400: Bad Request: The request wasn't understood by the server, due to
malformed syntax.
●
401: Unauthorized: Either the authentication header is missing, or it
contains invalid credentials.
●
403: Forbidden: The client does not have permission to access this
resource.
Brahim HAMDI 25
RESTful APIs
Status codes (Cont.)
●
404: Not Found: A resource matching the request doesn't exist.
●
405: Method Not Allowed: The requested operation is not supported on
the specified Artifact type by the Services API.
●
500: Internal Server Error: An unhandled exception occurred on the
server.
●
502 : Bad Gateway : The server was acting as a gateway or proxy and
received an invalid response from the upstream server
Brahim HAMDI 26
RESTful APIs
Verbs and status codes
●
GET: return 200 (OK)
●
POST: return 201 (CREATED)
●
PUT: return 200 (OK)
●
DELETE: return 204 (NO CONTENT)
Brahim HAMDI 27
RESTful APIs
REST example
Request: Response:
GET /customers/123 Status Code: 200 (OK)
Content-type: application/json
Accept: application/json
{
"customer": {
"id": 123,
"first_name": "Brahim",
"last_name": "Hamdi",
"email": "[email protected]"
}
}
Brahim HAMDI 28
Application security risks
Most security risks
●
SQL injection / LDAP injection
●
Broken authentication
●
Broken access control
●
Cross-site scripting (XSS)
●
Cross-site request forgery (CSRF)
●
Unvalidated redirects and forwards
●
Etc ...
Brahim HAMDI 29
Application security risks
What is Cross Site Scripting?
●
Cross-Site Scripting (XSS) is a type of injection attack
●
Malicious scripts are injected into trusted websites
Brahim HAMDI 30
Application security risks
How to Mitigate XSS Vulnerabilities
●
Validate your data:
– Is the data an integer (0 to 9 digits only)?
– Is the data a float with a decimal point allowed (0 to 9 and .
character)?
– Is the data numbers and dashes, e.g., a credit card date field?
– Is the data a string with numbers, letters, spaces, and punctuation
only?
●
Escape and sanitize your data
Brahim HAMDI 31
Application security risks
What is CSRF ?
Brahim HAMDI 32
Application security risks
What is a Anti-CSRF Token?
Brahim HAMDI 33
Application security risks
What is CORS?
Brahim HAMDI 34
Application security risks
Pre-flight request
●
a small request that is sent by the browser to server hosting the cross-
origin resource before the actual request.
– In order to check that the server will permit the actual request.
– The browser sends headers that indicate the HTTP method and headers that
will be used in the actual request.
●
Preflight example :
– Request :
OPTIONS /
Host: service.example.com
Origin: http://www.example.com
Access-Control-Request-Method: PUT
– Response (If service.example.com accept the action) :
Access-Control-Allow-Origin: http://www.example.com
Access-Control-Allow-Methods: PUT, DELETE
Brahim HAMDI 35
Application security risks
CORS Headers
●
headers that relate to CORS:
– Request Headers
●
Origin
●
Access-Control-Request-Method
●
Access-Control-Request-Headers
– Response headers
●
Access-Control-Allow-Origin
●
Access-Control-Allow-Credentials
●
Access-Control-Expose-Headers
●
Access-Control-Max-Age
●
Access-Control-Allow-Methods
●
Access-Control-Allow-Headers
Brahim HAMDI 36
LPI DevOps Tools Engineers
Module 2
Components, platforms and
cloud deployment
Brahim HAMDI 37
Plan
●
Data platforms and concepts
●
PaaS platforms
●
Deployment strategies
●
OpenStack
●
Cloud-init
●
Content Delivery Networks
Brahim HAMDI 38
Data platforms and concepts
Relational database
●
Based on the relational model of data.
●
Relational database systems use SQL.
●
Relational model organizes data into one or more tables.
●
Each row in a table has its own unique key (primary key).
●
MySQL (MariaDB), Oracle, Postgres, etc ...
Brahim HAMDI 39
Data platforms and concepts
NoSQL database
●
Mechanism for storage and retrieval of data other than the tabular
relations used in relational databases.
●
Increasingly used in big data and real-time web applications
●
Properties :
– Simplicity of design
– Simpler scaling to clusters of machines (problem for relational
databases)
– Finer control over availability.
– Some operations faster (than relational DB)
Brahim HAMDI 40
Data platforms and concepts
Types of NoSQL database
●
Key-value :
Brahim HAMDI 43
Data platforms and concepts
CAP theorem
Brahim HAMDI 44
Data platforms and concepts
ACID properties
●
ACID : Atomicity, Consistency, Isolation and Durability.
●
Set of properties of database transactions intended to guarantee
validity even in the event of errors, power failures, etc ...
– Atomicity : each transaction is treated as a single "unit", which
either succeeds completely, or fails completely.
– Consistency (integrity): Ensures that a transaction can only bring
the database from one valid state to another, maintaining
database invariants ( only starts what can be finished).
– Isolation: two or more transactions made at the same time must be
independent and do not affect each other.
– Durability: If a transaction is successful, it will persist in the system
(recorded in non-volatile memory)
Brahim HAMDI 45
PaaS platforms
Cloud services
Brahim HAMDI 46
PaaS platforms
cloud PaaS software
●
AWS Lambda
●
Plesk
●
Google Cloud Functions
●
Azure Web Apps
●
Oracle Cloud PaaS
●
OpenShift
●
Cloud Foundry
●
Etc ...
Brahim HAMDI 47
PaaS platforms
CloudFoundry
●
Originally developed by VMware
●
Written in Ruby, Go and Java
●
Release in 2011
●
Build, test, deploy apps easily
●
Open source, commercial product or through a hosting provider
●
The CLI is supported on Linux, Mac and Windows
●
Support any language or framework by using buildpacks
●
Supports Docker images
Brahim HAMDI 48
PaaS platforms
OpenShift
●
Open source cloud PaaS developed by Red Hat.
●
Used to create, test, and run applications, and finally deploy them on
cloud.
●
Capable of managing applications written in different langages
(Node.js, Ruby, Python, Perl, and Java).
●
It is extensible : helps the users support the application written in
other languages).
●
It comes with various concepts of virtualization as its abstraction layer.
– uses an hypervisor to abstract the layer from the underlying
hardware.
Brahim HAMDI 49
Openstack
Presentation
●
Open-source software platform for cloud computing, mostly deployed
as IaaS.
●
Virtual servers and other resources are made available to customers
●
Interrelated components that control diverse, multi-vendor hardware
pools of processing, storage, and networking resources throughout a
data center.
●
Managed through a web-based dashboard, command-line tools, or
RESTful API.
Brahim HAMDI 50
Openstack
Components
Brahim HAMDI 51
Cloud-init
What is cloud-init?
●
Multi-distribution package that handles early initialization of a cloud
instance.
●
Use Cases :
– Setting an instance hostname
– Generating instance SSH private keys
– Adding SSH keys to a user’s .ssh/authorized_keys
– Setting up mount points
– Configuring network devices
– Installing packages
Brahim HAMDI 52
Cloud-init
Formats
●
User-data script :
– Execute a script shell
– Begins with : #!
●
Include File :
– An include file
– Begins with : #include
●
Cloud Config Data :
– The simplest way to accomplish some things via user-data
– Begins with : #cloud-config
Brahim HAMDI 53
Cloud-init
Examples
●
Example 1 :
#cloud-config
package_upgrade: true
packages:
- git
- screen
- vim -enhanced
●
Example 2 :
# !/bin/sh
echo «Time is now $(date -R) ! » | tee /root/output.txt
Brahim HAMDI 54
Deployment strategies
Why deployment strategies ?
●
The biggest change to software development is the frequency of
deployments.
●
The business benefits of shorter deployment cycles are clear:
– Time-to-market is reduced
– Customers get product value in less time
– Customer feedback also flows back into the product team faster,
which means the team can iterate on features and fix problems
faster
– Overall developer morale goes up
Brahim HAMDI 55
Deployment strategies
Popular Deployment Strategies
●
Application and infrastructure teams should devise and adopt a
deployment strategy suitable for their use case.
●
The most poplular deployment strategies :
– "Big Bang" Deployment : the full solution is developed and tested
and then replaces the current system at once.
– Rolling Deployment : An application’s new version gradually
replaces the old one.
– Blue-Green Deployment : Two identical production environments
work in parallel.
– A/B Testing : comparing two version and measuring the resultant
responses.
– Canary Deployment : deploying an application in small, incremental
steps, and only to a small group of people.
Brahim HAMDI 56
Deployment strategies
Blue-Green deployment
Brahim HAMDI 57
Deployment strategies
Blue-Green deployment
Brahim HAMDI 58
Deployment strategies
Blue-Green deployment
Brahim HAMDI 59
Deployment strategies
Blue-Green deployment
Brahim HAMDI 60
Deployment strategies
Blue-Green deployment
Brahim HAMDI 61
Deployment strategies
Canary deployment
Brahim HAMDI 62
Deployment strategies
Canary deployment
Brahim HAMDI 63
Deployment strategies
Canary deployment
Brahim HAMDI 64
Content Delivery Network
what is CDN
●
Geographically distributed network of proxy servers and their data
centers that work together to provide fast delivery of Internet content
●
Minimizes the distance between the visitors and your website’s server
●
Serves a large portion of the Internet content
●
Not a replacement for proper web hosting, but helps cache the content
Brahim HAMDI 65
Content Delivery Network
Benefits of Using a CDN
●
Uptime reliability
●
Improving website load times
●
Reducing bandwidth costs
●
Increasing content availability and redundancy
●
Improving website security
Brahim HAMDI 66
Content Delivery Network
CDN architecture
Brahim HAMDI 67
LPI DevOps Tools Engineers
Module 3
Source code management
Brahim HAMDI 68
Plan
●
SCM solutions
●
Git and the repository
●
Git commands
●
Git remote repository commands
●
Git merge conflicts
Brahim HAMDI 69
SCM solutions
Source Code Management
●
SCM – Source Code Management
●
SCM involves tracking the modifications to code.
●
Tracking modifications assists development and colloaboration by :
– Providing a running history of development
– helping to resolve conflicts when merging contributions from
multiple sources.
●
Software tools SCM are sometimes referred to as :
– "Source Code Management Systems" (SCMS)
– "Version Control Systems" (VCS)
– "Revision Control Systems" (RCS)
– or simply "code repositories"
Brahim HAMDI 70
SCM solutions
SCM types
●
Two types of version control: centralized and distributed.
●
Centralized version control :
– Have a single “central” copy of your project on a server.
– Commit changes to this central copy
– Never have a full copy of project locally
– Solutions : CVS, SVN (Subversion)
●
Distributed version control
– Version control is mirrored on every developer's computer.
– All ows branching and merging to be managed automatically.
– Ability to work offline (Allows users to work productively when not
connected to a network)
– Solutions : Git, Mercurial.
Brahim HAMDI 71
Git and the repository
What is Git ?
●
Git is a distributed SCM system.
●
Initially designed and developed by Linus Torvalds for Linux kernel
development.
●
A free software distributed under GNU General Public License version 2.
●
Advantages :
– Free and open source
– Fast and small
– Implicit backup
– Secure : uses SHA1 to name and identify objects.
– Easier branching : copy all the codes to new branch.
Brahim HAMDI 72
Git and the repository
Git repository
●
Git Repository : Typically is on developer’s computer.
– Developer make changes in his private workplace
– After commit, these changes become a part of a Git repository.
– Users can perform many operations with this repository
●
add file
●
remove file
●
rename file
●
move file
●
commit changes
●
and many more...
Brahim HAMDI 73
Git and the repository
Blobs and Trees
●
Blob - Binary Large Object
– Each version of a file is represented by blob.
– It holds the file data but doesn’t contain any metadata about the file.
– It is a binary file, and in Git database, it is named as SHA1 hash of that
file
●
Trees : an object, which represents a directory.
– It holds blobs as well as other sub-directories.
– It is a binary file that stores references to blobs and trees which are
also named as SHA1 hash of the tree object.
Brahim HAMDI 74
Git and the repository
Commits
●
Commit holds the current state of the repository.
●
Also named by SHA1 hash.
●
Every commit object has a pointer to the parent commit object.
●
From a given commit, you can traverse back by looking at the parent
pointer to view the history of the commit.
●
If a commit has multiple parent commits, then that particular commit has
been created by merging two branches.
Brahim HAMDI 75
Git and the repository
Branches
●
Branches are used to create another line of development.
●
By default, Git has a master branch.
●
Usually, a branch is created to work on a new feature.
●
Once the feature is completed, it is merged back with the master branch
and we delete the branch.
●
Every branch is referenced by HEAD, which points to the latest commit in
the branch.
●
Whenever you make a commit, HEAD is updated with the latest commit.
Brahim HAMDI 76
Git and the repository
Tags
●
Tag assigns a meaningful name with a specific version in the repository.
●
An immutable reference to a specific commit on a branch.
●
Once a tag is created for a particular commit, even if you create a new
commit, it will not be updated.
●
Usually, developers create tags for product releases.
Brahim HAMDI 77
Git and the repository
HEAD
●
HEAD is a pointer, which always points to the latest commit in the branch.
●
Whenever you make a commit, HEAD is updated with the latest commit.
●
The heads of the branches are stored in .git/refs/heads/ directory.
Brahim HAMDI 78
Git and the repository
Git platforms
●
GitHub, GitLab and Bitbucket : Git repositories management platforms.
●
Allows developers to change, adapt and improve software from its
repositories
●
Repositories can have multiple collaborators and can be either public or
private.
●
Each public or private repository contains all of a project's files, as well as
each file's revision history.
Brahim HAMDI 79
Git commands
Git commands
Brahim HAMDI 80
Git commands
git init
●
Create an empty Git repository or reinitialize an existing one.
●
a « .git » directory with subdirectories for objects, refs/heads,
refs/tags, and template files.
●
An initial HEAD file that references the HEAD of the master branch is
also created.
●
Running git init in an existing repository will not overwrite things that
are already there.
Brahim HAMDI 81
Git commands
git clone
●
Clones a repository into a newly created directory.
●
Creates remote-tracking branches for each branch in the cloned
repository.
●
Creates and checks out an initial branch that is forked from the cloned
repository’s currently active branch.
●
After the clone :
– a plain git fetch without arguments will update all the remote-
tracking branches,
– a git pull without arguments will in addition merge the remote
master branch into the current master branch
Brahim HAMDI 82
Git and the repository
git status
Brahim HAMDI 83
Git commands
git add
●
Add file contents to the index.
●
updates the index using the current content found in the workspace, to
prepare the content staged for the next commit.
●
This command can be performed multiple times before a commit.
●
The git add command will not add ignored files by default.
●
Ignored files specified in a «.gitignore» file or on the command line.
●
The «git status» command can be used to obtain a summary of which files
have changes that are staged for the next commit.
Brahim HAMDI 84
Git commands
git commit
●
Record changes to the repository.
●
Stores the current contents of the index in a new commit along with a log
message from the user describing the changes.
●
Use « -m <msg> » or « –message=<msg> » option to describe the
change.
●
If you make a commit and then find a mistake immediately after that, you
can recover from it with « git reset ».
Brahim HAMDI 85
Git commands
git checkout
●
Switch branches or restore working tree files.
●
Syntax :
git checkout <branch>
●
To prepare for working on <branch>, switch to it by updating the index and
the files in the working tree, and by pointing HEAD at the branch.
●
-b option creates new branch.
Brahim HAMDI 86
Git commands
git diff
●
Show changes between :
– The working tree and the index or a tree,
– The index and a tree
– Two trees
– Two files on disk.
●
Examples :
– git diff : Changes in the working tree not yet staged for the next
commit.
– git diff HEAD : Changes in the working tree since your last commit
– git diff HEAD^ HEAD : Compare the version before the last commit
and the last commit.
– git diff HEAD^^^ : show the changes contained in the last three
commits
Brahim HAMDI 87
Git commands
git log
●
Shows the commit logs.
●
Examples :
– git log –no-merges : Show the whole commit history, but skip any
merges
– git log -3 : Limits the number of commits to show to 3.
– git log --since="2 weeks ago" – gitk : Show changes during last
two weeks to the file gitk. -- is to avoid confusion with the branch
named gitk
– git log master --not –remotes=*/master : Shows all commits that
are in local master but not in any remote repository master
branches.
Brahim HAMDI 88
Git commands
git rm
●
Remove files from the working tree and from the index.
●
git rm will not remove a file from just the working directory.
●
use /bin/rm to delete files from working directory.
●
Examples :
– git rm Documentation/\*.txt : Removes all *.txt files from the index
that are under the Documentation directory and any of its
subdirectories.
Brahim HAMDI 89
Git commands
git mv
●
Move or rename a file, directory or symlink.
●
In rename form, it renames <source>, which must exist and be either
a file, symlink or directory, to <destination>.
●
In move form, the last argument has to be an existing directory; the
given sources will be moved into this directory.
●
The index is updated after successful completion, but the change
must still be committed.
Brahim HAMDI 90
Git commands
git branch
●
List, create, or delete branches
●
If --list is given, or if there are no non-option arguments, existing
branches are listed
●
git branch <branchname> : create new branch
●
git branch -m : <oldbranch> will be renamed to <newbranch>
●
git branch -d <branchname> : delete branch
Brahim HAMDI 91
Git remote repository commands
git push
●
Updates remote refs using local refs, while sending objects necessary to
complete the given refs.
●
Syntax :
git push [options] <repository>
– The "remote" repository that is destination of a push operation. It can be
either a URL or the name of a remote
– If <repository> argument not specified, « branch.*.remote » configuration
for the current branch is consulted to determine where to push.
– If the configuration is missing, it defaults to « origin ».
Brahim HAMDI 92
Git remote repository commands
git fetch, git merge
●
« git fetch » Fetch branches and/or tags from one or more other repositories,
along with the objects necessary to complete their histories.
●
It can fetch from either a single named repository or URL, or from several
repositories at once if <group> is given and there is a remotes.
●
« git merge » join two or more development histories together.
●
Incorporates changes from the named commits into the current branch.
●
Used by « git pull » to incorporate changes from another repository
●
can be used by hand to merge changes from one branch into another.
Brahim HAMDI 93
Git remote repository commands
git pull
●
Incorporates changes from a remote repository into the current branch.
●
It is shorthand for « git fetch » followed by « git merge
FETCH_HEAD ».
●
<repository> should be the name of a remote repository.
●
git pull = git fetch + git merge
git pull
Brahim HAMDI 94
Git merge conflict
Understanding merge conflicts
●
Conflicts generally arise when :
– Two people have changed the same lines in a file
– If one developer deleted a file while another developer was
modifying it.
●
Git cannot automatically determine what is correct.
●
Conflicts only affect the developer conducting the merge, the rest of
the team is unaware of the conflict.
●
Git will mark the file as being conflicted and halt the merging process.
●
It is then the developers' responsibility to resolve the conflict.
Brahim HAMDI 95
Git merge conflict
Types of merge conflicts
●
A merge can enter a conflicted state at two separate points.
– Git fails to start the merge :
●
A merge will fail to start when Git sees there are changes in
either the working directory or staging area of the current
project.
●
Error: Entry '<fileName>' not uptodate. Cannot merge.
(Changes in working directory)
– Git fails during the merge :
●
A failure DURING a merge indicates a conflict between the
current local branch and the branch being merged
●
This indicates a conflict with another developers code.
●
Error: Entry '<fileName>' would be overwritten by merge. Cann
ot merge. (Changes in staging area)
Brahim HAMDI 96
LPI DevOps Tools Engineers
Module 4
System image creation and
VM Deployment
Brahim HAMDI 97
Plan
●
Vagrant
●
Vagrantfile
●
Vagrantbox
●
Packer
Brahim HAMDI 98
Vagrant
What’s vagrant
●
Create and configure lightweight, reproducible,
and portable development environments.
●
A higher-level wrapper around virtualization
software such as VirtualBox, VMware, KVM.
●
Wrapper around configuration management software such as Ansible,
Chef, Salt, and Puppet.
●
Public clouds e.g. AWS, DigitalOcean can be providers too.
Brahim HAMDI 99
Vagrant
What’s vagrant
Module 5
Container usage
●
Each VM requires an operating system (OS)
– Each OS requires a licence
– Each OS has its own compute and storage overhead
– Needs maintenance, updates
●
You can create user-defined overlay networks using the command :
– docker network create -d overlay my-overlay
●
WORKDIR, EXPOSE, ENTRYPOINT result in tags. Others in Layers.
Brahim HAMDI 138
Create Dockerfiles and build images
FROM, RUN instructions
●
A Dockerfile must start with a `FROM` instruction
●
FROM instruction specifies the Base Image from which you are
building.
●
The RUN instruction will execute any commands in a new layer on top
of the current image and commit the results.
●
RUN has 2 forms:
– RUN <command> (shell form, the command is run in a shell, which
by default is /bin/sh -c on Linux or cmd /S /C on Windows)
– RUN ["executable", "param1", "param2"] (exec form)
Module 6
Container Infrastructure
Module 7
Container Deployment and
Orchestration
Installation & Cluster Installation very simple, but cluster not Insttallation complicated ; but once setup,
configuration very strong the cluster is very strong
Scalability Highly scalable & scales faster than Highly scalable & scales faste
kubernetes
Load Balancing Does auto load balancing of trafic Manual intervention needed for load
between containers in the cluster balancing trafic between different
containers in different Pods
Rolling Updates & Can deploy Rolling updates, but not Can deploy Rolling updates, & does
Rollbacks automatic Rollbacks automatic Rollbacks
Data Volumes Can share storage volumes with any Can share storage volumes only with other
other container containers in same Pod
Logging & Monitoring 3rd party tools like ELK should be In-built tools for logging & monitoring
used
Brahim HAMDI 170
Kubernetes
Architecture
●
Might contain:
– Kube-proxy
– a network management utility
●
Might contain:
– a network management utility
Module 8
Ansible and configuration
management tools
●
Ansible uses the first ansible.cfg file it finds, ignoring all others.
tasks:
- name: install Apache
yum: name=httpd state=installed
when: ansible_os_family == "RedHat"
Brahim HAMDI 196
Playbook
Handlers
●
Only run if task has a “changed” status
●
Example :
- name: This is a Play
hosts: web-servers
tasks:
- yum: name={{ item }} state=installed
with_items:
- httpd
- memcached
notify: Restart Apache
- template: src=templates/web.conf.j2 dest=/etc/httpd/conf.d/web.conf
notify: Restart Apache
handlers:
- name: Restart Apache
service: name=httpd state=restarted
Brahim HAMDI 197
Playbook
Tags
●
Example of tag usage (example.yml) :
tasks:
- yum: name={{ item }} state=installed
with_items:
- httpd
- memcached
tags:
- packages
- template: src=templates/src.j2 dest=/etc/foo.conf
tags:
- configuration
●
Running with tags :
$ ansible-playbook example.yml --tags “configuration”
$ ansible-playbook example.yml --skip-tags "notification"
Brahim HAMDI 198
Variables
Setting Variables
●
Variables in Ansible help you to contextualise and abstract roles.
●
Variables can be defined in several areas
– Inventory
– Playbook
– Files and Roles
– Command Line
– Facts
- debug:
var: find_output
Brahim HAMDI 202
Variables
Reference a field
●
supports dictionaries which map keys to values.
●
Example :
foo:
field1: one
field2: two
●
can then reference a specific field in the dictionary using :
– bracket notation : foo['field1']
or
– dot notation: foo.field1
Module 9
CI/CD with Jenkins
git(gitUrl) authorization {
// limit builds to just Jack and Jill
}
permission('hudson.model.Item.Build', 'jill')
triggers {
permission('hudson.model.Item.Build', 'jack')
cron('15 13 * * *') }
} steps {
steps { maven('-B release:prepare release:perform')
maven('sonar:sonar') shell('cleanup.sh')
}
} Brahim HAMDI 236
}
}
Jenkinsfile
Declarative pipeline
●
Pipelines can be defined with a simpler syntax.
●
Declarative “section” blocks for common configuration areas, like
– Stages
– Tools
– post-build actions
– Notifications
– Environment
– build agent or Docker image
●
All wrapped up in a pipeline { ... } step, with syntactic and semantic
validation available.
●
It’s configured and run from a Jenkinsfile.
Brahim HAMDI 237
LPI DevOps Tools Engineers
Module 10
IT monitoring
●
Gathering metrics into database
– Scheduled pull |harvest| scrape actions – HTTP/TCP requests
– Accessing Exporters and built in (scrape) endpoints.
●
Treating time-series data as a data source for generating alerts.
rule_files:
# - "first.rules"
# - "second.rules"
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
Brahim HAMDI 247
Exposing metrics for Prometheus
Scrape Metrics for Prometheus
●
Configure the endpoint on the Prometheus server in the prometheus’
configuration file.
●
Have the application or environment listen for HTTP requests at a specific
endpoint (for example: host:port/metrics).
●
Return Metrics in the proper format to GET requests to this endpoint.
●
Use a Client Library to easily compose the proper metrics response
messages.
Module 11
Log management and
analysis
}
– Results :
{
"message" => "Starting transaction for session -464410bf-37bf-475a-afc0-498e0199f008",
"timestamp" => "2016-07-11T23:56:42.000+00:00",
"log-level" => "INFO",
"class" => "MySecretApp.com.Transaction.Manager"
}