intro to vagrant

45
and STUFF

Upload: mantas-klasavicius

Post on 15-Jan-2015

268 views

Category:

Technology


0 download

DESCRIPTION

Introduction to Vagrant with examples on Docker and AWS

TRANSCRIPT

Page 1: Intro to vagrant

and

STUFF

Page 2: Intro to vagrant

* Vagrant is a tool for creating,

managing and distributing

portable development

environments.

Page 3: Intro to vagrant

* Wrapper around a variety of virtual machine

providers.

* Single command that uniformly creates,

provisions, destroys, and connects to machines

* Replicate and rebuild whole VM instantly

Page 4: Intro to vagrant
Page 5: Intro to vagrant

* Open source tool.

* Works on Mac OS X, Windows

and Linux

Page 6: Intro to vagrant

Zero to VM in Seconds

* Vagrant up

Page 7: Intro to vagrant

Main Concepts

‘vagrant’ cli Boxes Vagrantfile

Page 8: Intro to vagrant

vagrant reads a Vagrantfile

and builds a machine based

on a template called box.

Page 9: Intro to vagrant

Boxes

* Template from which machines are created.

* Contains pre –installed OS

* Boxes managed with vagrant command line

Page 10: Intro to vagrant

Boxes * Many publically available - http://www.vagrantbox.es/ - https://vagrantcloud.com/discover/featured - https://github.com/jedi4ever/veewee/tree/master/templates

* Can be custom build - vagrant package --base <vm name> * Preinstalled with specific software - Veewee - Packer

Page 11: Intro to vagrant

Packer http://www.packer.io/

Created by Hashicorp

Some functionality overlaps with Vagrant

Useful with Vagrant

some-os-distro.iso → distro.box

Page 12: Intro to vagrant

Packer templates

h"ps://www.google.lt/search?q=packer+templates    h"ps://github.com/monai/packer-­‐templates  

 

Page 13: Intro to vagrant

Vagrantfile

* Per-project configuration file read by vagrant. * Describe machine properties, software to be provisioned, network, etc… * Simple Ruby based DSL

Page 14: Intro to vagrant

Vagrantfile example

VAGRANTFILE_API_VERSION  =  "2"    Vagrant.configure(VAGRANTFILE_API_VERSION)  do  |config|        config.vm.box  =  "MantasK/centos-­‐6.5-­‐x86_64-­‐puppet"      config.vm.host_name  =  'test77v1.dev1.adform.com'        config.vm.provider  "virtualbox"  do  |vm|            vm.customize  [                                        "modifyvm",                    :id,                                          "-­‐-­‐memory",                    "2048",                                        "-­‐-­‐cpus",                        "2"                                    ]      end  end  

Page 15: Intro to vagrant

Vagrantfile cli •  Manages entire lifecycle of the dev environments •  $ vagrant …

Page 16: Intro to vagrant

Vagrantfile cli

Vagrant up

Vagrant ssh

Vagrant destroy

Page 17: Intro to vagrant

Vagrantfile cli

Vagrant init

Vagrant box

Vagrant suspend

Vagrant halt

Vagrant plugin

Vagrant package

https://docs.vagrantup.com/v2/cli/index.html

Page 18: Intro to vagrant

Features

Provisioning Synced Folders Networking

Multi machine

Providers Plugins

Page 19: Intro to vagrant

Providers

A provider manages compute resources for virtual machines

Allows to use the right provider for the different environment

Page 20: Intro to vagrant

Providers

VAGRANTFILE_API_VERSION  =  "2"    Vagrant.configure(VAGRANTFILE_API_VERSION)  do  |config|        config.vm.box  =  "MantasK/centos-­‐6.5-­‐x86_64-­‐puppet"      config.vm.host_name  =  'test77v1.dev1.adform.com'        config.vm.provider  "virtualbox"  do  |vm|            vm.customize  [                                        "modifyvm",                    :id,                                          "-­‐-­‐memory",                    "2048",                                        "-­‐-­‐cpus",                                  "2"                                    ]      end  end  

Page 21: Intro to vagrant

Providers

$  vagrant  box  list  

$  vagrant  box  add  <name>  <url>  

$  vagrant  up  -­‐-­‐provider=<name>

Page 22: Intro to vagrant

Synced Folders

Automaticaly syncs folders from host to guest Types: VirtualBox, Rsync, SMB, NFS, Etc., Default: Vagrant will share your project directory (the directory with the Vagrantfile) to /vagrant

Page 23: Intro to vagrant

Synced Folders

VAGRANTFILE_API_VERSION  =  "2"    Vagrant.configure(VAGRANTFILE_API_VERSION)  do  |config|        config.vm.box  =  "MantasK/centos-­‐6.5-­‐x86_64-­‐puppet"      config.vm.host_name  =  'test77v1.dev1.adform.com’      config.vm.synced_folder  "data",  "/tutorial"        config.vm.provider  "virtualbox"  do  |vm|          vm.customize  [                                        "modifyvm",                    :id,                                          "-­‐-­‐memory",                    "2048",                                        "-­‐-­‐cpus",                                  "2"                                    ]      end  end  

Page 24: Intro to vagrant

Networking

Forwarded Ports - basically NAT

Private Network - Host-only networking

Public Network - Bridged Networking

You can use mix and match – couple of those together or

couple of one

Page 25: Intro to vagrant

Networking VAGRANTFILE_API_VERSION  =  "2"    Vagrant.configure(VAGRANTFILE_API_VERSION)  do  |config|        config.vm.box  =  "MantasK/centos-­‐6.5-­‐x86_64-­‐puppet"      config.vm.host_name  =  'test77v1.dev1.adform.com’      config.vm.synced_folder  "data",  "/tutorial”    config.vm.network  "forwarded_port",  guest:  80,  host:  8080    config.vm.network  "private_network",  ip:  "172.16.0.11"        config.vm.provider  "virtualbox"  do  |vm|          vm.customize  [                                        "modifyvm",                    :id,                                          "-­‐-­‐memory",                    "2048",                                        "-­‐-­‐cpus",                                  "2"                                    ]      end  end  

Page 26: Intro to vagrant

Provisioning

Install required software as part of ‘vagrant up’

Supports: Shell, Ansible, Docker, Puppet, Salt

Page 27: Intro to vagrant

Provisioning Puppet apply

VAGRANTFILE_API_VERSION  =  "2"    Vagrant.configure(VAGRANTFILE_API_VERSION)  do  |config|        config.vm.box  =  "MantasK/centos-­‐6.5-­‐x86_64-­‐puppet"      config.vm.host_name  =  'test77v1.dev1.adform.com’  …      config.vm.provider  "virtualbox"  do  |vm|  …          config.vm.provision  "puppet"  do  |puppet|          puppet.manifests_path  =  "puppet/manifests"          puppet.module_path        =  "puppet/modules"          puppet.manifest_file    =  "site.pp"      end  end  

Page 28: Intro to vagrant

Provisioning Puppet agent

VAGRANTFILE_API_VERSION  =  "2"    Vagrant.configure(VAGRANTFILE_API_VERSION)  do  |config|        config.vm.box  =  "MantasK/centos-­‐6.5-­‐x86_64-­‐puppet"      config.vm.host_name  =  'test77v1.dev1.adform.com’  …      config.vm.provider  "virtualbox"  do  |vm|  …        config.vm.provision  "shell",  inline:  "sudo  /usr/bin/puppet  agent  -­‐-­‐verbose  –onekme    –no-­‐daemonize  -­‐-­‐server  puppetmaster.adform.com  -­‐-­‐wailorcert  60  -­‐-­‐environment  noenv"        config.vm.provision  "puppet_server"  do  |puppet|          puppet.puppet_server  =  "puppetmaster.adform.com"          puppet.opkons              =  ['-­‐-­‐test',  '-­‐-­‐configkmeout  1200']      end  end  

Page 29: Intro to vagrant

Multi machine Manage multi-machine cluster with a single Vagrantfile

Vagrant.configure(VAGRANTFILE_API_VERSION)  do  |config|              config.vm.define  "node1"  do  |node1|                          node1.vm.box  =  "MantasK/centos-­‐6.5-­‐x86_64-­‐puppet"                          node1.vm.host_name  =  'node1.test.com'                          node1.vm.provider  "virtualbox"  do  |vb|                                      vb.customize  ["modifyvm",  :id,  "-­‐-­‐memory",  "2048"]                          end                          node1.vm.network  "private_network",  ip:  "172.16.0.11"              end            config.vm.define  "node2"  do  |node2|                        node2.vm.box  =  "MantasK/centos-­‐6.5-­‐x86_64-­‐puppet"                        node2.vm.host_name  =  'node2.test.com'                        node2.vm.provider  "virtualbox"  do  |vb|                                    vb.gui  =  true                                  vb.customize  ["modifyvm",  :id,  "-­‐-­‐memory",  "1048"]                        end                        node2.vm.network  "private_network",  ip:  "172.16.0.21"            end  end  

Page 30: Intro to vagrant

Plugins

Extensions. Lots of them!

https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins

$  vagrant  plugin  install  vagrant-­‐aws  $ vagrant up --provider=aws

Page 31: Intro to vagrant

Vagrant Cloud

Vagrant Share

Box Distribution

Discover Boxes

Page 32: Intro to vagrant

Download/Install h"ps://www.vagrantup.com/downloads  

Page 33: Intro to vagrant
Page 34: Intro to vagrant

Docker

* Linux Only

* Open Source

* uses LinuX Containers (LXC)

* run in the same operating system as its host.

* uses AuFS for the file system

Page 35: Intro to vagrant

Docker vs VMs

Page 36: Intro to vagrant

Docker vs VMs Full Issolation Resources guaranteed Size: 1GB VM x # VMs Performance: overhead Minutes to start Need conversion

Less Issolation No guaranteed resources Size: 1GB ( little over J) Performance: no overhead Seconds to start Portable

Page 37: Intro to vagrant

Docker portable

Page 38: Intro to vagrant

Docker vs VMs

full isolation with guaranteed resources => VMs isolate processes from each other and want to run a ton of them => LXS

Page 39: Intro to vagrant

Docker on Windows & MAC

Page 40: Intro to vagrant

Docker Hello World

$  docker  run  -­‐d  ubuntu:14.04  /bin/sh  -­‐c  "while  true;  do  echo  hello  world;  sleep  1;  done”  

 

$  docker  ps  

$ docker  logs  <name>  

Page 41: Intro to vagrant

Docker CLI

$  docker  run  -­‐d  -­‐P  training/webapp  python  app.py  

Page 42: Intro to vagrant

Docker Cli

$  docker  run  

$  docker  ps  

$  docker  logs  

$  docker  stop  

$  docker  a"ach  

$  docker  images  

$  docker  search  

$  docker  pull  

$  docker  top  

$  docker  inspect  

…  

Page 43: Intro to vagrant

Docker Dockerfile

FROM                ubuntu:12.10  RUN                  apt-­‐get  update  RUN                  apt-­‐get  -­‐y  install  redis-­‐server  EXPOSE            6379  ENTRYPOINT    ["/usr/bin/redis-­‐server"]  

Page 44: Intro to vagrant

Docker Cli

$  docker  build  -­‐t  adform/redis  <path_to_dir>  

 

$  docker  run  -­‐-­‐name  redis  -­‐d  <your  username>/redis  

Page 45: Intro to vagrant

Docker With Vagrant

DEMO $  vagrant  up  -­‐-­‐provider=docker    -­‐-­‐no-­‐parallel