operations: a developer's guide

185
Operations: a developer’s guide Anna Shipman @annashipman

Upload: annashipman

Post on 13-Feb-2017

3.559 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Operations: a developer's guide

Operations: a developer’s guideAnna Shipman @annashipman

Page 2: Operations: a developer's guide

@annashipman

Technical architect at the Government Digital Service

Page 3: Operations: a developer's guide

@annashipman

My background

Page 4: Operations: a developer's guide

@annashipman

Previous career in publishing

Page 5: Operations: a developer's guide

@annashipman

Self taught programmer: HTML, CSS, terrible JS

Page 6: Operations: a developer's guide

@annashipman

First employed gig, 2005: backend, Java

Page 7: Operations: a developer's guide

@annashipman

First job at GDS, 2012: redirecting URLs

Page 8: Operations: a developer's guide

@annashipman

Page 9: Operations: a developer's guide

@annashipman

Wrote perl to generate nginx config

Page 10: Operations: a developer's guide

@annashipman

Didn’t understand the emails from the infrastructure team

Page 11: Operations: a developer's guide

@annashipman

So joined the infrastructure team

Page 12: Operations: a developer's guide

@annashipman

Which led to where I am now…

Page 13: Operations: a developer's guide

@annashipman

Technical architect on a large infrastructure project

Page 14: Operations: a developer's guide

@annashipman

What I learned has made me a better developer

Page 15: Operations: a developer's guide

@annashipman

Knowing these things might help you

Page 16: Operations: a developer's guide

@annashipman

Wrangling servers Virtualisation Containerisation Some tools to make you a better developer

Page 17: Operations: a developer's guide

@annashipman

Each section will have a take-home

Page 18: Operations: a developer's guide

@annashipman

1. Wrangling servers

Page 19: Operations: a developer's guide

@annashipman

How the internet works

Wrangling servers

Page 20: Operations: a developer's guide

@annashipman

“It’s a series of tubes”—Sen. Ted Stevens

Wrangling servers

Page 21: Operations: a developer's guide
Page 22: Operations: a developer's guide

@annashipman

Servers

Wrangling servers

Page 23: Operations: a developer's guide

@annashipman

Where are your servers?

Wrangling servers

Page 24: Operations: a developer's guide

@annashipman

Where are your servers?You own them (e.g. in the office)

Wrangling servers

Page 25: Operations: a developer's guide

@annashipman

Where are your servers?You own them (e.g. in the office) Shared hosting (e.g. Dreamhost)

Wrangling servers

Page 26: Operations: a developer's guide

@annashipman

Where are your servers?You own them (e.g. in the office) Shared hosting (e.g. Dreamhost) The cloud (e.g. AWS)

Wrangling servers

Page 27: Operations: a developer's guide

@annashipman

Where are your servers?You own them (e.g. in the office) Shared hosting (e.g. Dreamhost) The cloud (e.g. AWS) PaaS/application hosting (e.g. Heroku)

Wrangling servers

Page 28: Operations: a developer's guide

@annashipman

Where are your servers?You own them (e.g. in the office) Shared hosting (e.g. Dreamhost) The cloud (e.g. AWS) PaaS/application hosting (e.g. Heroku) Something else/don’t know

Wrangling servers

Page 29: Operations: a developer's guide

@annashipman

You need to make sure the server has the software you need

Wrangling servers

Page 30: Operations: a developer's guide

@annashipman

Handcrafting servers

Wrangling servers

Page 31: Operations: a developer's guide

@annashipman

But what happens if your server dies?

Wrangling servers

Page 32: Operations: a developer's guide

@annashipman

It’s also easy to make a mistake

Wrangling servers

Page 33: Operations: a developer's guide

@annashipman

Configuration management

Wrangling servers

Page 34: Operations: a developer's guide

@annashipman

Tools that use configuration you’ve written to build servers

Wrangling servers

Page 35: Operations: a developer's guide

https://www.getfilecloud.com/blog/2014/08/top-8-configuration-management-tools-for-sys-admins/

Page 36: Operations: a developer's guide

@annashipman

GOV.UK uses Puppet, my current project uses Ansible

Wrangling servers

Page 37: Operations: a developer's guide

@annashipman

Config management tools automate building your servers

Wrangling servers

Page 38: Operations: a developer's guide

@annashipman

So it is reliable and repeatable

Wrangling servers

Page 39: Operations: a developer's guide

@annashipman

Some getting started guides at the end

Wrangling servers

Page 40: Operations: a developer's guide

@annashipman

If nothing else, just write a script

Wrangling servers

Page 41: Operations: a developer's guide

@annashipman

“Cattle not pets”

Wrangling servers

Page 42: Operations: a developer's guide

@annashipman

You should not be afraid to lose your servers

Wrangling servers

Page 43: Operations: a developer's guide

@annashipman

2. Virtualisation

Page 44: Operations: a developer's guide

@annashipman

Creating logical computing resources from available physical resources

Virtualisation

Page 45: Operations: a developer's guide

@annashipman

Virtual machines

Virtualisation

Page 46: Operations: a developer's guide

@annashipman

What’s a hypervisor?

Virtualisation

Page 47: Operations: a developer's guide

@annashipman

Hypervisor is the software that runs the VMs

Virtualisation

Page 48: Operations: a developer's guide

@annashipman

Page 49: Operations: a developer's guide

@annashipman

Slight digression into cloud computing

Virtualisation

Page 50: Operations: a developer's guide

@annashipman

“Someone else’s computers”

Virtualisation

Page 51: Operations: a developer's guide

@annashipman

Your servers are in a data centre

Virtualisation

Page 52: Operations: a developer's guide
Page 53: Operations: a developer's guide

@annashipman

A layer of abstraction that pools the resources

Virtualisation

Page 54: Operations: a developer's guide

@annashipman

Page 55: Operations: a developer's guide

@annashipman

Some advantages of cloud computing

Virtualisation

Page 56: Operations: a developer's guide

@annashipman

Some advantages of cloud computingIncreased uptime & disaster recovery

Virtualisation

Page 57: Operations: a developer's guide

@annashipman

Some advantages of cloud computingIncreased uptime & disaster recovery Can get a VM straight away

Virtualisation

Page 58: Operations: a developer's guide

@annashipman

Some advantages of cloud computingIncreased uptime & disaster recovery Can get a VM straight away Charged for what you use

Virtualisation

Page 59: Operations: a developer's guide

@annashipman

That’s the cloud – now your computer

Virtualisation

Page 60: Operations: a developer's guide

@annashipman

How is virtualisation useful to you?

Virtualisation

Page 61: Operations: a developer's guide

@annashipman

Used to be software = slow, resource-intensive

Virtualisation

Page 62: Operations: a developer's guide

@annashipman

From 2005 Intel & AMD started doing hardware-accelerated virtualisation

Virtualisation

Page 63: Operations: a developer's guide

@annashipman

So can run lots of VMs on your computer

Virtualisation

Page 64: Operations: a developer's guide
Page 65: Operations: a developer's guide

@annashipman

Vagrant is a lightweight way to create VMs

Virtualisation

Page 66: Operations: a developer's guide

@annashipman

Vagrant.configure(2) do |config| config.vm.box = "puppetlabs/centos-7.0-64-puppet" config.vm.provider :virtualbox |vb| vb.customize ["modifyvm", :id, "--memory", "2048"] end end

Virtualisation

Page 67: Operations: a developer's guide

@annashipman

Vagrant.configure(2) do |config| config.vm.box = "ubuntu/trusty64" end

Virtualisation

Page 68: Operations: a developer's guide

@annashipman

$ vagrant up

Virtualisation

Page 69: Operations: a developer's guide

@annashipman

$ vagrant ssh

Virtualisation

Page 70: Operations: a developer's guide

@annashipman

$ cd /vagrant

Virtualisation

Page 71: Operations: a developer's guide

@annashipman

Links to documentation and simple examples at the end

Virtualisation

Page 72: Operations: a developer's guide

@annashipman

You can develop locally using the same software as is deployed remotely

Virtualisation

Page 73: Operations: a developer's guide

@annashipman

You can use configuration management to build your VM

Virtualisation

Page 74: Operations: a developer's guide

@annashipman

It makes it easy to collaborate

Virtualisation

Page 75: Operations: a developer's guide

@annashipman

Vagrant makes it easy to get started/pick up where you left off

Virtualisation

Page 76: Operations: a developer's guide
Page 77: Operations: a developer's guide

@annashipman

Currently Otto uses Vagrant

Virtualisation

Page 78: Operations: a developer's guide

@annashipman

Vagrant can improve your project tomorrow

Virtualisation

Page 79: Operations: a developer's guide

@annashipman

3. Containerisation

Page 80: Operations: a developer's guide
Page 81: Operations: a developer's guide

@annashipman

(Docker is not the only containerisation tech)

Containerisation

Page 82: Operations: a developer's guide

@annashipman

Docker is based on Linux Containers

1. Put netting on garlic and put back outside

Containerisation

Page 83: Operations: a developer's guide

@annashipman

2008: LXC 2004: Solaris zones 2000: BSD jails 1982: chroot (tech based on)

Containerisation

Page 84: Operations: a developer's guide
Page 85: Operations: a developer's guide
Page 86: Operations: a developer's guide

@annashipman

You can run multiple containers

Containerisation

Page 87: Operations: a developer's guide

@annashipman

Containers are isolated from each other

Containerisation

Page 88: Operations: a developer's guide

@annashipman

Why would you use containers?

Containerisation

Page 89: Operations: a developer's guide

@annashipman

Configuring a VM can be slow

Containerisation

Page 90: Operations: a developer's guide

@annashipman

You might instead decide to take a snapshot

Containerisation

Page 91: Operations: a developer's guide

@annashipman

And that is what you deploy to production

Containerisation

Page 92: Operations: a developer's guide

@annashipman

Containers are immutable

Containerisation

Page 93: Operations: a developer's guide

@annashipman

So you can be sure what you’ve tested is what is running in production

Containerisation

Page 94: Operations: a developer's guide

@annashipman

With all the same dependencies

1. Put netting on garlic and put back outside

Containerisation

Page 95: Operations: a developer's guide

@annashipman

However…

Containerisation

Page 96: Operations: a developer's guide

@annashipman

The immutability can make developing locally difficult

Containerisation

Page 97: Operations: a developer's guide

@annashipman

You can’t run them everywhere

Containerisation

Page 98: Operations: a developer's guide

@annashipman

Possibly a harder concept to grasp

Containerisation

Page 99: Operations: a developer's guide

@annashipman

Right now, it’s not essential that you understand Docker unless you are interested

Containerisation

Page 100: Operations: a developer's guide

@annashipman

2 + 3: Virtualisation + Containerisation

Turtles

Page 101: Operations: a developer's guide

@annashipman

Locally, it’s Vagrant or Docker

Turtles

Page 102: Operations: a developer's guide

@annashipman

But if you deploy to the cloud…

Turtles

Page 103: Operations: a developer's guide

@annashipman

Page 104: Operations: a developer's guide

@annashipman

How do you know where the problem is?

Turtles

Page 105: Operations: a developer's guide

@annashipman

It’s turtles all the way down

Turtles

Page 106: Operations: a developer's guide

@annashipman

BREAK

Page 107: Operations: a developer's guide

@annashipman

Wrangling servers“Cattle not pets”

Page 108: Operations: a developer's guide

@annashipman

VirtualisationUse Vagrant

Page 109: Operations: a developer's guide

@annashipman

ContainerisationYou don’t need to learn Docker right now

Page 110: Operations: a developer's guide

@annashipman

4. Some tools to make you a better developer

Page 111: Operations: a developer's guide

@annashipman

“Should all my tools be written in JavaScript (warning: if the answer is ‘no’, there might be a revolution!!!)”—Remy

Tools

Page 112: Operations: a developer's guide

@annashipman

Build systems – Grunt, Gulp…

Tools

Page 113: Operations: a developer's guide

@annashipman

Don’t just work out of the box

Tools

Page 114: Operations: a developer's guide

@annashipman

Dependencies and plug-ins

Tools

Page 115: Operations: a developer's guide

@annashipman

You could use NPM

Tools

Page 116: Operations: a developer's guide

@annashipman

Make

Tools

Page 117: Operations: a developer's guide

@annashipman

Can create tasks to do anything: clean, compile, build…

Tools

Page 118: Operations: a developer's guide

@annashipman

Advantages of Make

Tools

Page 119: Operations: a developer's guide

@annashipman

Advantages of MakeDependency tracking and resolution

Tools

Page 120: Operations: a developer's guide

@annashipman

Advantages of MakeDependency tracking and resolution Only does what it needs to

Tools

Page 121: Operations: a developer's guide

@annashipman

all: styles.css print.css

styles.css: styles.scss sass styles.scss:styles.css

print.css: print.scss sass print.scss:print.css

Tools

Page 122: Operations: a developer's guide

@annashipman

all: styles.css print.css

styles.css: styles.scss sass styles.scss:styles.css

print.css: print.scss sass print.scss:print.css

Compiles your SCSS to CSS

Tools

Page 123: Operations: a developer's guide

@annashipman

all: styles.css print.css

styles.css: styles.scss sass styles.scss:styles.css

print.css: print.scss sass print.scss:print.css

This is what Grunt, Gulp etc are doing

Tools

Page 124: Operations: a developer's guide

@annashipman

all: styles.css print.css

styles.css: styles.scss sass styles.scss:styles.css

print.css: print.scss sass print.scss:print.css

$ make styles.css

Tools

Page 125: Operations: a developer's guide

@annashipman

all: styles.css print.css

styles.css: styles.scss sass styles.scss:styles.css

print.css: print.scss sass print.scss:print.css

Only runs if SCSS is newer than CSS

Tools

Page 126: Operations: a developer's guide

@annashipman

all: styles.css print.css

styles.css: styles.scss sass styles.scss:styles.css

print.css: print.scss sass print.scss:print.css

$ make print.css

Tools

Page 127: Operations: a developer's guide

@annashipman

all: styles.css print.css

styles.css: styles.scss sass styles.scss:styles.css

print.css: print.scss sass print.scss:print.css

$ make all

Tools

Page 128: Operations: a developer's guide

@annashipman

all: styles.css print.css

styles.css: styles.scss sass styles.scss:styles.css

print.css: print.scss sass print.scss:print.css

$ make all

Tools

Page 129: Operations: a developer's guide

@annashipman

all: styles.css print.css

styles.css: styles.scss sass styles.scss:styles.css

print.css: print.scss sass print.scss:print.css

$ make

Tools

Page 130: Operations: a developer's guide

@annashipman

all: styles.css print.css

styles.css: styles.scss sass styles.scss:styles.css

print.css: print.scss sass print.scss:print.css

If print.css doesn’t need updating, only runs styles.cssTools

Page 131: Operations: a developer's guide

@annashipman

Advantages of MakeDependency tracking and resolution Only does what it needs to

Tools

Page 132: Operations: a developer's guide

@annashipman

Advantages of MakeDependency tracking and resolution Only does what it needs to Included in your OS*

*Linux, Unix, MacOS

Tools

Page 133: Operations: a developer's guide

@annashipman

Has everything you need

Tools

Page 134: Operations: a developer's guide

@annashipman

It just isn’t written in JS

Tools

Page 135: Operations: a developer's guide

@annashipman

Unix tools

Tools

Page 136: Operations: a developer's guide

@annashipman

grep

Tools

Page 137: Operations: a developer's guide

@annashipman

grepSearch given input files for patterns

Tools

Page 138: Operations: a developer's guide

@annashipman

cat

Tools

Page 139: Operations: a developer's guide

@annashipman

catConcatenate and print files

Tools

Page 140: Operations: a developer's guide

@annashipman

awk

Tools

Page 141: Operations: a developer's guide

@annashipman

awkScan input files for patterns; perform action

Tools

Page 142: Operations: a developer's guide

@annashipman

And the most useful: man

Tools

Page 143: Operations: a developer's guide

@annashipman

manformat and display manual pages

Tools

Page 144: Operations: a developer's guide

@annashipman

$ man grep

Tools

Page 145: Operations: a developer's guide
Page 146: Operations: a developer's guide

@annashipman

$ man man

Tools

Page 147: Operations: a developer's guide
Page 148: Operations: a developer's guide

@annashipman

Being unixy

Tools

Page 149: Operations: a developer's guide

@annashipman

Each tool does one thing very well

Tools

Page 150: Operations: a developer's guide

@annashipman

Composable

Tools

Page 151: Operations: a developer's guide

@annashipman

|

Tools

Page 152: Operations: a developer's guide

@annashipman

| (Pipe)

Tools

Page 153: Operations: a developer's guide

@annashipman

Read a file of text, determine the n most frequently used words, and print out a sorted list of those words along with their frequencies.

Tools

Page 154: Operations: a developer's guide

@annashipman

1 tr -cs A-Za-z '\n' | 2 tr A-Z a-z | 3 sort | 4 uniq -c | 5 sort -rn | 6 sed ${1}q

Tools

Page 155: Operations: a developer's guide

@annashipman

1 tr -cs A-Za-z '\n' | 2 tr A-Z a-z | 3 sort | 4 uniq -c | 5 sort -rn | 6 sed ${1}q

Tools

Page 156: Operations: a developer's guide

@annashipman

1 tr -cs A-Za-z '\n' | 2 tr A-Z a-z | 3 sort | 4 uniq -c | 5 sort -rn | 6 sed ${1}q

Tools

Page 157: Operations: a developer's guide

@annashipman

1 tr -cs A-Za-z '\n' | 2 tr A-Z a-z | 3 sort | 4 uniq -c | 5 sort -rn | 6 sed ${1}q

Tools

Page 158: Operations: a developer's guide

@annashipman

1 tr -cs A-Za-z '\n' | 2 tr A-Z a-z | 3 sort | 4 uniq -c | 5 sort -rn | 6 sed ${1}q

Tools

Page 159: Operations: a developer's guide

@annashipman

1 tr -cs A-Za-z '\n' | 2 tr A-Z a-z | 3 sort | 4 uniq -c | 5 sort -rn | 6 sed ${1}q

Tools

Page 160: Operations: a developer's guide

@annashipman

1 tr -cs A-Za-z '\n' | 2 tr A-Z a-z | 3 sort | 4 uniq -c | 5 sort -rn | 6 sed ${1}q

Tools

Page 161: Operations: a developer's guide

@annashipman

1 tr -cs A-Za-z '\n' | 2 tr A-Z a-z | 3 sort | 4 uniq -c | 5 sort -rn | 6 sed ${1}q

Tools

Page 162: Operations: a developer's guide

@annashipman

1 tr -cs A-Za-z '\n' | 2 tr A-Z a-z | 3 sort | 4 uniq -c | 5 sort -rn | 6 sed ${1}q

Tools

Page 163: Operations: a developer's guide

@annashipman

1 tr -cs A-Za-z '\n' | 2 tr A-Z a-z | 3 sort | 4 uniq -c | 5 sort -rn | 6 sed ${1}q

Tools

Page 164: Operations: a developer's guide

@annashipman

1 tr -cs A-Za-z '\n' | 2 tr A-Z a-z | 3 sort | 4 uniq -c | 5 sort -rn | 6 sed ${1}q

Tools

Page 165: Operations: a developer's guide

@annashipman

Read a file of text, determine the n most frequently used words, and print out a sorted list of those words along with their frequencies.

Tools

Page 166: Operations: a developer's guide

@annashipman

You might not want to write all your programs in Unix

Tools

Page 167: Operations: a developer's guide

@annashipman

It can be really useful for doing complex tasks

Tools

Page 168: Operations: a developer's guide

@annashipman

It’s worth getting familiar with Unix tools locally

Tools

Page 169: Operations: a developer's guide

@annashipman

So that the first time isn’t when you’re debugging on the server

Tools

Page 170: Operations: a developer's guide

@annashipman

$ rake -T | grep "some detail"

Tools

Page 171: Operations: a developer's guide

@annashipman

Read the output

Tools

Page 172: Operations: a developer's guide

@annashipman

Git instructions

Tools

Page 173: Operations: a developer's guide

@annashipman

$ git add accidental_new_file.txt $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage)

new file: accidental_new_file.txt

Tools

Page 174: Operations: a developer's guide

@annashipman

$ git add accidental_new_file.txt $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage)

new file: accidental_new_file.txt

Tools

Page 175: Operations: a developer's guide

@annashipman

Unix error messages

Tools

Page 176: Operations: a developer's guide

@annashipman

$ grep -r anna

Tools

Page 177: Operations: a developer's guide

@annashipman

$ grep -r anna grep: warning: recursive search of stdin

Tools

Page 178: Operations: a developer's guide

@annashipman

$ grep -r anna .

Tools

Page 179: Operations: a developer's guide

@annashipman

Unix tools can help you

Tools

Page 180: Operations: a developer's guide

@annashipman

The main three things you should take home:

Page 181: Operations: a developer's guide

@annashipman

Use Vagrant

Page 182: Operations: a developer's guide

@annashipman

Unix tools are your friends

Page 183: Operations: a developer's guide

@annashipman

Read the output

Page 184: Operations: a developer's guide

Thank you!Anna Shipman @annashipman

Page 185: Operations: a developer's guide

Configuration managementhttps://www.scriptrock.com/articles/the-7-configuration-management-tools-you-need-to-know http://gettingstartedwithchef.com/first-steps-with-chef.html https://docs.vagrantup.com/v2/getting-started/provisioning.html

Virtualisationhttp://searchvirtualdatacentre.techtarget.co.uk/definition/Virtualisation http://searchservervirtualization.techtarget.com/definition/server-virtualization http://www.infoworld.com/article/2621446/server-virtualization/server-virtualization-top-10-benefits-of-server-virtualization.html

Using Vagranthttps://www.vagrantup.com/ http://blog.bennycornelissen.nl/otto-a-modern-developers-new-best-friend/ https://github.com/patrickdlee/vagrant-examples (Useful getting started examples)

Dockerhttp://patg.net/containers,virtualization,docker/2014/06/05/docker-intro/ https://zeltser.com/security-risks-and-benefits-of-docker-application/

Containerisation vs Virtualisationhttp://www.slideshare.net/bcantrill/docker-and-the-future-of-containers-in-production https://www.scriptrock.com/articles/docker-vs-vagrant

Make instead of Grunt/Gulphttp://blog.keithcirkel.co.uk/why-we-should-stop-using-grunt/ https://www.youtube.com/watch?v=0RYETb9YVrk (Talk on using NPM as a build tool) https://blog.jcoglan.com/2014/02/05/building-javascript-projects-with-make/

Tools for better devhttp://www.leancrew.com/all-this/2011/12/more-shell-less-egg/ (More detail on the 6-line Unix program)