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