0% found this document useful (0 votes)
430 views133 pages

IBMCE - DevOpsFundamentals - Jul10

Uploaded by

Vaibhav Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
430 views133 pages

IBMCE - DevOpsFundamentals - Jul10

Uploaded by

Vaibhav Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 133

DevOps Training Module

or

Training Module

Preface
December 2019

© 2019 IBM Corporation 1


DevOps Training Module

Table of Contents
Chapter 1: DevOps Fundamentals ...................................................... 6
Introduction to DevOps .............................................................................. 6
What is DevOps? .................................................................................... 6
A definition of DevOps ........................................................................... 7
Benefits of DevOps approach ................................................................ 7
Drivers of DevOps .................................................................................. 8
Understanding the Business Need for DevOps ..................................... 8
How is DevOps different from Traditional IT? ....................................... 9
Issues in traditional application ............................................................ 9
Recognizing the Business Value of DevOps ........................................ 10
Return on Investment .......................................................................... 11
When to adopt / not adopt DevOps? ................................................... 11
How is DevOps different from Agile? DevOps vs Agile........................ 12
DevOps Principles ................................................................................ 13
DevOps Lifecycle ................................................................................. 15
Test your knowledge ................................................................................ 17
Introduction to Continuous Integration / Continuous Delivery /
Continuous Deployment........................................................................... 18
Continuous Integration ........................................................................ 18
Continuous Delivery ............................................................................. 19
Continuous Deployment ...................................................................... 19
Introduction to DevOps Tools .................................................................. 20
Version Control – Git ............................................................................ 20

© 2019 IBM Corporation 2


DevOps Training Module

Exercise 1: Git Server installation ............................................................ 21


Exercise 2: Git Client Installation ............................................................ 24
Exercise 3: Git Exercise ............................................................................ 25
Test your knowledge ................................................................................ 28
Build Automation – Maven ....................................................................... 29
Exercise 4: ECLIPSE IDE Installation ...................................................... 29
Exercise 5: Maven Installation ................................................................. 34
Test your knowledge ................................................................................ 42
Configuration Management – Puppet ...................................................... 43
Exercise 6: Installing Puppet on Ubuntu ................................................. 43
Exercise 7: Puppet Exercise ..................................................................... 47
Test your knowledge ................................................................................ 49
Containerization with Docker ................................................................... 50
Exercise 8: Installing Docker on Ubuntu ................................................. 51
Exercise 9: Create Docker images ........................................................... 53
Test your knowledge ................................................................................ 55
Continuous Deployment – Jenkins .......................................................... 57
Exercise 10: Installation of Jenkins on Ubuntu ....................................... 57
Test your knowledge ................................................................................ 63
Continuous Integration – Jenkins ............................................................ 64
Continuous Testing – Junit ...................................................................... 65
Exercise 11: JUnit Installation ................................................................. 65
Test your knowledge ................................................................................ 71
Continuous Monitoring - Nagios............................................................... 72
Exercise 12: Nagios Installation .............................................................. 73

© 2019 IBM Corporation 3


DevOps Training Module

Test your knowledge ................................................................................ 81


Continuous Monitoring – Graphite & Grafana.......................................... 82
Exercise 13: Graphite & Grafana Installation .......................................... 82
Test your knowledge ................................................................................ 92
Chapter 2: DevOps Usecase ..............................................................93
DevOps Use case & Setup ........................................................................ 93
Introduction of a Usecase for CI/CD Pipeline ..................................... 93
Exercise 1 - Set Up a CI/CD Pipeline from Scratch.................................. 94
Solving Problems with DevOps ............................................................. 100
DevOps in Mobile Applications ......................................................... 100
DevOps in eCommerce ..................................................................... 102
DevOps in Internet of Things ............................................................ 103
DevOps in Data Science & Data Engineering .................................... 104
Test Your Knowledge ............................................................................ 106
Chapter 3: Advanced DevOps .........................................................107
Introduction to advanced DevOps Concepts ........................................ 107
Automatic Rollback........................................................................... 107
Automatic Provisioning ..................................................................... 108
Exercise 1 - Automatic Rollback ........................................................... 109
Infrastructure as Code (IaC) - a key DevOps practice ..................... 111
Scalability .......................................................................................... 113
Clustering .......................................................................................... 115
Chapter 4: Introduction to DevOps on IBM Cloud ............................116
Introduction to Cloud ............................................................................ 116
Why Cloud? ....................................................................................... 116

© 2019 IBM Corporation 4


DevOps Training Module

Introduction to IBM Cloud ................................................................ 116


DevOps on IBM Cloud ........................................................................... 118
Why DevOps on Cloud? ..................................................................... 118
IBM Cloud DevOps Services ............................................................. 119
Exercise 1 - DevOps using IBM Cloud................................................... 121
Test your knowledge ............................................................................. 131
Answer Keys ..................................................................................132
NOTICES ........................................................................................133

© 2019 IBM Corporation 5


DevOps Training Module

Chapter 1: DevOps Fundamentals


Introduction to DevOps

What is DevOps?

DevOps (a clipped compound of "development" and "operations") is a


software development methodology that combines software development
(Dev) with information technology operations (Ops). The goal of DevOps is
to shorten the systems development life cycle while also delivering
features, fixes, and updates frequently in close alignment with business
objectives. The DevOps approach is to include automation and event
monitoring at all steps of the software build.
– Wikipedia Introduction of DevOps

The screen capture depicts the meaning of DevOps in business. The term
DevOps is a blend of processes,
methods and tools combined with a set
of principles and practices that can be
adopted by the development and
operations teams to achieve faster
releases, better quality and happier
teams.
It is a modern way of delivering business value through bringing
development and operations together to collaborate and co-create better
outcomes.
Making any change in “business as usual” is always hard and usually
requires an investment. So whenever an organization adopts any new
technology, methodology, or approach, that adoption has to be driven by a
business need. To develop a business case for adopting DevOps, you must
understand the business need for it, including the challenges that it

© 2019 IBM Corporation 6


DevOps Training Module

addresses. In this chapter, we give you the foundation you need to start
building your case.
A definition of DevOps

DevOps (n.) –
DevOps is a philosophy, a cultural shift that merges operations with
development and demands a linked toolchain of technologies to facilitate
collaborative change. DevOps toolchains can include dozens of
noncollaborative tools, making the task of automation a technically
complex and arduous one.

For more details on definition refer link:


https://en.wikipedia.org/wiki/DevOps#Definition
Benefits of DevOps approach

By following a DevOps approach, clients can benefit in several ways:


 Build a startup culture that brings business, development, and
operations together.
 Respond to the market faster and build engaging user experiences.
 Reduce development and operational costs by automating processes
such as code integration, testing, deployment, application
monitoring, and issue management.
 Deliver new features continuously without waiting for a convenient
time to deliver major releases.
 Ensure quality by enabling automated testing on a production-like
environment before you push changes to your production site.

© 2019 IBM Corporation 7


DevOps Training Module

Drivers of DevOps

There are three key drivers of DevOps:


1. Line-of-business leaders need to experiment and quickly determine
the best alternatives for new business capabilities.
2. Businesses need to quickly experiment with entering new markets,
introducing new products, and differentiating existing products with
enhancements.
3. Enterprises need rapid delivery of new apps and services and rapid
feedback for quick adjustments.
Understanding the Business Need for DevOps
Following are the main business need for an organization to opt for DevOps:
 Organizations want to create innovative applications or services to
solve business problems.
 Organization need to address internal business problems, such as
creating a better customer relationship management system or
providing a new mobile app.
 Many organizations aren’t successful with software projects,
however, and their failures are often related to challenges in software
development and delivery.
 Although most enterprises feel that software development and
delivery are critical.

Note: A recent IBM survey of the industry found that only 25


percent believe that their teams are effective. This execution
gap leads to missed business opportunities.

© 2019 IBM Corporation 8


DevOps Training Module

How is DevOps different from Traditional IT?

Refer the table for the key dimensions where DevOps & Traditional IT
differ:

Dimensions Traditional IT DevOps


Size Big Micro
Team Silos Dedicated team
Planning Centralized Decentralized
Release High risk Low risk
Data Massive reports but Small & Concise
poorly actioned items reports helps to act
faster
Culture Do not fail Fail early
Measure Cost & Capacity Cost, Capacity & Time
Definition of “Ready” “My part is done and “Ready to be
handed over” deployed”

Issues in traditional application

The problem is further amplified by a major shift in the types of applications


that businesses are required to deliver. They are
1. Systems of record
2. Systems of engagement

To explain in detail:
Systems of record
 Traditional software applications are large systems that functions as
systems of record. This in turn contain massive amounts of data
and/or transactions and are designed to be highly reliable and stable.
 This application doesn’t need to change often, organizations can
satisfy their customers and business needs by delivering only one or
two large new releases a year.

© 2019 IBM Corporation 9


DevOps Training Module

Systems of engagement
 With the advent of mobile communications and the maturation of web
applications.
 Systems of record are being supplemented by systems of
engagement.
 Customers can access directly and use to interact with the business.
Such applications must be easy to use, high performing, and capable
of rapid change to address customers’ changing needs and evolving
market forces.
 Systems of engagement are used directly by customers, they require
intense focus on user experience, speed of delivery, and agility — in
other words, a DevOps approach.
 Systems of engagement aren’t isolated islands and are often tied to
systems of record, so rapid changes to systems of engagement result
in changes to systems of record.
 Indeed, any kind of system that needs rapid delivery of innovation
requires DevOps.

Note: Such innovation is driven primarily by emerging


technology trends such as cloud computing, mobile
applications, Big Data, and social media, which may affect
all types of systems.

Recognizing the Business Value of DevOps

DevOps is essential
 In a cloud-native environment, applications are viewed as collections
of microservices with many deployable components that deploy at
various speeds and independently of each other.
 Manually deploying anything becomes an unsustainable effort prone
to error, inconsistency, and delays.

© 2019 IBM Corporation 10


DevOps Training Module

 Automating continuous delivery pipelines is a way to free operations


from deploying an application they have little knowledge of and
rescue developers from complex configurations and deployments.
 Efficient delivery means more time for innovation, enabling the
business to disrupt the market and competitors.
 Deliver to the market faster with quality

Return on Investment

DevOps provides significant return on investment in three areas:


 Enhanced customer experience
 Increased capacity to innovate
 Faster time to value
When to adopt / not adopt DevOps?

Many companies that incorporate DevOps practices get more things done
in a short span and also derive many business benefits. But it does not mean
it is right for every situation or project. DevOps is not a silver bullet. There
are some scenarios where DevOps approach will fail, and it is imperative to
understand where and when it will fit / misfit.
Below table provides few pointers on when to adopt / not adopt DevOps:
When to adopt? When not to adopt?
The main benefit of Microservice Transitioning legacy applications to
architecture is speed and DevOps newer technology is a big challenge
helps to achieve this through and if DevOps process also to be
people, process and technology included, then the challenge is
change escalated even further. A gradual
phase-out should be planned
When there is a demand for For smaller organizations that do
frequent production releases, not have much resources or there is
faster time to market no need of frequent production

© 2019 IBM Corporation 11


DevOps Training Module

releases, DevOps is not


recommended
When Agile methodology is already If the objective of a project is to
being followed launch a minimum viable product,
then DevOps is not required.
When Cloud technologies & If the product needs thorough
services are amalgamated with testing and more time is required,
DevOps, it can reap huge benefits, then DevOps may not help if the test
enhance agility and time to market suites are not automated
and also greatly reduces operating
costs

How is DevOps different from Agile? DevOps vs Agile

Agile and DevOps are not same though they have similar aims i.e. release
the product as quickly and efficiently as possible. But that doesn’t mean
one should be adopted over the other. On the contrary, both methodologies
can work in tandem. DevOps is not a replacement for Agile. But, it is an
improvement. Let’s see how.
Agile’s aim is to bring agility to Development. But DevOps’s aim is to bring
agility to both Development & Operations. It follows a set of best practices
for creating quality software in a timely manner. But, involves people
working in silos.

It means there are people who will be working as Developers, or as Testers,


or as ITOps with very little communication between them. Because of this,
they are not aware what the others are working though they are part of the
same process.

DevOps aims to bring software development teams and information


technology operation teams together. It is a concept that fosters a culture
of collaboration between these two teams that historically worked in their

© 2019 IBM Corporation 12


DevOps Training Module

own separate silos, from the initial design phase right through to product
release. The intent is to enable communication between the teams so that
they can build, test, and release software more quickly and with greater
efficiency and speed. In combining these two distinct teams and processes
together, it promoted continuous integration, continuous deployment,
automated testing, and transparency in code repositories.
Basically, DevOps brings together two large silo-ed teams together to allow
for quicker software releases while Agile is focused on getting smaller
teams to collaborate with each other, so it can react quickly to the ever-
changing consumer needs.
Both DevOps and Agile can work in tandem since they can complement
each other. DevOps promotes a fully automated continuous integration and
deployment pipeline to enable frequent releases, while Agile provides the
ability to rapidly adapt to the changing requirements and better
collaboration between different smaller teams.

DevOps Principles

DevOps methodology has a set of principles which is the cornerstone of


DevOps culture. Its primary objectives are to reduce the time to market,
apply incremental improvements in all areas with respect to the changing
environment, and create more streamlined processes. To truly achieve a
DevOps culture, some key principles should be followed.
Promote a collaborative environment
The main objective behind DevOps is to combine both development and
operations to form a single team that focuses on delivering common
objectives. To achieve this, development and operations should be
encouraged to regularly communicate, share ideas and solve problems
together.

© 2019 IBM Corporation 13


DevOps Training Module

Everyone is responsible
In traditional software development methodology, developers and
operation personnel had unique roles. But in DevOps, both of them work as
a single team who is fully accountable for the application from beginning to
end. This is one of the core principles of DevOps where there should be
control and responsibility of all services from the get-go till end.
Continuous improvement
End-to-end responsibility also means that the team must continuously
adapt to changing circumstances like new technology, customer needs etc.

DevOps puts a strong focus on continuous improvement to optimize


performance, cost and speed of delivery, minimize waste etc.

Automate where possible


Automating the processes where possible will reduce the time to market,
eradicate human errors and this is one the key step towards continuous
improvement. Automated infrastructure provisioning, build/deployment of
software products, unit testing etc. are some of the automated processes.
Focus on Customer’s Needs
DevOps teams must always work towards meeting the needs of ever-
changing consumer demands. They should innovate continuously and
invest in areas that will please the customer and also should try new
strategies & point of concepts.
Welcome Failures
DevOps teams must change their attitude towards failure. When the team
is empowered to radically transform their way of working, failure can occur.
But it’s important to convert those failures into opportunities to learn.

© 2019 IBM Corporation 14


DevOps Training Module

Embracing failure will foster a climate for learning which will positively
impact organizational culture.
Cross-functional independent teams
As DevOps teams are required to be involved at every stage of the software
development lifecycle, it requires a cross-functional team that has a
balanced set of skills and each member is an all-rounder. As it is not that
easy to find an IT professional with versatile skills, the teams should be
encouraged to share responsibility.

DevOps Lifecycle

DevOps engineers have end to end responsibility of the Application right


from gathering the requirements to development to testing to deployment
to monitoring & gathering feedback from the end users, then again
implementing the changes. This never-ending cycle consists of various
phases and let’s see below some of the important ones. The diagram shows
various DevOps phases and examples of DevOps tools.

© 2019 IBM Corporation 15


DevOps Training Module

Plan: The first phase in DevOps lifecycle is to plan the application. Create a
set of achievable targets that must be delivered by the application. Once
these targets are finalized, project development can commence.
Code: This phase consists of developing the code as per requirements.
Since DevOps lifecycle is continuous, sometimes the development can
happen on already existing code as well.
Build: The application is built by performing the integrations of various
codes developed in previous phase
Test: Test the application to ensure functional and performance
requirements are met. If not, fix the code, rebuild and test again.
Release: Once the testing phase is completed successfully, the code
should be packaged and released for deployment.
Deploy: Deploy the code in respective environment for further usage. It is
important to ensure that the deployment should not affect the functioning
of application for the end users.
Operate: All DevOps operations are based on automation of release
process, applying patches etc. which will allow organizations to accelerate
the overall time to market on an ongoing basis.
Monitor: In the monitoring phase, key information about application usage
is recorded and carefully analyzed to find out trends and identify the
problem areas. Automatically monitor metrics so any change in code that
impacts the production environment can be identified quickly.

© 2019 IBM Corporation 16


DevOps Training Module

Test your knowledge

1) Which one of below is not ensured by DevOps?


A. Continuous software delivery
B. Faster delivery of features
C. Faster resolution of problems
D. Bug free code

2) Which one of below is not true?


A. Devops is a philosophy that merges operations and development
team
B. Agile & DevOps are same
C. Traditional IT culture is “Do not fail”
D. DevOps’s aim is to bring agility to both Development & Operations.

3) When not to adopt DevOps?


A. When there is a demand for frequent production releases, faster
time to market
B. When Agile methodology is already being followed
C. When the objective of a project is to launch a minimum viable
product
D. When Microservice architecture is already being used

4) Which of the following is a goal of DevOps?


A. Larger, less frequent releases
B. Increased lead time between fixes
C. Lower failure rate of new releases
D. Reduced feedback loops

5) What are the primary objectives of DevOps?


A. Promote a collaborative environment
B. Automate where possible
C. Welcome failures
D. All of the above

© 2019 IBM Corporation 17


DevOps Training Module

Introduction to Continuous Integration / Continuous Delivery /


Continuous Deployment
Before DevOps era, most companies would deploy software in
monthly/quarterly/half-yearly/annual releases. But now, weekly/daily or
multiple daily deployments are common. Due to this frequent deployment,
the conventional methods of development & delivery are rapidly turning
obsolete.

To adapt to the shortened deployment cycles, most of the developers have


automated processes related to code check-in, deployment etc. And this
has birthed 3 strategies: Continuous Integration, Continuous Delivery &
Continuous Deployment. Let’s see what they mean.

Continuous Integration

It is a process of merging all code from all developers in a team to one


central branch of the repository many times a day so conflicts in the code
could be avoided in the future. This merged code will be verified by an
automated build which helps developers to find bugs before it is too late.
More the wait time to integrate code, then higher the chances of bigger
problems. For example, let’s say you are sewing a shirt and you give sleeves
to one person and body of the shirt to another person. If you wait till the last
day to give the shirt to someone, then there are chances that it will not fit

© 2019 IBM Corporation 18


DevOps Training Module

that person. So, Continuous Integration will help in saving on costs in the
long run since it is more expensive to fix defects in the architecture when
it’s discovered later on in the process.

Continuous Delivery

This process is about automated build, packaging, deployment & testing


processes to reduce manual efforts and speed up the delivery. Its aim is to
keep the code in deployable state at any given point of time. This does not
mean the code is 100% complete but it gives confidence that whatever
feature sets are available are tested, debugged & ready to deploy in any
environment. This process benefits business users because as soon as the
code is ready to be tested, it is released to users who can provide feedback
immediately whether their expectations are met or not.

Continuous Deployment

This is about automated deployment of code to production environment as


soon as it is ready without any manual intervention i.e. whenever the
developer changes code, assuming all automated builds/tests pass, the
code is automatically deployed into production without manual
intervention. Some companies push hundreds and thousands of releases
into production every day. And of course, it requires a first-class automation
coverage, ability to roll out changes slowly (starting with small subset of
servers and expanding to more if no issues) and also ability to roll back
quickly if any issues occur.

© 2019 IBM Corporation 19


DevOps Training Module

Introduction to DevOps Tools


Version Control – Git

The most widely used modern version control system in the world today is
Git. It is a mature and open source project originally developed in 2005 by
Linus Torvalds, the famous creator of the Linux operating system kernel.
Large number of software projects rely on Git for version control, that
includes both commercial projects as well as open source.
GitHub is a collaboration version control platform for developers. Using Git,
source code for each project is stored and maintained and tracks the
complete history of the commits. Git provide tools which effectively
collaborate on a project and manages all conflicting changes in commits
from multiple developers. It delivers quality project by allowing developers
to change, adapt and improve the source code.
Command Description
Git –version Displays the git version.
Git init --bare Creates a new bare local git repository.
Git clone Downloads the project and its entire version
history.
Git config –global user.name Sets the name you want to your commit
“[name]” transactions.
Git config –global user.email Sets the email you want to your commit
“[email_address]” transactions.
Git config --list Displays all the configurations.
Git status Lists all the new or modified files to be committed.
Git add [file] Snapshots the file in preparation for versioning.
Git branch [branch_name] Creates a new branch.
Git checkout [branch_name] Switches to the specified branch and updates the
working directory.
Git commit -m Records file snapshots permanently in version
“[commit_message]” history.
Git push -u origin [branch_name] Uploads all the local branch commits to Github.
Git merge [branch_name] Combines the specified branch’s history into the
current branch.

© 2019 IBM Corporation 20


DevOps Training Module

Exercise 1: Git Server installation


In this exercise you will learn how to install Git server
Procedure
1. Open Terminal & login to our non-root user and update the default
packages.
$ sudo apt update
2. Create the SSH Key Pair

Note: If you change the file location where you save your ssh
key, then make sure you give the same location in step in 6.

3. Now create a new non-sudo user for Git.

© 2019 IBM Corporation 21


DevOps Training Module

Note: Set the password for the new git user, use the same
password in step 6 & 7.

4. Install git server


$ sudo apt-get -y install git
5. Add the created non-sudo user to the ssh configuration as shown
below and make sure the ssh port is assigned as 22 in the
configuration.
$ sudo vim /etc/ssh/sshd_config -- ssh configuration file

© 2019 IBM Corporation 22


DevOps Training Module

Now restart the ssh server by issuing the below command –


$ sudo service ssh restart

Note: If vim editor is not found, then install using below


command
$ sudo apt install vim

6. Add SSH Key to the Access List

7. SSH into git user

8. Create a repository

© 2019 IBM Corporation 23


DevOps Training Module

9. Logout from git user

10. Testing (Cloning repo to local)

Exercise 2: Git Client Installation


In this exercise you will learn how to install Git client
Procedure -
1. Log in into the non-sudo user and update the default packages and
install the git

2. Check the git version installed

3. Now, Set up the git client username and mail id

4. The git client setup is completed, and we can access the server and
commit the files.

© 2019 IBM Corporation 24


DevOps Training Module

Exercise 3: Git Exercise


In this exercise you will learn some of the important Git commands
1. Clone the remote repository

2. Get inside the cloned repository and check the status.

It shows No commits yet.

3. Create README.md file inside repository.

4. Add and commit the README.md file.

5. So, you have done one commit successfully through Git.

© 2019 IBM Corporation 25


DevOps Training Module

6. Now, create one branch devops_branch.

In list you can see, you have two branches and currently you are on
master branch.

7. Checkout/Switch to new branch devops_branch.

8. Now check status for the new branch.

9. Create some files (sample.txt) to git and stage them for commit.

10. Commit all the staged files.

11. Push all the changes to the remote repository on devops_branch.

© 2019 IBM Corporation 26


DevOps Training Module

All the changes have been pushed to remote repo branch


devops_branch.

12. Now, checkout to master branch and list all the content of directory.

You can see, master branch’s content is in the state where you left it.
No code commit made to master.

13. Merge devops_branch with master branch (If you have already
merged it will show).

Now you can see all the changes are merged to master branch.

© 2019 IBM Corporation 27


DevOps Training Module

Test your knowledge


1) Which command should you use to initialize a new Git repository?
A. git run
B. git install
C. git init
D. git start
2) How do you supply a commit message to a commit?
A. git message "I'm coding"
B. git add "I'm coding"
C. git commit "I'm coding"
D. git commit -m "I'm coding"

3) Command to switch to the branch is


A. git checkout master
B. git change master
C. git switch master
D. git master

4) How do you check the state of your local git repository since your last
commit?
A. git check
B. git status
C. git commit
D. git diff
5) What's the git command that downloads your repository from GitHub to
your computer?
A. git push
B. git fork
C. git clone
D. git commit

© 2019 IBM Corporation 28


DevOps Training Module

Build Automation – Maven


Maven is a build automation and project management tool developed by
Apache Software Foundation. It was initially released on 13 July 2004. In
Yiddish language the word Maven means "accumulator of knowledge".
It is written in Java Language and used to build and manage projects written
in C#, Ruby, Scala, and other languages. It is used to build projects,
dependency, and documentation and it is much advanced than ANT. It
handles multiple tasks like compilation, distribution, documentation, team
collaboration easily.
Maven is also able to build any number of projects into desired output such
as jar, war, metadata.
Commands Description
mvn -version Specifies the maven version installed.
mvn clean Deletes the target directory and any generated
resources.
mvn test Runs the tests against the compiled source
code using a suitable unit testing framework.
mvn install Runs the package command then installs it in
local repo.

Exercise 4: ECLIPSE IDE Installation


In this exercise you will learn how to install Eclipse IDE which is required
for Maven exercise.
Procedure -
1) Install Java
As Eclipse is a java-based IDE it requires Java JDK to be installed on the
system you want to use. To install JDK, use the steps below:
$ sudo apt update

© 2019 IBM Corporation 29


DevOps Training Module

$ sudo apt install openjdk-8-jdk


$ java -version (To check the version)

2) Download Eclipse
Now that Java JDK 8 is installed, download the latest Eclipse IDE package
for your systems. The link below can be used to get it.

https://www.eclipse.org/downloads/

3) Install Eclipse
Use the commands below to extract the content in the ~/Downloads folder
$ tar xfz ~/Downloads/eclipse-inst-linux64.tar.gz
Now launch the Eclipse installer-
~/Downloads/eclipse-installer/eclipse-inst
Select the package IDE you want to install and continue.

© 2019 IBM Corporation 30


DevOps Training Module

Use the onscreen instructions to complete the installer. Accept the default
installation directory and continue.

© 2019 IBM Corporation 31


DevOps Training Module

Next, accept the license terms and continue, it will install Eclipse along with
all the packages.

After installation is complete, launch the Eclipse IDE.

4) Create Eclipse App Launcher


Once it is downloaded & installed, create a launcher for the application. For
that, run the below command -
$ vim .local/share/applications/eclipse.desktop
Next, copy and paste the content below into this file and save it. (Change
the Exec and Icon accordingly)

© 2019 IBM Corporation 32


DevOps Training Module

[Desktop Entry]
Name=Eclipse JEE Oxygen
Type=Application
Exec=/home/administrator/eclipse/java-2019-03/eclipse/eclipse
Terminal=false
Icon=/home/administrator/eclipse/java-2019-03/eclipse/icon.xpm
Comment=Integrated Development Environment
NoDisplay=false
Categories=Development;IDE;
Name[en]=Eclipse

5) Launch Eclipse IDE

Set the Eclipse Workspace -

© 2019 IBM Corporation 33


DevOps Training Module

Exercise 5: Maven Installation


In this exercise we will learn how to install Maven
Procedure -
1) Create a new Maven project
File New  Project  Maven  Maven Project

© 2019 IBM Corporation 34


DevOps Training Module

Select an archetype for the project

Now, provide suitable parameters (Group ID and Artifact ID) for the project

© 2019 IBM Corporation 35


DevOps Training Module

And Click on Finish.


Sample Project -

Maven project structure look like this -

We will create a simple calculator project which is modularized which helps


in testing through Junit and ease the process of refactoring.
1. First, create a class CalcMain.java in “src/main/java” and place this
following code
package com.devops.calcProject;

import java.util.Scanner;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

public class CalcMain


{
static final Logger logger = Logger.getLogger(CalcMain.class);

public static void main( String[] args )


{
BasicConfigurator.configure();
int a,b,choice;

© 2019 IBM Corporation 36


DevOps Training Module

float result=0;
Scanner in=new Scanner(System.in);
a=Integer.parseInt(args[0]);
logger.info("First number: "+a);
b=Integer.parseInt(args[1]);
logger.info("Second number: "+b);

logger.info("\n1: Addition.\n2: Subtraction.\n3: Multiplication.\n4:


Divide.\n5: Remainder.\n6: Exit.");

choice=Integer.parseInt(args[2]);
logger.info("\nYour choice: "+choice);
switch(choice)
{
case 1:
result=addition(a,b); break;
case 2:
result=subtraction(a,b); break;
case 3:
result=multiplication(a,b); break;
case 4:
result=division(a,b); break;
case 5:
result=remainder(a,b); break;
default:
logger.info("An Invalid Choice!!!\n");
}
if(choice>=1 && choice<=5)
logger.info("Result is: " + result);
}

public static int addition(int a,int b) {


return a+b;
}
public static int subtraction(int a,int b) {
return a-b;

© 2019 IBM Corporation 37


DevOps Training Module

}
public static int multiplication(int a,int b) {
return a*b;
}
public static float division(int a,int b) {
return (float)((float)a/(float)b);
}
public static int remainder(int a,int b) {
return a%b;
}
}

2. Next, add the dependencies used in pom.xml file. Add the following
code in the pom.xml file.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.devops</groupId>
<artifactId>calcProject</artifactId>
<version>0.2</version>
<packaging>jar</packaging>

<name>CalcProject</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>

© 2019 IBM Corporation 38


DevOps Training Module

<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.devops.calcProject.CalcMain</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>

</project>

3. You have created your maven project and added all the class and
dependencies. Now, you will run the project which will create an
executable jar.
For this, right click on your project from Project Explorer bar, select
“Run as” and then click on “maven clean”. This will clean your project
removing target folder, all class files, java docs, jars etc.

© 2019 IBM Corporation 39


DevOps Training Module

Maven clean output will look like this -

4. After this, perform “maven install” which will add all artifacts and
dependencies specified in pom, to the local repository and creates an
executable jar out of it.

© 2019 IBM Corporation 40


DevOps Training Module

Maven install output will look like this –

5. In case of “Build Success” message in “maven install” means that


your code is without syntax error and all the dependencies are
resolved. This will generate an executable jar in project workspace
directory under “target” folder.

6. Now, you can take the jar from above location and paste it to a
directory and execute it using the below command.
$ java -jar {jarName} {commandLineArguments}

© 2019 IBM Corporation 41


DevOps Training Module

Test your knowledge


1) POM stands for
A. Project Object Model
B. Project Oriented Model
C. Prospective Object Model
D. Prospective Objective Model

2) Which of the following command removes the target directory with all
the build data before starting the build process?
A. mvn clean
B. mvn build
C. mvn compile
D. mvn site

3) Which of the following is not a maven goal?


A. clean
B. package
C. install
D. debug

4) Which file is used to define dependency in maven?


A. build.xml
B. pom.xml
C. dependency.xml
D. version.xml
5) Which command can be used to check maven version?
A. mvn -ver
B. maven -ver
C. maven -version
D. mvn -version

© 2019 IBM Corporation 42


DevOps Training Module

Configuration Management – Puppet


Puppet is a configuration management tool which harness infrastructure as
code capabilities. Puppet has the capability to manage any system from
scratch, starting from initial configuration till end-of-life of any machine.
Puppet works on the client server architecture, wherein we call the server
as the Puppet master and the client as the Puppet node/agent.
Commands Description
puppet agent -t Provides the agent configuration and
modifications
puppet apply [file.pp] Apply puppet manifests locally

Exercise 6: Installing Puppet on Ubuntu


In this exercise you will learn how to install Puppet on Ubuntu
Procedure -
For puppet installation you will install both master and client/agent on
single node.
1. First step is to install puppetlabs repository –
$ sudo wget https://apt.puppetlabs.com/puppetlabs-release-
trusty.deb
$ sudo dpkg -i puppetlabs-release-trusty.deb

Now you can see the puppetlab repository in the directory.

2. You need to install puppet master and puppet agent both on the
same machine
$ sudo apt-get update
$ sudo apt-get install puppetmaster
$ sudo apt-get install puppet

© 2019 IBM Corporation 43


DevOps Training Module

3. Now, you will install puppet dependencies tools for the development
process
$ sudo apt-get install vim-puppet puppet-lint

4. Next step is to configure the puppet services, for this you need to use
puppet config file which can be found at - /etc/puppet/puppet.conf.
This file has 3 sections namely-
[main] – These configurations are global and are used by all services.
[master] – These configurations are used by puppet master service.
[agent] - These configurations are used by puppet agent service.

5. Give permission to puppet.conf file by executing below command


and then open the file in editor
$ sudo chmod 777 puppet.conf
$ vi puppet.conf
Update and define these sections with the configuration as shown
below -

© 2019 IBM Corporation 44


DevOps Training Module

[main]
confdir = /etc/puppet
logdir = /var/log/puppet
vardir = /var/lib/puppet
ssldir = /var/lib/puppet/ssl
rundir = /var/run/puppet
environmentpath = $confdir/environments
factpath = $vardir/lib/facter
pluginsource = puppet:///plugins
pluginsync = true
srv_domain = localhost
strict_variables = true
parser = future

[master]
vardir = /var/lib/puppet
cadir = /var/lib/puppet/ssl/ca
dns_alt_names = puppet
certname = localhost
report = true
reports = log
ssl_client_header = HTTP_X_CLIENT_DN
ssl_client_verify_header = HTTP_X_CLIENT_VERIFY

[agent]
certname = localhost
server = localhost
pluginsync = true
report = true
summarize = true

6. After saving the puppet config file, restart the puppet master.
$ sudo service puppetmaster restart

7. Create a new environment (as you used environmentpath in the


configuration in step 5) under /etc/puppet directory.
$ sudo mkdir -p /etc/puppet/environments/devops

© 2019 IBM Corporation 45


DevOps Training Module

8. Now, test our defined puppet configuration by running puppet agent


using the below command.
$ sudo puppet agent -t

9. Finally, test the puppet installation. For this you need to create puppet
file (.pp file extension) under manifests folder of your environment as
shown below.
If write permission is not there, then go back to environments folder and
execute below command:
$ sudo chmod 777 devops

Then, execute below commands


$ sudo mkdir manifests
$ sudo vi site.pp
And save the blank file

Here, site.pp is our puppet file.

© 2019 IBM Corporation 46


DevOps Training Module

Exercise 7: Puppet Exercise


1. In this exercise you will check the existence of a file and create if it is
not present. Place the below resource code in the site.pp file.

file { '/home/administrator/Desktop/Wallpaper.png':
ensure => present
}
Before applying this configuration, check whether your file exist or not
(file does not exist)-

Now run the following command to apply the configuration-


$ sudo puppet apply site.pp (before running the command, you can
also use –noop option, this will do a dry-run without actually applying
the configuration)
After you run the above command, the site.pp configuration is applied
and you can see the new file created in the specified directory.

2. In this exercise you will install a package via puppet agent.


For this, place this resource code in our site.pp file.

© 2019 IBM Corporation 47


DevOps Training Module

# install mysql-server package


package { 'mysql-server':
ensure => installed,
}

# ensure mysql service is running


service { 'mysql':
ensure => running,
}

Now, apply the configuration by running the following command:


$ sudo puppet apply site.pp

The above command updated puppet configuration (install mysql-


server) on our agent, so verify the installation –

Mysql is installed on agent using the puppet configuration.

© 2019 IBM Corporation 48


DevOps Training Module

Test your knowledge


1) PUPPET is mainly used to
A. automate administration tasks
B. Deployment tasks
C. Designing tasks
D. Virtualization tasks

1) PUPPET follows which type of architecture?


A. Master-Slave
B. Master only
C. Slave-Master
D. None of the above

2) Command to sign Requested Certificates


A. puppet sign hostname-of-agent
B. puppet --sign hostname-of-agent
C. puppet ca sign hostname-of-agent
D. puppet ca-sign hostname-of-agent

3) Where Puppet Master Stores Certificates?


A. /var/lib/puppet/ssl/ca/signed
B. /var/lib/puppet
C. /var/lib/puppet/ssl/
D. /var/lib/puppet/ssl/ca/

4) What is Manifests in PUPPET?


A. Client configuration files
B. Workspace files
C. Imported module files
D. Proxy settings files

© 2019 IBM Corporation 49


DevOps Training Module

Containerization with Docker


Docker unites software-as-a-service and platform-as-a-service that
use operating-system-level virtualization to develop and run packaged
software called containers. Docker provisions, packages and runs
containers which are independent of the underlying OS. Docker is a tool to
create, deploy, and run applications easily by using containers. Containers
allow a developer to package up an application with all the parts it needs,
such as libraries and other dependencies, and ship it all out as one package.
By doing so, the developer can rest assured that the application will run on
any other Linux machine regardless of any customized settings that
machine might have that could differ from the machine used for writing and
testing the code.
Docker is like a VM but unlike a VM, rather than creating a whole virtual
operating system, Docker allows applications to use the same Linux kernel
as the system that they're running on and only requires applications be
shipped with things not already running on the host computer. This gives
significant performance and reduces the size of the application.
Commands Description
docker --version Describe the docker version installed.
systemctl status docker Describe the current docker status.
docker build -t Used to build an image from a specified docker
[image_name]:[tag_name] . file.
docker images Used to list all the locally stored docker images.
docker run Used to create a container from an image.
[image_name]:[tag_name]
docker ps Used to list the running containers.
docker ps -a Used to show all the running and exited
containers.

© 2019 IBM Corporation 50


DevOps Training Module

Exercise 8: Installing Docker on Ubuntu


In this exercise you will learn how to install Docker on Ubuntu
Procedure
To install docker on our Ubuntu machine and then dockerize your maven
project, follow the below steps –
1. First, update the default packages and install the dependencies
needed to install and run Docker.
$ sudo apt update
$ sudo apt install apt-transport-https ca-certificates curl software-
properties-common
2. Next step is to add the GPG key for the docker repository.
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo
apt-key add -

3. Now add the stable docker APT repository to your system’s software
repository list.
$ sudo add-apt-repository "deb [arch=amd64]
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

4. The above step enabled the docker repository, you need to update
your default apt packages.

© 2019 IBM Corporation 51


DevOps Training Module

$ sudo apt update


5. Now install the docker community edition.

$ sudo apt install docker-ce


6. After the installation is complete, docker service will start
automatically. You can verify that by checking the status of our
docker service.

$ sudo systemctl status docker

Now you can see that docker is installed and running.

© 2019 IBM Corporation 52


DevOps Training Module

Exercise 9: Create Docker images


In this exercise, you will create docker image with a program. For this
create a directory and place the executable jar created by maven in that
directory.
Now, create a file named “Dockerfile” in the same directory and place this
content in it.

#Dockerfile for running java application


FROM anapsix/alpine-java
MAINTAINER [email protected]
COPY calcProject-0.2-jar-with-dependencies.jar /home/calcProject-0.2-jar-with-
dependencies.jar
CMD ["java","-jar","/home/calcProject-0.2-jar-with-dependencies.jar","2","3","1"]

Now, run the below step to build the docker image.


$ sudo docker build -t devops_calc:1.0 .

You can check that your image is created using the below command.
$ sudo docker images

© 2019 IBM Corporation 53


DevOps Training Module

Now, run the build image by issuing the below command.


$ sudo docker run devops_calc:1.0

Now, you can see your dockerized application executed.

© 2019 IBM Corporation 54


DevOps Training Module

Test your knowledge


1) What is the difference between a Docker container and a Docker
image?
A. Nothing: these are two words for the same thing.
B. An image is the blueprint for spinning up containers. An image
is a TAR of a file system, and a container is a file system plus a
set of processes running in isolation.
C. Images are used to create the host machine that runs the
Docker Engine.
D. Images are used only as a backup and restore mechanism for
containers.

2) Which statement is not true about Docker?


A. Docker makes it easier to package applications and add to
CI/CD pipelines.
B. Docker helps you package dependencies with containers.
C. Docker invented containers and Linux namespaces.
D. Docker simplifies container technology to make creating and
running containers easier.

3) Which file should you use to create reproducible builds for Docker
images?
A. docker.yml
B. docker.config
C. Dockerfile
D. README.md

4) To rebuild and re-push images quickly, you should optimize your


Dockerfile for what?
A. Reproducibility: ensures your Dockerfile will create the same
image every time it is built
B. Documentation: helps other engineers build and push images
faster

© 2019 IBM Corporation 55


DevOps Training Module

C. Time to market: enables business users to get their features


out faster
D. The layer cache: put lines that change more frequently near
the end of the file

5) ____is a tool for defining and running multi-container Docker


applications.
A. Docker Swarm
B. Docker Hub
C. Docker Cloud
D. Docker Compose

© 2019 IBM Corporation 56


DevOps Training Module

Continuous Deployment – Jenkins


Jenkins is an open source continuous integration (CI) and continuous
delivery (CD) tool built in Java.

Exercise 10: Installation of Jenkins on Ubuntu


In this exercise you will learn how to install Jenkins on Ubuntu
Procedure -
1. As Jenkins is a Java based tool, you need to install Java first. Check
if the java is already installed, if not then install using the below
command.
$ sudo apt-get install openjdk-8-jdk

2. For Jenkins to work you need a web server, here you will install
nginx web server. To install nginx use the below step.
$ sudo apt-get install nginx
Make sure our web server is running, for this, type our localhost IP
on browser.

3. Next step is to add the repository key to the system.


$ wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-
key add -

Now append the package repository to the system’s source list.

© 2019 IBM Corporation 57


DevOps Training Module

$ sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ >


/etc/apt/sources.list.d/jenkins.list'

4. Next, update default apt packages.


$ sudo apt update

5. Now install Jenkins along with its dependencies.


$ sudo apt-get install jenkins

6. Once Jenkins is installed, you can check the status using the below
command.
$ sudo systemctl status jenkins

7. Default Jenkins port is 8080. To start the Jenkins, give the IP and
port 8080 in the browser, it looks like - http://localhost:8080.
After this you will be asked to enter Administrator password which
can be found in this file-
“/var/lib/jenkins/secrets/initialAdminPassword”. Take the password
and paste it to get started.

© 2019 IBM Corporation 58


DevOps Training Module

8. Next, you need to customize the Jenkins configuration. Install the


suggested plugins.

This will install the plugins.

© 2019 IBM Corporation 59


DevOps Training Module

9. After all the plugins are installed, you will be prompted to set up the
administrative user. Create a user of your choice-

10. Next you will be prompted with Instance Configuration where you
need to provide the URL for our Jenkins instance and then click
“Save and Finish”.

© 2019 IBM Corporation 60


DevOps Training Module

11. After setting the URL, Jenkins installation is complete, and you can
start using our Jenkins instance.

© 2019 IBM Corporation 61


DevOps Training Module

You have successfully installed Jenkins.

© 2019 IBM Corporation 62


DevOps Training Module

Test your knowledge


1) Jenkin is written in
A. Python
B. Java
C. C#
D. Go

2) Which command is used to run the Jenkins installation file in the war
format?
A. java –jar Jenkins.war
B. java –j Jenkins.war
C. javac Jenkins.war
D. java waenkins.war

3) Which source code management plug-in does Jenkins install by


default?
A. Git
B. Subversion
C. Concurrent Versions System
D. None

© 2019 IBM Corporation 63


DevOps Training Module

Continuous Integration – Jenkins


Jenkins is an open source Continuous Integration server capable of
orchestrating a chain of actions that help to achieve the Continuous
Integration process in an automated fashion. By using Jenkins, software
companies can accelerate their software development process, as Jenkins
can automate build and test at a rapid rate. Jenkins supports the complete
development lifecycle of software from building, testing, documenting the
software, deploying and other stages of a software development lifecycle.

In Chapter 2, you will learn more about how to setup a CI/CD pipeline from
scratch and how Jenkins achieve Continuous integration.

© 2019 IBM Corporation 64


DevOps Training Module

Continuous Testing – Junit


JUnit is a unit testing framework used in Java applications. JUnit is useful
in test-driven development. JUnit test cases are designed which will test
the functionality of the individual methods in the code base.

Exercise 11: JUnit Installation


In this exercise you will learn how to install JUnit
Procedure -
1. For JUnit testing, make sure you have this dependency in pom.xml
file.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
If not,add the above dependency under “dependencies” tag in
pom.xml.

© 2019 IBM Corporation 65


DevOps Training Module

2. Now, you will create a class called CalcTest.java inside


“src/test/java” in the same project.

3. Place the following code in the CalcTest.java class. Here you have to
create both valid and invalid junit tests for all methods (which can be
individually tested).

package com.devops.calcProject;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import org.junit.*;

import com.devops.calcProject.CalcMain;

public class CalcTest {

@Test
public void testValidAdddition(){
int result = CalcMain.addition(4,6);
assertEquals(result,10);
}

@Test

© 2019 IBM Corporation 66


DevOps Training Module

public void testValidSubtraction(){


int result = CalcMain.subtraction(6,3);
assertEquals(result,3);
}

@Test
public void testValidMultiplication(){
int result = CalcMain.multiplication(4,6);
assertEquals(result,24);
}

@Test
public void testValidDivison(){
float result = CalcMain.division(10,2);
assertEquals(result,5.0,5.0f);
}

@Test
public void testValidRemainder(){
int result = CalcMain.remainder(10,3);
assertEquals(result,1);
}

@Test
public void testInvalidAdddition(){
int result = CalcMain.addition(6,2);
assertNotEquals(result,9);
}

@Test
public void testInvalidSubtraction(){
int result = CalcMain.subtraction(10,4);
assertNotEquals(result,8);
}

@Test

© 2019 IBM Corporation 67


DevOps Training Module

public void testInvalidMultiplication(){


int result = CalcMain.multiplication(11,5);
assertNotEquals(result,22);
}

@Test
public void testInvalidDivison(){
float result = CalcMain.division(20,5);
assertNotEquals(result,5.0f);
}

@Test
public void testInvalidRemainder(){
int result = CalcMain.remainder(12,6);
assertNotEquals(result,1);
}
}

4. To test your Junit test cases, right click on your project from Project
Explorer bar, select “Run As” and then click on “maven test”.

© 2019 IBM Corporation 68


DevOps Training Module

Output of “Maven test” will be-

5. When you perform “Maven test”, all the junit test cases in the project
are executed, but you can also test your junit tests separately. To test
the Junit test cases right click on the “CalcTest.java” class and under
“Run As” option, click on Junit Test.

© 2019 IBM Corporation 69


DevOps Training Module

It will give test results like this

© 2019 IBM Corporation 70


DevOps Training Module

Test your knowledge


1) Which of the following annotation causes that method to be run after
each Test method?
A. @Test
B. @Before
C. @After
D. @AfterClass

2) JUnit is used for what type of software testing for the Java language?
A. Unit Testing
B. Integration Testing
C. Functional Testing
D. System Testing

3) JUnit test methods must compulsorily return what value?


A. String
B. int
C. Object
D. Void

4) JUnit test files are written in files with which file extension?
A. .junit
B. .test
C. .java
D. .unit

5) What is the purpose of assertArrayEquals(“message”, A, B)?


A. Checks that “message” is in both A and B
B. Checks that “message” is in A but not B
C. Checks that “message” is in B but not A
D. Asserts the equality of the A and B arrays

© 2019 IBM Corporation 71


DevOps Training Module

Continuous Monitoring - Nagios


Nagios is an open-source tool that monitors systems, networks and
infrastructure. It offers monitoring and alerting services for servers,
switches, applications and services. It watches hosts and services that
you specify, alerting you when things go bad and when they get better.

Benefits of using Nagios are:


 Fast detection of network and server outages and protocol failures
 Fast detection of failed servers, services, processes and batch jobs

Commands Description

apt-get install wget build-essential To compile OpenSSL manually from sources,


unzip openssl libssl-dev you need to first install few dependencies such
as “Development
Tools” under RHEL/CentOS/Fedora or “build-
essential” in Debian/Ubuntu as shown.
apt-get install apache2 php To install apache and PHP
libapache2-mod-php php-gd libgd-dev
groupadd nagcmd Create a group for Nagios setup “nagcmd”
usermod -a -G nagcmd Nagios To add Nagios user to the group
usermod -a -G nagcmd www-data To add Nagios user to apache group
./configure --with-command- Before installing, need to configure
group=nagcmd
htpasswd -c To setup apache authentication for user
/usr/local/nagios/etc/htpasswd.users nagiosadmin
nagiosadmin

a2enconf nagios To enable the apache configuration and to


a2enmod cgi rewrite restart apache for new settings
service apache2 restart

© 2019 IBM Corporation 72


DevOps Training Module

Exercise 12: Nagios Installation


In this exercise, you will learn to install Nagios.
1. Prerequisite – Ensure below options are selected under Software & Updates
in your Ubuntu VM

© 2019 IBM Corporation 73


DevOps Training Module

2. To install Apache and PHP, follow the below commands


$ sudo apt-get update
$ sudo apt-get install wget build-essential unzip openssl libssl-dev
$ sudo apt-get install apache2 php libapache2-mod-php php-gd libgd-
dev
3. Create Nagios User
Create a new user account for Nagios in your system and assign a
password for the Nagios user.
User: nagios
Pwd: nagiosuser

© 2019 IBM Corporation 74


DevOps Training Module

Create a group for Nagios setup “nagcmd” and add Nagios user to this
group. Also, add Nagios user in the Apache group.
$ sudo groupadd nagcmd
$ sudo usermod -a -G nagcmd nagios
$ sudo usermod -a -G nagcmd www-data

4. Install Nagios Core Service


After installing required dependencies and adding user accounts, let’s
start with Nagios core installation. Download latest Nagios core service
from the official site.

$ cd /opt
$ sudo wget
https://assets.nagios.com/downloads/nagioscore/releases/nagios-
4.4.3.tar.gz
$ sudo tar xzf nagios-4.4.3.tar.gz

After extracting, navigate to Nagios source directory and install using


make command.

$ cd nagios-4.4.3
$ sudo ./configure --with-command-group=nagcmd
$ sudo make all
$ sudo make install
$ sudo make install-init
$ sudo make install-daemoninit
$ sudo make install-config
$ sudo make install-commandmode
$ sudo make install-exfoliation

Copy event handlers scripts under libexec directory. These binaries


provide multiple events triggers for your Nagios web interface.

© 2019 IBM Corporation 75


DevOps Training Module

$ sudo cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/


$ sudo chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

5. Setup Apache with Authentication


Create an Apache configuration file for your Nagios server as below:

In /etc/apache2/conf-available/nagios.conf

$ sudo vi /etc/apache2/conf-available/nagios.conf

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>

Alias /nagios "/usr/local/nagios/share"

<Directory "/usr/local/nagios/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>

© 2019 IBM Corporation 76


DevOps Training Module

You need to setup apache authentication for user nagiosadmin (use


username as “nagiosadmin”, if you want to use other user make
changes in nagios configuration).

$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Note: Give password as “nagiosadmin” and use this password


while logging into Nagios dashboard.

Now enable Apache configuration and restart Apache service to make


the new settings take effect.

$ sudo a2enconf nagios


$ sudo a2enmod cgi rewrite
6. Open ports.conf under /etc/apache2 and ensure below is present
Listen 9090

© 2019 IBM Corporation 77


DevOps Training Module

7. Then restart apache service


$ sudo service apache2 restart

8. Installing Nagios Plugins


After installing and configuring Nagios core service, download latest
nagios-plugins and install using following commands.

$ cd /opt
$ sudo wget http://www.nagios-plugins.org/download/nagios-plugins-
2.2.1.tar.gz
$ sudo tar xzf nagios-plugins-2.2.1.tar.gz
$ cd nagios-plugins-2.2.1

Now compile and install Nagios plugins

$ sudo ./configure --with-nagios-user=nagios --with-nagios-


group=nagios --with-openssl
$ sudo make
$ sudo make install

9. Verify Settings
Use the below Nagios commands to verify the Nagios installation and
configuration file. After successful installation start the Nagios core
service.
$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
$ service nagios start

© 2019 IBM Corporation 78


DevOps Training Module

Also configure Nagios to auto start on system boot.


$ sudo systemctl enable nagios

10. Access Nagios Web Interface


Access your nagios setup by access nagios server using hostname or IP
address followed by /nagios.
http://localhost:9090/nagios/
username: nagiosadmin

Note: Use the password set in step 4.

© 2019 IBM Corporation 79


DevOps Training Module

© 2019 IBM Corporation 80


DevOps Training Module

Test your knowledge


1. Which three Nagios variables can affect recursion and inheritance in
Nagios?
A. NAME
B. USE
C. Register
D. All

2. What are the benefits of using Nagios?


A. Plan for infrastructure upgrades before outdated systems
cause failures
B. Automatically fix problems when they are detected
C. None
D. A & B

3. What are ports numbers Nagios will use to Monitor Clients?


A. 5666
B. 5663
C. 5669
D. 5662

4. Nagios Provides monitoring of network services


A. SMTP
B. POP3
C. HTTP
D. ALL

5. What are the prerequisites of Nagios installations?


A. php
B. apache server
C. A & B
D. python

© 2019 IBM Corporation 81


DevOps Training Module

Continuous Monitoring – Graphite & Grafana


Graphite is an open source monitoring tool for storing and viewing time
series data. It does not collect data by itself but has a simple interface and
integrates easily with third-party tools. It is a highly scalable real-time
graphing system. As a user, you write an application that collects numeric
time-series data that you are interested in graphing, and send it
to Graphite's processing backend, carbon, which stores the data in
Graphite's specialized database.
Grafana allows you to connect to a Graphite installation (or other data
source) and build dashboards to view and analyze the data.
In the real world, Graphite is used in combination with Grafana.
Graphite does the data storage, while Grafana does the visualization.

Exercise 13: Graphite & Grafana Installation


In this exercise, you will learn to install Graphite & Grafana.
1. Install Docker (as in Exercise 8)
2. Install Docker Compose
Download the latest version of Docker Compose. Check
the releases page and replace 1.21.2 in the command below with
the version tagged as latest release:

$ sudo curl -L
https://github.com/docker/compose/releases/download/1.21.2/dock
er-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-
compose

Set file permissions:


$ sudo chmod +x /usr/local/bin/docker-compose

3. Docker Compose Configuration

© 2019 IBM Corporation 82


DevOps Training Module

Create a directory:

$ mkdir ~/grafana && cd ~/grafana

Create “docker-compose.yml” and add the following content:

version: "3"
services:
grafana:
image: grafana/grafana
container_name: grafana
restart: always
ports:
- 3000:3000
networks:
- grafana-net
volumes:
- grafana-volume

graphite:
image: graphiteapp/graphite-statsd
container_name: graphite
restart: always
networks:
- grafana-net

networks:
grafana-net:

volumes:
grafana-volume:
external: true

© 2019 IBM Corporation 83


DevOps Training Module

This Compose file uses the official Docker images for both Graphite
and Grafana. It also specifies a network to connect the containers.

Since the data volume is external, you will need to create it


manually:

$ sudo docker volume create --name=grafana-volume

Bring up the configuration:


$ sudo docker-compose up -d

Check that both containers started successfully:


$ docker ps

4. Use the below URL to navigate to Grafana console (use port 3000
which is configurable in docker-compose.yml file)
URL - http://localhost:3000

© 2019 IBM Corporation 84


DevOps Training Module

Default username and password will be admin. Once you login, it


asks for a new password(Ex:Welcome2ibm!)

5. You need to create a data source. Click on Create your first data
source.

© 2019 IBM Corporation 85


DevOps Training Module

Do necessary configuration:
 Name: Graphite
 URL: http://graphite:8080
 Access: Server (Default)
 Version: Select the newest available. 1.1.3 in this example.

Click “Save & Test”.

6. Click “New dashboard” to create and customize a new panel:

© 2019 IBM Corporation 86


DevOps Training Module

To import a sample Dashboard, try the Internal Grafana Stats


- Click “New dashboard” at the top, then “Import dashboard”.
- Type 55 into the Grafana.com Dashboard box and
click “Load”.
- Select Graphite in the data source dropdown and
click “Import”.
- Save the changes made in the dashboard.

7. Graphite does not collect data by itself. To collect the data for
graphite we need to install some third-party utility like collectd.
Install collectd
$ sudo apt-get update
$ sudo apt-get install collectd collectd-utils

Configure Collectd
$ sudo nano /etc/collectd/collectd.conf

Set the hostname of the machine.


Hostname "graph_host"

8. Make sure FQDNLookup value is true in the collectd configuration


file (located at /etc/collectd/collectd.conf), if not, uncomment the
Hostname entry in the same file and provide your machine’s
hostname.

© 2019 IBM Corporation 87


DevOps Training Module

Ensure the following plugins are there:

LoadPlugin apache
LoadPlugin cpu
LoadPlugin df
LoadPlugin entropy
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
LoadPlugin processes
LoadPlugin rrdtool
LoadPlugin users
LoadPlugin write_graphite

9. For the df plugin, which tells us how full our disks are, we can
uncomment the plugin (if present) or add a simple configuration in
“sudo vim /etc/collectd/collectd.conf” file which looks like this:

<Plugin df>
Device "/dev/sda1"
MountPoint "/"
FSType "ext3"
</Plugin>

10. You should point the device to the device name of the drive on
your system. You can find this by typing the command in the
terminal:

$ df

© 2019 IBM Corporation 88


DevOps Training Module

11. Choose the networking interface you wish to monitor and


uncomment or add (if not present) in “sudo vim
/etc/collectd/collectd.conf” file:
<Plugin interface>
Interface "eth0"
IgnoreSelected false
</Plugin>
Finally, we come to the Graphite plugin. This will tell collectd how to
connect to our Graphite instance. Make the section look something
like this:

<Plugin write_graphite>
<Node "example">
Host "172.18.0.3"
Port "2003"
Protocol "tcp"
LogSendErrors true
Prefix "collectd."
StoreRates true
AlwaysAppendDS false
EscapeCharacter "_"
</Node>
</Plugin>

© 2019 IBM Corporation 89


DevOps Training Module

Note: Change the Host address to the Graphite docker


container’s IP address. This tells our daemon how to connect
to Carbon to pass off its data. We specify that it should look
to the local computer on port 2003, which Carbon uses to
listen for TCP connections.

12. Save and close the file when you are finished.
$ sudo service collectd stop
$ sudo service collectd start

© 2019 IBM Corporation 90


DevOps Training Module

13. Open Dashboard

© 2019 IBM Corporation 91


DevOps Training Module

Test your knowledge


1. Grafana is an open source platform for (multiple choice):
A. Data visualization
B. Analysis
C. Version Control
D. Monitoring

2. Supported data sources for Grafana are:


A. Graphite
B. Elasticsearch
C. Prometheus
D. InfluxDB
E. All of the above
3. What is the default port for running Grafana
A. 3000
B. 1433
C. 50000
D. 8080

4. ______ is the basic visualization building block in Grafana


A. Data Source
B. Row
C. Panel
D. Dashboard

© 2019 IBM Corporation 92


DevOps Training Module

Chapter 2: DevOps Usecase


DevOps Use case & Setup
Introduction of a Usecase for CI/CD Pipeline

Let's take an example of a project (Maven Java program) where developer


works and maintain the source code repository like GitHub. They have to
commit each change and pull the code base from Github and perform the
build process (maven build) then generates executable jar. Now, once the
jar is created they can execute and monitor it.

All the steps discussed above are manual and developers have to put lot of
effort in it. But using Jenkins, we can automate the build and deployment
process. Jenkins, an open source Continuous Integration server, helps to
automate software development process, with continuous integration and
continuous delivery. For automating build and deployment process,
developers have to just create a pipeline in Jenkins and configure the
pipeline to perform all the functions. In the Jenkins pipeline, source code
repository can be integrated which can take any new commits, also build
process can be configured which performs maven clean and build actions
and generates the jar and the post build process will execute the program.
So, the full DevOps process can be automated which will ease the efforts of
developers.

For this exercise, we will deploy our calculator java project in Jenkins server
and integrate all tools to the Jenkins project which includes the source code
repository (GitHub), maven for build process which generates executable
jar.

© 2019 IBM Corporation 93


DevOps Training Module

Exercise 1 - Set Up a CI/CD Pipeline from Scratch

1. First step is to add the required plugins for your project. For this click on
“Manage Jenkins” option from the left panel on Jenkins homepage. Now
click on the “Manage Plugins” from the main options. Now under the
“Available” tab search and install “Hudson Post build task” and
“PostBuildScript Plugin” plugins. These are essential for running
executable jar.

2. Now before creating the Jenkins pipeline, we need to install Maven


which we will need in our build process. For this run the below command
in your linux terminal.
$ sudo apt install maven

3. Now we need to push our maven project to git server which we set-up
in Exercise 3. Copy our pom.xml and /src folder to git client and then
we’ll add these files and push the changes to the git server.

© 2019 IBM Corporation 94


DevOps Training Module

4. Now, create a new freestyle project item in Jenkins.

5. Now, configure your pipeline. First, provide description for the Jenkins
pipeline (This step is optional).

© 2019 IBM Corporation 95


DevOps Training Module

6. Next step is to configure git repository to Jenkins pipeline. (Which you


have created, configured and committed your maven project to it).

7. After this, add build configuration which will tell what tasks needs to be
performed during the build process.
Here, click on “Add build step” and select “Execute shell”, in this give
“mvn clean package” command which will clean the maven project and
build the package (executable jar).

© 2019 IBM Corporation 96


DevOps Training Module

8. As Jenkins use the host machine as “jenkins” user, it doesn’t have sudo
access. So, you have to make changes to tell the host machine not to ask
for password for Jenkins user. For this add the below entry (update if
already present) in the sudoers file which can be found at
“/etc/sudoers”.
$ sudo vi /etc/sudoers
Add this entry – Jenkins ALL=(ALL) NOPASSWD: ALL

9. Now, add the Post-build Actions configuration which tell what tasks will
be performed after build process is completed.
For this under “Post-build Actions” click “Add post-build action” and
select “Execute Scripts”. Add post build step and select “Execute shell”
option under Add build step. Take the jar build in the previous step and
copy it into a directory then execute the jar.

sudo cp /var/lib/jenkins/workspace/devops-integration/target/calcProject-
0.2-jar-with-dependencies.jar /home/administrator/Documents/devops/

java -jar "/home/administrator/Documents/devops/calcProject-0.2-jar-with-


dependencies.jar" "2" "5" "1"

© 2019 IBM Corporation 97


DevOps Training Module

10. You have configured the Jenkins pipeline and let’s test it now. For this
go to Jenkins home page and issue build against your pipeline by clicking
the below command.

11. You can see the build running on the left panel.

12. Once the build is run you can see the status on the homepage against the
pipeline. Where Blue is built passed and Red is build failed. You can also
see the build log and status details, for this click on your pipeline from
Jenkins homepage. Here on the left panel you can find all pipeline
related details as well as all the builds.

© 2019 IBM Corporation 98


DevOps Training Module

13. To see the log for your build, click on the build number from “Build
History” and then from the left panel click on “Console Output”.
The Console Output for your build will look like this –

© 2019 IBM Corporation 99


DevOps Training Module

Solving Problems with DevOps


DevOps in Mobile Applications

Adopting DevOps in Mobile App Development can be a game changer for


many organizations. However, it is not that easy as it requires lot of
technical and business decisions. But once implemented successfully, they
can help organizations to achieve client satisfaction, increased efficiency,
and increased revenue.
Before adopting mobile DevOps, all the bottlenecks and potential problems
should be identified first. Some of the challenges are:
Multi-Platform Support
Most of the mobile apps target multiple devices, OS versions, hardware
specifications and more.
App Store and Play Store
A mobile app cannot be deployed directly to a mobile device. It has to go
through App Store for iOS and Google Play Store for Android and it has to go
through a submission and review process.
Pull Deployment Model
Traditional deployments operate on a push model where a new version of
the application can be pushed. But, the process of updating a mobile app is
a pull process as it is up to the user to choose whether they want to update
the app.
Mobile App Testing
Unsatisfied customers can publicly harm the app through the medium of
the App Store or Play Store by giving low ratings. So it becomes extremely
important to do rigorous testing using functional, usability, and
performance testing techniques for the app.

© 2019 IBM Corporation 100


DevOps Training Module

To adopt mobile DevOps, it is important to follow below rules:


Continuous Integration and Continuous Delivery
There are different types of variants of Android & iOS for almost every mobile
brand. Due to this, there must be a separate build for each of the variants
and platforms targeted. As the number of builds increase, developers can
use scripts to generate automated builds.

Testing and Monitoring


Most of the mobile app testing is done on simulators manually and not on
actual physical devices. With a greater number of platforms, manual testing
will be very time consuming. The only possible way is to use automated
testing tools.
Mobile apps follow a rapid development process which results in more
frequent releases. This results in rapid testing and it is very common that the
app performs well in the test environment but fails in the live environment
due to issues like network conditions, memory, power etc. So it is important
to ensure continuous performance monitoring by adding third party SDKs to
the app such as log, crash report, etc. to find the root cause of the failure.

Quality and Delivery


The feedbacks and ratings on App Stores should be closely monitored for
future enhancements and improvements which results in continuously
improving mobile apps.

© 2019 IBM Corporation 101


DevOps Training Module

DevOps in eCommerce

Ecommerce is the core component in most retailers’ multichannel


strategies. Strategy is fine, but the real battleground is in software delivery;
specifically, speed to market. Market trends evolve rapidly with minimal
predictability or upfront warning signals. Growing market competition
means that consumers don’t wait for ecommerce platforms to get it right –
they switch to alternatives better capable of delivering new features as
demands arise. Organizations must be able to respond quickly to the
demands of the consumers. Failing to meet this, challenges their very
existence.

That’s exactly the goal of DevOps i.e. to accelerate software deployment


and decrease time to market. Code is built collaboratively, and in close
proximity to the business, the market and the customer. Organizations are
transforming the way they deploy their solutions and DevOps is driving that
transformation.

© 2019 IBM Corporation 102


DevOps Training Module

DevOps in Internet of Things

The next big step for DevOps is its evolution into the systems or embedded-
devices space where it’s often referred to as Continuous engineering. When
the Internet started, most of the data shared on it was human-generated.
Today, innumerable Internet-connected devices (such as sensors and
actuators) generate much more data than humans do. This network of inter-
connected devices on the Internet is commonly referred to as the Internet
of Things.
In this space, DevOps is potentially even more essential, because of the co-
dependence of the hardware and the embedded software that runs on it.
DevOps principles are reflected in continuous engineering to ensure that
the embedded software delivered to the devices is high-quality software
with the right engineering specifications.

“Operations” in continuous engineering is replaced by hardware or systems


engineers who design and build custom hardware for the devices.
Collaboration between the development and testing teams and the systems
engineers is crucial to ensure that hardware and software are developed
and delivered in a coordinated manner despite hardware and software
development needing to follow different delivery cycles. The development
and testing need for continuous delivery and testing remain the same.
Simulators are used to test software and hardware during development.

© 2019 IBM Corporation 103


DevOps Training Module

DevOps in Data Science & Data Engineering

Artificial Intelligence (AI) and machine learning (ML) technologies extend


the capabilities of software applications that are now found throughout our
daily life: digital assistants, facial recognition, photo captioning, banking
services, and product recommendations. The difficult part about integrating
AI or ML into an application is not the technology, or the math, or the
science or the algorithms. The challenge is getting the model deployed into
a production environment and keeping it operational and supportable.
DevOps automation for ML gives us leverage to increase the delivery rate of
idea from development to production, and encapsulates aspects of data
engineering, software engineering, and data science to provide an end-to-
end view of applying intelligence from data to a business use case.
DevOps automation for ML allows to accelerate the process by which an
idea goes from development to production. It helps to achieve several key
objectives:
 Fastest time to train, with as much data and as accurately as possible
 Fastest time to inference, with ability to rapidly retrain
 Safe and reliable deployments to observe model behavior in the real
world
Another area of automation which is addressed by Machine Learning stack
is experiment tracking and model versioning. Deploying machine learning
systems to production typically requires ability to run many models and
multiple versions of models at the same time.
A typical Machine Learning DevOps pipeline includes:
 Data preparation / ETL
 Model training and testing
 Model evaluation and validation
 Deployment and versioning

© 2019 IBM Corporation 104


DevOps Training Module

 Production and monitoring


 Continuous training / reinforcement learning
DevOps for data engineering is same as software engineering. In both
cases, there are multiple environments where tests are performed, and
functionality is validated before releasing to a production or production-
like environment. And both have the need for greater velocity, faster
response times to feedback, and more accuracy in what is delivered to
users.

© 2019 IBM Corporation 105


DevOps Training Module

Test Your Knowledge

1) Which of this is not a DevOps tool-

A. Maven
B. Jenkins
C. Automation Anywhere
D. Puppet
E. Docker

2) Ansible an open-source tool.


A. TRUE
B. FALSE

3) __________ is an open-source container management tool which holds


the responsibilities of container deployment, scaling and descaling of
containers, and load balancing
A. Grafana
B. Nagios
C. Kubernetes
D. Docker

© 2019 IBM Corporation 106


DevOps Training Module

Chapter 3: Advanced DevOps


Introduction to advanced DevOps Concepts
Let’s see below some of the advanced DevOps Concepts.

Automatic Rollback

Continuous delivery is becoming a norm. If right process is implemented,


you get a predictable deployment. Whenever a code is changed, mostly the
build, test, deploy and monitor steps are followed. This is the base for
automation of release process.

When there is a failure during the monitoring phase, then someone has to
verify and rollback the failed release to the previously successful one. This
is time consuming process which requires someone to watch the
monitoring dashboard and react to it.

If the team follows DevOps way of working, then there will be an alert raised
when something goes wrong. But still, even after receiving the alert,
someone has to look at the issue if it is coming from the last release and
decide whether or not there is a need to roll back. So, there is a significant
amount of time wasted during the process, just because a release failed,
and nobody kept an eye on it. What if this process could be automated?

There are DevOps tools available that monitor the dashboard and if
something goes wrong, they initiate automatic rollback of current release
to the previously working release. Also, if there are new features rolled out,
there should be a tested rollback plan for every feature so if something goes
wrong, that feature can be turned off automatically.

© 2019 IBM Corporation 107


DevOps Training Module

Automatic Provisioning

Environment provisioning is a key part of Continuous Delivery. The idea is,


along with building, testing and deploying application code, we should also
provision the underlying application environment. That is, environments
should be provisioned automatically on demand and only for the duration
needed. Scripting & automation tools enable automated provisioning and
this enhanced capability allows for automated scaling during peak demand.
To deliver the DevOps promise of automated provisioning, below are
essential:
 Cloud Computing
 Monitoring tools
 Deployment tools

© 2019 IBM Corporation 108


DevOps Training Module

Exercise 1 - Automatic Rollback


While running the Maven project, if your build fails then Jenkins provide
features to rollback to previous successful build. Let’s see how to do this.
1. Install a plugin “Version Number Plugin”. This can be installed by
clicking “Manage Jenkins” from Jenkins homepage and then selecting
“Manage Plugins” option. After this, under “Available” tag search for
“Version number plugin” and install it.
2. Let’s change our code to make the build fail, so that we rollback to
previous successful build. Open your Git repository and change a test
case (CalcTest.java). Now commit the changes.
3. After this open your Jenkins pipeline from homepage and then click on
“Configure” option from left panel.
4. Replace the below commands under build configuration (Execute
shell)-
mvn clean
mvn versions:set -DnewVersion=0.2.$BUILD_NUMBER
mvn install
5. Now replace the below steps under Execute scripts/Execute shell
under Post-build Actions.
sudo cp /var/lib/jenkins/workspace/devops-
integration/target/calcProject-0.2.$BUILD_NUMBER-jar-with-
dependencies.jar /home/administrator/Documents/devops/

java -jar "/home/administrator/Documents/devops/calcProject-


0.2.$BUILD_NUMBER-jar-with-dependencies.jar" "2" "5" "1"
6. For the rollback, add another “post build task” under Post-build Actions
and add the below configurations.
java -jar "/home/administrator/Documents/devops/calcProject-
0.2.34.jar-with-dependencies.jar" "2" "5" "1"

© 2019 IBM Corporation 109


DevOps Training Module

7. Now save the configuration and run the build. After the build is
completed, check the logs and you will find the build failed but then
it rolled back to previous build and executed the jar.

This is how we can use the rollback feature in Jenkins.

© 2019 IBM Corporation 110


DevOps Training Module

Infrastructure as Code (IaC) - a key DevOps practice

Infrastructure as Code is a key DevOps practice and is used in conjunction


with Continuous delivery. It is an approach to managing infrastructure
(networks, virtual machines, load balancers, and connection topology
etc) that reduces costs, speeds delivery, and reduces risk. As the same
source code generates the same binary, an IaC model generates the same
environment every time it is applied. With IaC, resources and services are
created and managed programmatically through APIs rather than via a
portal or command line.

IaC dispenses with the traditional manual processes used by IT ops teams.
This is not simply writing ad-hoc scripts; you write code to provision and
manage the lifecycle of your cloud from creation to tearing down. IAC
describes the full infrastructure and its topology to host an application. It
encompasses every step required to take a blank sheet to the full stack
needed to run applications. It also defines how to tear it down again. These
IAC patterns become reusable building blocks for complex infrastructures.

This code example illustrates the simplicity of IAC. It defines a reusable


code block of three web-servers with security groups, a load balancer, and
TLS certificate
resource “ibm_compute_vm_instance” “web-system-test” {

count = 2
os_reference_code = “CENTOS_7_64″
count = 3
datacenter = LON05”
flavor = B1_1X2X25
private_security_group_ids = [“${ibm_security_group.sg_private_lamp.id}”]
public_security_group_ids = [“${ibm_security_group.sg_public_lamp.id}”]
}

resource “ibm_lbaas” “lb-web-system-test” {

name = “${var.lb_name}
protocols = [{
frontend_protocol = “HTTPS”
frontend_port = 443
backend_protocol = “HTTP”

© 2019 IBM Corporation 111


DevOps Training Module

backend_port = 80
}
tls_certificate_id = “${ibm_compute_ssl_certificate.lb-web-cert.id}”
}]

Treating infrastructure as code has many benefits. Handling it the same way
that developers treat code and applying DevOps techniques brings mature
practices that improve quality and reduce risk. Existing best practices of
version control, testing, small deployments, and design patterns apply
equally to cloud infrastructure. IAC is also a key enabler of DevOps as dev
and test environments can be created and torn down as needed.

© 2019 IBM Corporation 112


DevOps Training Module

Scalability

When everything is going smoothly, DevOps can be awesome i.e.


 Teams work together seamlessly
 Tasks are automated
 Continuous delivery is continuously integrated, continuously tested,
continuously deployed and continuously monitored
All is well unless the DevOps needs begin exceeding the capacity of tools
used. So, scalability is crucial for DevOps success.
As per Wikipedia,
Scalability is the property of a system to handle a growing amount of work
by adding resources to the system

Scalability is one of the primary reasons that DevOps and Cloud computing
are so integrally linked. There are many factors that could impact scalability
which may potentially impact DevOps success. Here are few things to
remember to ensure the environment is ready to scale:

Ensure tools and apps are scalable


There is more to scalability than just server and network capacity. It is
important to ensure that the tools used can seamlessly scale with the
infrastructure, and also the apps delivered through DevOps environment
are designed to take full advantage of the increased capacity as well.

Continuous optimization
Some tools and apps will run properly as the underlying infrastructure
scales up or down but may not run optimally. Ensure that the tools and apps
used can continuously adjust to changes in server, bandwidth and storage
capacity. They should always be able to take full advantage of the resources
available to ensure the best performance possible.

© 2019 IBM Corporation 113


DevOps Training Module

Storage
Most apps will have a data component which means there will be data
storage that must be scaled as well

Cost
It may be easy to automate scalability on cloud platforms but it’s not free.
And the DevOps tools used may include licensing fees that could be
impacted when the usage also scales.

© 2019 IBM Corporation 114


DevOps Training Module

Clustering

Container is an essential technology in any DevOps stack. When there are


large number of containers, then Cluster Management tools are much
needed without which it would be virtually impossible to manage the entire
cluster server, quickly resolve failures, and to pair containers with
resources.

A cluster is a group of servers that communicate with each other. These


clusters work together to achieve more availability, reliability, and
scalability.

The cluster manager is important because it includes many features, from


scheduling and running applications containers to providing the tools
necessary to build a container-centric development environment. Some of
the popular cluster manager tools are Kubernetes, Mesos, Mesosphere,
Nomad etc.

© 2019 IBM Corporation 115


DevOps Training Module

Chapter 4: Introduction to DevOps on IBM Cloud


Introduction to Cloud
Why Cloud?

Cloud is a term that refers to a global network of servers which are hooked
together to operate as a single ecosystem. These servers can store/manage
data, run software’s, deliver service like web mail, streaming videos etc.
Instead of accessing the files or software’s from your local computer, you
are accessing them online from any device that can connect to internet.
Some of the reasons why businesses move to cloud are:
1. Reduced cost
2. Flexibility – work from anywhere
3. Scalability – add additional storage or features whenever needed
4. No need for any backup plan
5. It is difficult to breach security measures on cloud platforms

Introduction to IBM Cloud

IBM Cloud is a suite of cloud computing services from IBM that combines
platform as a service (PaaS) with infrastructure as a service (IaaS) to
provide an integrated experience. The platform scales and supports both
small development teams and organizations, and large enterprise
businesses. Globally deployed across data centers around the world, the
solution you build on IBM Cloud™ spins up fast and performs reliably in a
tested and supported environment you can trust.

IBM Cloud platform is composed of multiple components that work


together to provide a consistent and dependable cloud experience.

 A robust console that serves as the front end for creating, viewing,
managing your cloud resources

© 2019 IBM Corporation 116


DevOps Training Module

 An identity and access management component that securely


authenticates users for both platform services and controls access to
resources consistently across IBM Cloud
 A catalog that consists of hundreds of IBM Cloud offerings
 A search and tagging mechanism for filtering and identifying your
resources
 An account and billing management system that provides exact usage
for pricing plans and secure credit card fraud protection

Whether you have existing code that you want to modernize and bring to
the cloud or you're developing a brand-new application, you can tap into the
rapidly growing ecosystem of available services and runtime frameworks in
IBM Cloud.
For more details, refer to
https://cloud.ibm.com/docs/overview?topic=overview-whatis-platform

© 2019 IBM Corporation 117


DevOps Training Module

DevOps on IBM Cloud


Why DevOps on Cloud?

The powerful combination of DevOps and Cloud computing propels


organizational growth at a rapid speed. Some of the today’s industry trends
given below have helped bring about the collaboration of these two
catalysts.

1. Industries are transitioning from a product-based economy to a


service-based economy
2. The 21st century business environment demands that companies
focus on agility & innovation rather than stability and efficiency

Most organizations today are beginning to realize the potential of these


business transformation agents. While DevOps is a more process-oriented
concept, the cloud acts as a catalyst to pace up this process.
DevOps and cloud are both catalysts and enablers for each other. As
organizations adopt cloud, the value proposition of leveraging cloud for
hosting a DevOps workload becomes self-evident. The flexibility, resilience,
agility, and the services a cloud platform brings allow for streamlining an
application delivery pipeline hosted on the cloud. Environments from
development through testing and all the way to production can be
provisioned and configured as needed and when needed. This process
minimizes the environment-related bottlenecks in the delivery process.
Organizations are also looking to leverage cloud platforms for either
reducing the cost of development and test environments or to provide a
modern streamlined developer experience for their practitioners. These
make for an extremely compelling business case for cloud adoption with
and for DevOps.

© 2019 IBM Corporation 118


DevOps Training Module

IBM Cloud DevOps Services

Toolchains
With the IBM Cloud DevOps service, you can create Continuous
Development and Continuous Integration toolchains to go from source code
to a running application in minutes. Toolchains allow you to develop, track,
plan and deploy applications in one place, you can access everything you
need to build all types of applications.
A DevOps toolchain is a set of tools that automates the tasks of developing
and deploying your app. You can perform DevOps manually with simple
apps, but the need for automation increases quickly as app complexity
increases, and toolchain automation is a must-have for continuous delivery.
The core component of a DevOps toolchain is a version control repository
like GitHub. More tools might include backlog tracking, delivery pipelines,
an integrated development environment (IDE), and monitoring like IBM®
Cloud DevOps Insights.
When you create an app by using a starter kit, and then click Configure
continuous delivery on the App details page, a DevOps toolchain is created.
The toolchain has a code repository, delivery pipeline, and web IDE. You
can then build on this toolchain to collaboratively manage and deploy your
app to separate environments for development, test, and production.
DevOps Insights
It is a cloud-based solution that provides comprehensive insights from
popular continuous integration and continuous delivery tools to increase
the speed, quality and control of your applications.
Features:
Deployment risk is like a continuous delivery safety net. It analyzes the
results from unit tests, functional tests, application scans and code

© 2019 IBM Corporation 119


DevOps Training Module

coverage tools at specified gates in your deployment process and prevents


risky changes from being released.
Team dynamics uses social coding analysis to help you learn how your team
collaborates and understand how it can work better.
Developer insights provides a comprehensive way to explore your project’s
development maturity. You can identify files with high error proneness and
get a compliance view of the project against developer practices.
Refer to https://www.ibm.com/in-en/cloud/devops-insights for more
details.

© 2019 IBM Corporation 120


DevOps Training Module

Exercise 1 - DevOps using IBM Cloud


1) Sign in to -> https://cloud.ibm.com/
The Dashboard will open where you will be creating your first simple
DevOps application.

2) Open the left Navigation bar and go to DevOps category

© 2019 IBM Corporation 121


DevOps Training Module

3) Ensure the LOCATION is “Tokyo” and click on Create Toolchain


Button

4) Click on Develop and test a Cloud Foundry app option

© 2019 IBM Corporation 122


DevOps Training Module

5) Page will open to you to configure the default options.

Under GitHub, click on Authorize button and login into your GitHub
account. Once it is authorized, in the pipeline option you will need to
create an API key.

© 2019 IBM Corporation 123


DevOps Training Module

6) Click on Create Button


7) After creating the API key will be automatically assigned to you in the
place and select London as your Staging stage and Production stage.

8) The configuration is completed now. Click on Eclipse Orion Web IDE.

© 2019 IBM Corporation 124


DevOps Training Module

9) This will show up files which are the GitHub files which are set default
in the initial configuration time.
10) Open the main.ejs file which consist of default code.

11) Paste the code below to modify the existing code

<!DOCTYPE html>

© 2019 IBM Corporation 125


DevOps Training Module

<html lang="en-us">
<head>
<title>Welcome to Devops Learning!!</title>
<link rel="stylesheet" href="/built/css/default.css" />

<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/angular-route/angular-
route.js"></script>
<script src="/js/controllers.js"></script>
<style>
img {
display: block;
margin-left: auto;
margin-right: auto;
padding-top: 10%;

}
marquee {
text-align:center;
}
</style>
</head>

<body>
<center>
<img src= "https://encrypted-
tbn0.gstatic.com/images?q=tbn:ANd9GcSE65xZ9tUWsRzustJpOZ1rWiA
-veUSfL9mNNZG7-Y6Rqb2j5nz" alt="ibm_logo"width="200"
height="150" >
<br>
</center>

© 2019 IBM Corporation 126


DevOps Training Module

<marquee direction="up" behavior="slide"


style="height:100px"><font size="150px"> WELCOME TO DEVOPS
LEARNING </marquee>

</body>
<script>
angular.element(document).ready(function() {
angular.bootstrap(document, ['ConsoleModule']);
});
</script>

</html>

12) Once the script is ready click on git icon

© 2019 IBM Corporation 127


DevOps Training Module

Commit

After commit, click on push

13) Commit the changes with a proper message. Once the changes are
committed, on the right-hand side click the button Push with the
respective outgoing changes

14) Go back to Edit screen and click on the deploy button

Deploy

15) The project will start deploying now


16) Once the project is up and ready, click on “Open the Deployed App”
Button

© 2019 IBM Corporation 128


DevOps Training Module

17) The project will be up and running and you can modify it to your wish
in the Eclipse IDE and commit in Git
18) If any changes are committed, it will build and deploy by itself in
Delivery Pipeline, and you can see those changes

© 2019 IBM Corporation 129


DevOps Training Module

Congrats! You made your first DevOps application.

© 2019 IBM Corporation 130


DevOps Training Module

Test your knowledge


1) IBM Bluemix is a
A. Platform as a service
B. Software as a service
C. Infrastructure as a service
D. A & B

2) IBM Cloud is also called


A. Watson
B. Bluemix
C. SoftLayer
D. Software stack

3) Which resources are typically provided by an Infrastructure as a Service


cloud computing delivery model?
A. applications
B. virtual machines
C. virtual private networks
D. middleware software stacks

4) An enterprise needs highly controlled storage and access to their


databases as well as managing the infrastructure for web front ends
and other applications. They have a large existing IT infrastructure and
they are continually expanding the capabilities. Which cloud computing
model will satisfy all their current needs and enable them to reduce
cost?
A. public cloud
B. hybrid cloud
C. private cloud
D. internal cloud

© 2019 IBM Corporation 131


DevOps Training Module

Answer Keys
Chapter Name Question Number -Answer Keys
Introduction to DevOps 1-D; 2-B; 3-C; 4-C; 5-D
DevOps Tools - Git 1-C; 2-D; 3-A;4-B; 5-C
DevOps Tools - Maven 1-A; 2-A; 3-D;4-B; 5-D
DevOps Tools - Puppet 1-A; 2-A; 3-C;4-A; 5-A
DevOps Tools - Docker 1-B; 2-C; 3-C;4-D; 5-D
DevOps Tools - Jenkins 1-B; 2-A; 3-D
DevOps Tools - JUnit 1-C; 2-A; 3-D;4-C; 5-D
DevOps Tools - Nagios 1-D; 2-D; 3-A;4-D; 5-C
DevOps Tools – Graphite & Grafana 1-A,B,D; 2-E; 3-A;4-C
DevOps Usecase & Setup 1-C; 2-A; 3-C
DevOps on IBM Cloud 1-A; 2-B; 3-B;4-B; 5-B

© 2019 IBM Corporation 132


DevOps Training Module

NOTICES
This material is meant for IBM Academic Initiative use only. NOT FOR RESALE.

TRADEMARKS

IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of the
International Business machines Corp., registered in many jurisdictions worldwide.
Other product and service names might be trademarks of IBM or other companies. A
current list of IBM trademarks in available on the web at “Copyright and trademark
information” at www.ibm.com/legal/copytrade.html.

Adobe, and the Adobe logo are either registered trademarks or trademarks of Adobe
Systems Incorporated in the United States, and/or other countries.

Microsoft, Windows and the Windows logo are trademarks of Microsoft Corporation in
the United States, other countries or both.

© Copyright International Business Machines Corporation 2019.

This document may not be reproduced in whole or in part without prior permission of
IBM.

US Government Users Restricted Rights – Use, duplication, or disclosure restricted by


GSA ADP Schedule Contract with IBM Corp.

© 2019 IBM Corporation 133

You might also like