Intro to vagrant

933 views

Published on

Introduction to Vagrant with examples on Docker and AWS

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
933
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
38
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Intro to vagrant

  1. 1. and STUFF
  2. 2. * Vagrant is a tool for creating, managing and distributing portable development environments.
  3. 3. * 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
  4. 4. * Open source tool. * Works on Mac OS X, Windows and Linux
  5. 5. Zero to VM in Seconds * Vagrant up
  6. 6. Main Concepts ‘vagrant’ cliBoxes Vagrantfile
  7. 7. vagrant reads a Vagrantfile and builds a machine based on a template called box.
  8. 8. Boxes * Template from which machines are created. * Contains pre –installed OS * Boxes managed with vagrant command line
  9. 9. 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
  10. 10. Packer http://www.packer.io/ Created by Hashicorp Some functionality overlaps with Vagrant Useful with Vagrant some-os-distro.iso → distro.box
  11. 11. Packer templates h"ps://www.google.lt/search?q=packer+templates     h"ps://github.com/monai/packer-­‐templates    
  12. 12. Vagrantfile * Per-project configuration file read by vagrant. * Describe machine properties, software to be provisioned, network, etc… * Simple Ruby based DSL
  13. 13. 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  
  14. 14. Vagrantfile cli •  Manages entire lifecycle of the dev environments •  $ vagrant …
  15. 15. Vagrantfile cli Vagrant up Vagrant ssh Vagrant destroy
  16. 16. Vagrantfile cli Vagrant init Vagrant box Vagrant suspend Vagrant halt Vagrant plugin Vagrant package https://docs.vagrantup.com/v2/cli/index.html
  17. 17. Features ProvisioningSynced Folders Networking Multi machine Providers Plugins
  18. 18. Providers A provider manages compute resources for virtual machines Allows to use the right provider for the different environment
  19. 19. 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  
  20. 20. Providers $  vagrant  box  list   $  vagrant  box  add  <name>  <url>   $  vagrant  up  -­‐-­‐provider=<name>
  21. 21. 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
  22. 22. 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  
  23. 23. 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
  24. 24. 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  
  25. 25. Provisioning Install required software as part of ‘vagrant up’ Supports: Shell, Ansible, Docker, Puppet, Salt
  26. 26. 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  
  27. 27. 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  
  28. 28. 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  
  29. 29. Plugins Extensions. Lots of them! https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins $  vagrant  plugin  install  vagrant-­‐aws   $ vagrant up --provider=aws
  30. 30. Vagrant Cloud Vagrant Share Box Distribution Discover Boxes
  31. 31. Download/Install h"ps://www.vagrantup.com/downloads  
  32. 32. Docker * Linux Only * Open Source * uses LinuX Containers (LXC) * run in the same operating system as its host. * uses AuFS for the file system
  33. 33. Docker vs VMs
  34. 34. 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
  35. 35. Docker portable
  36. 36. Docker vs VMs full isolation with guaranteed resources => VMs isolate processes from each other and want to run a ton of them => LXS
  37. 37. Dockeron Windows& MAC
  38. 38. 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>  
  39. 39. Docker CLI $  docker  run  -­‐d  -­‐P  training/webapp  python  app.py  
  40. 40. Docker Cli $  docker  run   $  docker  ps   $  docker  logs   $  docker  stop   $  docker  a"ach   $  docker  images   $  docker  search   $  docker  pull   $  docker  top   $  docker  inspect   …  
  41. 41. Docker Dockerfile FROM                ubuntu:12.10   RUN                  apt-­‐get  update   RUN                  apt-­‐get  -­‐y  install  redis-­‐server   EXPOSE            6379   ENTRYPOINT    ["/usr/bin/redis-­‐server"]  
  42. 42. Docker Cli $  docker  build  -­‐t  adform/redis  <path_to_dir>     $  docker  run  -­‐-­‐name  redis  -­‐d  <your  username>/redis  
  43. 43. Docker With Vagrant DEMO $  vagrant  up  -­‐-­‐provider=docker    -­‐-­‐no-­‐parallel

×