Vagrant

From Christoph's Personal Wiki
Revision as of 22:33, 21 September 2021 by Christoph (Talk | contribs) (Created page with "'''Vagrant''' is an open-source software product for building and maintaining portable virtual software development environments; e.g., for VirtualBox, KVM, Hyper-V, Docker co...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Vagrant is an open-source software product for building and maintaining portable virtual software development environments; e.g., for VirtualBox, KVM, Hyper-V, Docker containers, VMware, and AWS. It tries to simplify the software configuration management of virtualization in order to increase development productivity. Vagrant is written in the Ruby language, but its ecosystem supports development in a few other languages.

Vagrant commands

  • vagrant up — Bring a box online.
  • vagrant status — Show current box status.
  • vagrant suspend — Pause the current box.
  • vagrant resume — Resume the current box.
  • vagrant halt — Shutdown the current box.
  • vagrant destroy — Destroy the current box. By running this command, you will lose any data stored on the box.
  • vagrant snapshot — Take a snapshot of the current box.

Examples

Rancher

The following is an example of bringing up Rancher (pre-v2.x):

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

MASTER_MEMORY=1024
AGENT_MEMORY=1024

RANCH_MASTER_ADDRESS="172.19.8.100"
# Boxes are configured at 101, 102 and so on
RANCH_SUBNET="172.19.8"


RANCHER_SERVER_DOMAIN_NAME="ranch-svr.infracloud.io"
RANCHER_CLIENT_DEF="ranch-def.infracloud.io"
RANCHER_CLIENT_K8S="ranch-k8s.infracloud.io"


Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

    config.vm.define "ranch_server" do |rserver|
        rserver.vm.box = "ubuntu/xenial64"
        rserver.vm.network "private_network", ip: "#{RANCH_MASTER_ADDRESS}" 
        rserver.vm.hostname = "#{RANCHER_SERVER_DOMAIN_NAME}"
        rserver.vm.provider :virtualbox do |vba|
            vba.customize ["modifyvm", :id, "--memory", MASTER_MEMORY]
        end
        rserver.vm.provision "shell", inline: "wget -qO- https://get.docker.com/ | sh"          
        rserver.vm.provision "shell", inline: "sudo docker run -d --restart=always -p 8080:8080 rancher/server"     
    end

    config.vm.define "ranch_c_default" do |rclient|
        rclient.vm.box = "ubuntu/xenial64"
        rclient.vm.network "private_network", ip: "#{RANCH_SUBNET}.101"
        rclient.vm.hostname = "#{RANCHER_CLIENT_DEF}"
        rclient.vm.provider :virtualbox do |vba|
            vba.customize ["modifyvm", :id, "--memory", AGENT_MEMORY]
        end
        rclient.vm.provision "shell", inline: "wget -qO- https://get.docker.com/ | sh"      
        # K8S works with slightly older version of Docker hence downgrading
        #rclient.vm.provision "shell", inline: "sudo apt-get install -y --force-yes docker-engine=1.10.3-0~trusty"       
    end

    config.vm.define "ranch_c_k8s" do |rclient|
        rclient.vm.box = "ubuntu/xenial64"
        rclient.vm.network "private_network", ip: "#{RANCH_SUBNET}.102"
        rclient.vm.hostname = "#{RANCHER_CLIENT_K8S}"
        rclient.vm.provider :virtualbox do |vba|
            vba.customize ["modifyvm", :id, "--memory", AGENT_MEMORY]
        end
        rclient.vm.provision "shell", inline: "wget -qO- https://get.docker.com/ | sh"
        # K8S works with slightly older version of Docker hence downgrading
        #rclient.vm.provision "shell", inline: "sudo apt-get install -y --force-yes docker-engine=1.10.3-0~trusty"
    end

end
  • Start up resources:
$ vagrant up

External links