DevOps and Microservices
Cristian Klein
Agenda
• Mo*va*on
• DevOps: Defini*on, Concepts
• Star as Code
• DevOps: Caveats
• Microservices
2017-05-11 DevOps and Microservices 2
Why DevOps from 50,000 feat
2017-05-11 DevOps and Microservices 3
Google Search Example
• Business Hypothesis:
– “Users want 30 results instead of 10”
• Build (A/B tes*ng):
– Users A served 30 results
– Users B served 10 results
– Measure amount spent on Google Search
• Measure:
– Users A spent less 3me on Google Search.
• Learn:
– Displaying 30 results takes longer than 10 results
– Display only 10 results OR make 30 results faster
2017-05-11 DevOps and Microservices 4
Some Ideas of Lean Startup
• Faster learning => more compe33ve
• Discover requirements
– Instead of deba*ng them
2017-05-11 DevOps and Microservices 5
2017-05-11 DevOps and Microservices 6
2017-05-11 DevOps and Microservices 7
Misalignment of Incen*ves
2017-05-11 DevOps and Microservices 8
Wall of Confusion
2017-05-11 DevOps and Microservices 9
2017-05-11 DevOps and Microservices 10
Agenda
• Mo*va*on
• DevOps: Defini3on, Concepts
• Star as Code
• DevOps: Caveats
• Microservices
2017-05-11 DevOps and Microservices 11
DevOps: Defini*on
• "DevOps" is an emerging set of principles,
methods and prac1ces for communica3on,
collabora3on and integra3on between
so@ware development (applica*on/soZware
engineering) and IT opera3ons (systems
administra*on/infrastructure) professionals.
2017-05-11 DevOps and Microservices 12
DevOps “Pipeline”
2017-05-11 DevOps and Microservices 13
DevOps (cont.)
• Acknowledges the interdependence of
soZware development and IT opera*ons
• Aims to help organiza*ons rapidly produce
quality soZware products and services
• Responds to the demands of stakeholders for
an increased rate of produc*on releases
• Supports the use of agile development
processes
• Aligns Dev and Ops incen*ves
2017-05-11 DevOps and Microservices 14
Down*me Budget Example
• Google’s Site Reliability Engineers:
– “SRE is what happens when you ask a soZware engineer to
design an opera3ons team.”
• “A is allowed to be down 15 minutes in a month.”
• Down*me budget spend => no more new features
• Devs are incen*vized to:
– invest more in tes3ng, resilience, automa3on, ...
• Ops:
– get paged less o@en …
– … only for truly new issues
2017-05-11 DevOps and Microservices 15
State of DevOps Report
• Annual report by Puppet
• Survey from 2016
• Companies that uses DevOps
vs they who don’t.
Lead 1me - 1me between commit and produc1on
16
2017-05-11 DevOps and Microservices 17
Apart from that?
Worker 2.2 *mes more likely to recommend
their organiza*on to a friend as a good
workplace
18
Agenda
• Mo*va*on
• DevOps: Defini*on, Concepts
• Star as Code
• Micro-services
2017-05-11 DevOps and Microservices 19
Star as Code
• Pipeline as Code
• Infrastructure as Code
• Configura3on as Code
20
Lessons Learned from
597 outages 2009-2015
Gunawi, Haryadi S., et al. "Why Does the Cloud
2017-05-11 Stop and
DevOps Computing? Lessons from Hundreds of Service Outages.”
Microservices 21
Proceedings of the Seventh ACM Symposium on Cloud Computing. ACM, 2016.
Mo*va*on
Many DevOps tasks are: Such as:
• Dull • Server cra@ing
• Error-prone • SoZware configura3on
• Stressful • Deploying code
• Time-consuming
• Solu*on: Automate!
2017-05-11 DevOps and Microservices 22
Why “as code”?
• Code is:
– human readable
– machine executable
• Can be:
– versioned
– audited
– commented
– tested
– scaled (configure 10,000 servers)
2017-05-11 DevOps and Microservices 23
Playbooks instead of Tribal Knowledge
2017-05-11 DevOps and Microservices 24
Approaches to “as code”
• Impera*ve (how?)
– Copy this file
– Install this package
• Declara*ve (what?)
– Ensure this file is up-to-date
– Ensure this package is installed and up-to-date
• Most tools offer both
2017-05-11 DevOps and Microservices 25
Pipeline as Code: Jenkins
stage('Checkout'){ stage('Deploy'){
checkout scm echo 'Push to Repo'
} sh './dockerPushToRepo.sh'
stage('Test'){ sh 'ssh deploy@xxxxx.com dockerRun.sh’
env.NODE_ENV = "test” }
sh 'node -v' stage('Cleanup'){
sh 'npm prune' sh 'npm prune'
sh 'npm install’ sh 'rm node_modules -rf'
sh 'npm test’
} mail body: 'project build successful',
from: 'xxxx@yyyyy.com',
stage('Build Docker'){ replyTo: 'xxxx@yyyy.com',
sh './dockerBuild.sh’ subject: ‘build successful’
} to: 'yyyyy@yyyy.com’
}
2017-05-11 DevOps and Microservices 26
Pipeline as Code: Travis
sudo: required
language: ruby
services:
- docker
before_install:
- docker pull carlad/sinatra
- docker run -d -p 127.0.0.1:80:4567
carlad/sinatra /bin/sh -c "cd /root/sinatra; bundle exec foreman start;"
- docker ps -a
- docker run carlad/sinatra
/bin/sh -c "cd /root/sinatra; bundle exec rake test"
script:
- bundle exec rake test
2017-05-11 DevOps and Microservices 27
Configura*on Management as Code
• Describe systems once
• Predictable results
• Handle differences in environments
– Dev vs. staging vs. produc*on
• No Snowflakes!
• Server configura*on *me
– Seconds
2017-05-11 DevOps and Microservices 28
Infrastructure as Code:
Pets vs. Cakle
2017-05-11 DevOps and Microservices 29
IaC and CMaC Tools
• Declara*ve configura*on language
• Plain-text configura*on in source control
• Fully programma*c, no manual interac*ons
30
2017-05-11 DevOps and Microservices 30
Puppet overview
1. Describe what you want to be configured
2. (Don‘t care how it is done)
3. Describe dependencies
file package service types
win *nix deb rpm POSIX win providers
Puppet DSL
2017-05-11 DevOps and Microservices 31
Puppet example:
Apache server
Puppet Example | Apache HTTP Server
package { "httpd":
Manifests name => "httpd.x86_64",
ensure => "present",
Resources }
● Name file { "http.conf":
path => "/etc/httpd/conf/httpd.conf",
● Attributes and owner => root,
values group => root,
mode => 0644,
Ordering and source => "puppet:///modules/apache/httpd.conf",
require => Package["httpd"],
dependencies }
service { "httpd":
ensure => running,
enable => true,
subscribe => File["http.conf"],
}
10 | 28
10
2017-05-11 DevOps and Microservices 32
Puppet building blocks
More on Puppet | building blocks
if $operatingsystem == 'CentOS'
Manifests node 'www1.example.com' {
Variables and (custom) facts include common
include apache
Node declarations }
node 'db1.example.com' {
Classes and Modules include common
include mysql
Defined resource types }
Templates
file { "http.conf":
Console path => "/etc/httpd/conf/httpd.conf",
owner => 'root',
group => 'root',
mode => '0644',
content => template('config/httpd.erb'),
}
11 | 28
10
2017-05-11 DevOps and Microservices 33
A Puppet run
1. Retrieve plugins from server
2. Get “facts“ on client and send them
to master
3. Compile catalog and send it to the
client
4. Apply catalog on client
5. Process report
2017-05-11 DevOps and Microservices 34
Challenge: Idempotence
Applying the same playbook twice MUST give
the same results
Hummer, Waldemar, et al. "Testing idempotence for infrastructure as code.”
Distributed Systems Platforms and Open Distributed Processing. 2013.
2017-05-11 DevOps and Microservices 35
DevOps: Dangers
• “To err is human, but to err and deploy it to all systems
simultaneously is DevOps”
– A. CockcroZ, prev. Neolix Architect
• 2014 Gmail outage:
– "The incorrect configura*on was sent to live services over
the next 15 minutes, caused users’ requests for their data
to be ignored, and those services, in turn, generated
errors.”
• 2016 Amazon WS S3 outage:
– “Unfortunately, one of the inputs to the command was
entered incorrectly and a larger set of servers was
removed than intended.”
• Don’t roll out system-wide un*l it works…
2017-05-11 DevOps and Microservices 36
2017-05-11 DevOps and Microservices 37
Con*nuous Monitoring
2017-05-11 DevOps and Microservices 38
Agenda
• Mo*va*on
• DevOps: Defini*on, Concepts
• Star as Code
• Microservices
2017-05-11 DevOps and Microservices 39
Microservices
• (One) Defini*on: “Loosely coupled service
oriented architectures with bounded contexts”
– Loosely coupled: asynchronous service updates
– Bounded context: Limited knowledge of surrounding
services
2017-05-11 DevOps and Microservices 40
Microservices: More about coupling
• Organiza3onal coupling
• Centralized database schemes
• Enterprise service bus – centralized messaging
2017-05-11 DevOps and Microservices 41
Microservices: Conway’s Law
• Conway’s law (1967):
– “Any organiza*on that designs a system (defined broadly) will produce a
design whose structure is a copy of the organiza*on’s communica*on
structure”
2017-05-11 DevOps and Microservices 42
Microservices: Avoiding Organiza*onal Coupling
2017-05-11 DevOps and Microservices 43
Microservices: Data Coupling
2017-05-11 DevOps and Microservices 44
Microservices: Proper*es
• Polyglot
– Mul*ple languages, plaoorms, etc.
• Immutable code pakern
– Keep old code / exis*ng service
– Deploy new version
– Eventually, re-route traffic
• A/B tests, feature flags, version rou*ng
– Canary tes*ng
– Try out new features with developers and testers only
– Add a few real users, measure improvements
– Make default for all users, but keep old version
2017-05-11 DevOps and Microservices 45
Microservices: Benefits
• Small, easy to understand code base
• Easy to scale (next slide)
• Easy to throw away
• Easy to deploy
• Easy to use different tools (polyglot)
• Resilient systems
2017-05-11 DevOps and Microservices 46
Microservices: Scaling
2017-05-11 DevOps and Microservices 47
Microservices: Drawbacks
• Higher communica*on overhead
– Nanoservices an*-pakern
• Integra3on tes*ng more complicated
• Moving responsibility more difficult
– Needs communica*on between different teams
2017-05-11 DevOps and Microservices 48
Conclusions
• Need to deploy code rapidly and reliably
• DevOps bridges the gap between development and
opera*ons
• Automa3on key to success
– Many tools/services out there to help
• Microservices: preferred architecture for DevOps
• Hot research area!
– Make beker use of opera3ons feedback during development
2017-05-11 DevOps and Microservices 49