Skip to content

Instantly share code, notes, and snippets.

@danielnegri
Created January 8, 2015 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielnegri/edcd89627ac2b08937fe to your computer and use it in GitHub Desktop.
Save danielnegri/edcd89627ac2b08937fe to your computer and use it in GitHub Desktop.
Vagrant Cluster - Master & Slaves
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
# Require a recent version of vagrant otherwise some have reported errors setting host names on boxes
Vagrant.require_version ">= 1.6.2"
INSTANCE_PREFIX="byoc"
MASTER_NAME="#{INSTANCE_PREFIX}-master"
# The number of slaves to provision
$num_slave = (ENV['NUM_SLAVES'] || 1).to_i
# Determine the OS platform to use
$byoc_os = "ubuntu"
# ip configuration
$master_ip = ENV['MASTER_IP'] || "10.245.1.2"
$slave_ip_base = ENV['SLAVE_IP_BASE'] || "10.245.1."
$slave_ips = $num_slave.times.collect { |n| $slave_ip_base + "#{n+3}" }
# OS platform to box information
$byoc_box = {
"ubuntu" => {
"name" => "ubuntu14.04",
"box_url" => "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
}
}
# This stuff is cargo-culted from http://www.stefanwrobel.com/how-to-make-vagrant-performance-not-suck
# Give access to half of all cpu cores on the host. We divide by 2 as we assume
# that users are running with hyperthreads.
host = RbConfig::CONFIG['host_os']
if host =~ /darwin/
$vm_cpus = (`sysctl -n hw.ncpu`.to_i/2.0).ceil
elsif host =~ /linux/
$vm_cpus = (`nproc`.to_i/2.0).ceil
else # sorry Windows folks, I can't help you
$vm_cpus = 2
end
# Give VM 512MB of RAM -> 1Gb
$vm_mem = 512*2
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
def customize_vm(config)
config.vm.box = $byoc_box[$byoc_os]["name"]
config.vm.box_url = $byoc_box[$byoc_os]["box_url"]
config.vm.synced_folder "../", "/byoc"
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", $vm_mem]
v.customize ["modifyvm", :id, "--cpus", $vm_cpus]
# Use faster paravirtualized networking
v.customize ["modifyvm", :id, "--nictype1", "virtio"]
v.customize ["modifyvm", :id, "--nictype2", "virtio"]
end
end
# Kubernetes master
config.vm.define "master" do |config|
customize_vm config
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", $vm_mem*2]
end
# config.vm.provision "shell", path: "#{$byoc_os}/provision-master.sh"
config.vm.network "private_network", ip: "#{$master_ip}"
config.vm.hostname = MASTER_NAME
end
# Kubernetes slave
$num_slave.times do |n|
config.vm.define "slave-#{n+1}" do |slave|
customize_vm slave
slave_index = n+1
slave_ip = $slave_ips[n]
# slave.vm.provision "shell", run: "always", path: "#{$byoc_os}/provision-slave.sh"
slave.vm.network "private_network", ip: "#{slave_ip}"
slave.vm.hostname = "#{INSTANCE_PREFIX}-slave-#{slave_index}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment