c12s-kubespray/Vagrantfile

89 lines
2.5 KiB
Ruby
Raw Normal View History

2016-06-14 16:21:56 +00:00
# -*- mode: ruby -*-
# vi: set ft=ruby :
ENV["VAGRANT_DEFAULT_PROVIDER"] = "libvirt"
pool = ENV["VAGRANT_POOL"] || "10.210.0.0/16"
prefix = pool.gsub(/\.\d+\.\d+\/16$/, "")
2016-06-14 16:21:56 +00:00
$num_instances = 7
$vm_memory = 2048
$vm_cpus = 2
$user = ENV["USER"]
$public_subnet = prefix.to_s + ".0"
$private_subnet = prefix.to_s + ".1"
$mgmt_cidr = prefix.to_s + ".2.0/24"
2016-06-14 16:21:56 +00:00
$instance_name_prefix = "#{$user}-k8s"
2016-06-14 16:21:56 +00:00
# Boxes with libvirt provider support:
#$box = "yk0/ubuntu-xenial" #900M
#$box = "centos/7"
$box = "nrclark/xenial64-minimal-libvirt"
# Create SSH keys for future lab
system 'bash ssh-keygen.sh'
# Create nodes list for future kargo deployment
nodes=""
2016-06-16 11:00:51 +00:00
(2..$num_instances).each do |i|
ip = "#{$private_subnet}.#{i+10}"
nodes = "#{nodes}#{ip}\n"
end
File.open("nodes", 'w') { |file| file.write(nodes) }
# Create the lab
2016-06-14 16:21:56 +00:00
Vagrant.configure("2") do |config|
(1..$num_instances).each do |i|
# First node would be master node
2016-06-14 16:21:56 +00:00
if i == 1
bootstrap_script = "bootstrap-master.sh"
master = true
2016-06-14 16:21:56 +00:00
else
bootstrap_script = "bootstrap-node.sh"
master = false
2016-06-14 16:21:56 +00:00
end
2016-06-14 16:21:56 +00:00
config.ssh.insert_key = false
vm_name = "%s-%02d" % [$instance_name_prefix, i]
2016-06-14 16:21:56 +00:00
config.vm.define vm_name do |test_vm|
test_vm.vm.box = $box
test_vm.vm.hostname = vm_name
# Libvirt provider settings
2016-06-14 16:21:56 +00:00
test_vm.vm.provider :libvirt do |domain|
domain.uri = "qemu+unix:///system"
domain.memory = $vm_memory
domain.cpus = $vm_cpus
domain.driver = "kvm"
domain.host = "localhost"
domain.connect_via_ssh = false
domain.username = $user
domain.storage_pool_name = "default"
domain.nic_model_type = "e1000"
domain.management_network_name = "#{$instance_name_prefix}-mgmt-net"
domain.management_network_address = $mgmt_cidr
domain.nested = true
domain.cpu_mode = "host-passthrough"
domain.volume_cache = "unsafe"
domain.disk_bus = "virtio"
2016-06-14 16:21:56 +00:00
end
ip = "#{$private_subnet}.#{i+10}"
test_vm.vm.network :private_network, :ip => "#{ip}"
2016-06-14 16:21:56 +00:00
# Provisioning
if master
config.vm.provision "file", source: "deploy-k8s.kargo.sh", destination: "~/deploy-k8s.kargo.sh"
config.vm.provision "file", source: "custom.yaml", destination: "~/custom.yaml"
config.vm.provision "file", source: "nodes", destination: "~/nodes"
end
2016-06-16 11:00:51 +00:00
2016-06-14 16:21:56 +00:00
config.vm.provision "file", source: "ssh", destination: "~/ssh"
config.vm.provision :shell, :path => bootstrap_script
end
end
end