2016-05-08 15:11:09 +00:00
|
|
|
# -*- mode: ruby -*-
|
|
|
|
# # vi: set ft=ruby :
|
|
|
|
|
|
|
|
require 'fileutils'
|
|
|
|
|
2017-12-20 14:40:35 +00:00
|
|
|
Vagrant.require_version ">= 2.0.0"
|
2016-05-08 15:11:09 +00:00
|
|
|
|
|
|
|
CONFIG = File.join(File.dirname(__FILE__), "vagrant/config.rb")
|
|
|
|
|
2017-06-04 15:31:39 +00:00
|
|
|
COREOS_URL_TEMPLATE = "https://storage.googleapis.com/%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json"
|
|
|
|
|
2018-01-11 18:28:33 +00:00
|
|
|
# Uniq disk UUID for libvirt
|
|
|
|
DISK_UUID = Time.now.utc.to_i
|
|
|
|
|
2017-06-02 22:53:47 +00:00
|
|
|
SUPPORTED_OS = {
|
2017-06-04 15:31:39 +00:00
|
|
|
"coreos-stable" => {box: "coreos-stable", bootstrap_os: "coreos", user: "core", box_url: COREOS_URL_TEMPLATE % ["stable"]},
|
|
|
|
"coreos-alpha" => {box: "coreos-alpha", bootstrap_os: "coreos", user: "core", box_url: COREOS_URL_TEMPLATE % ["alpha"]},
|
|
|
|
"coreos-beta" => {box: "coreos-beta", bootstrap_os: "coreos", user: "core", box_url: COREOS_URL_TEMPLATE % ["beta"]},
|
2017-06-27 14:42:18 +00:00
|
|
|
"ubuntu" => {box: "bento/ubuntu-16.04", bootstrap_os: "ubuntu", user: "vagrant"},
|
2018-01-12 16:43:41 +00:00
|
|
|
"centos" => {box: "centos/7", bootstrap_os: "centos", user: "vagrant"},
|
2018-02-06 12:45:02 +00:00
|
|
|
"opensuse" => {box: "opensuse/openSUSE-42.3-x86_64", bootstrap_os: "opensuse", use: "vagrant"},
|
2018-02-22 14:17:57 +00:00
|
|
|
"opensuse-tumbleweed" => {box: "opensuse/openSUSE-Tumbleweed-x86_64", bootstrap_os: "opensuse", use: "vagrant"},
|
2017-06-02 22:53:47 +00:00
|
|
|
}
|
|
|
|
|
2016-05-08 15:11:09 +00:00
|
|
|
# Defaults for config options defined in CONFIG
|
|
|
|
$num_instances = 3
|
|
|
|
$instance_name_prefix = "k8s"
|
|
|
|
$vm_gui = false
|
2017-10-02 20:16:39 +00:00
|
|
|
$vm_memory = 2048
|
2016-05-08 15:11:09 +00:00
|
|
|
$vm_cpus = 1
|
|
|
|
$shared_folders = {}
|
|
|
|
$forwarded_ports = {}
|
|
|
|
$subnet = "172.17.8"
|
2017-06-02 23:03:43 +00:00
|
|
|
$os = "ubuntu"
|
2017-10-03 10:16:13 +00:00
|
|
|
$network_plugin = "flannel"
|
2017-02-16 20:46:04 +00:00
|
|
|
# The first three nodes are etcd servers
|
|
|
|
$etcd_instances = $num_instances
|
2017-10-03 10:16:13 +00:00
|
|
|
# The first two nodes are kube masters
|
2017-02-16 20:46:04 +00:00
|
|
|
$kube_master_instances = $num_instances == 1 ? $num_instances : ($num_instances - 1)
|
2017-10-03 10:16:13 +00:00
|
|
|
# All nodes are kube nodes
|
|
|
|
$kube_node_instances = $num_instances
|
2018-01-11 18:28:33 +00:00
|
|
|
# The following only works when using the libvirt provider
|
|
|
|
$kube_node_instances_with_disks = false
|
|
|
|
$kube_node_instances_with_disks_size = "20G"
|
|
|
|
$kube_node_instances_with_disks_number = 2
|
|
|
|
|
2017-02-24 21:41:27 +00:00
|
|
|
$local_release_dir = "/vagrant/temp"
|
2016-05-08 15:11:09 +00:00
|
|
|
|
|
|
|
host_vars = {}
|
|
|
|
|
|
|
|
if File.exist?(CONFIG)
|
|
|
|
require CONFIG
|
|
|
|
end
|
|
|
|
|
2017-06-04 15:31:39 +00:00
|
|
|
$box = SUPPORTED_OS[$os][:box]
|
2016-05-08 15:11:09 +00:00
|
|
|
# if $inventory is not set, try to use example
|
|
|
|
$inventory = File.join(File.dirname(__FILE__), "inventory") if ! $inventory
|
|
|
|
|
|
|
|
# if $inventory has a hosts file use it, otherwise copy over vars etc
|
|
|
|
# to where vagrant expects dynamic inventory to be.
|
|
|
|
if ! File.exist?(File.join(File.dirname($inventory), "hosts"))
|
|
|
|
$vagrant_ansible = File.join(File.dirname(__FILE__), ".vagrant",
|
|
|
|
"provisioners", "ansible")
|
|
|
|
FileUtils.mkdir_p($vagrant_ansible) if ! File.exist?($vagrant_ansible)
|
|
|
|
if ! File.exist?(File.join($vagrant_ansible,"inventory"))
|
2018-02-07 15:50:05 +00:00
|
|
|
FileUtils.ln_s($inventory, File.join($vagrant_ansible,"inventory"))
|
2016-05-08 15:11:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-28 21:32:56 +00:00
|
|
|
if Vagrant.has_plugin?("vagrant-proxyconf")
|
|
|
|
$no_proxy = ENV['NO_PROXY'] || ENV['no_proxy'] || "127.0.0.1,localhost"
|
|
|
|
(1..$num_instances).each do |i|
|
|
|
|
$no_proxy += ",#{$subnet}.#{i+100}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-08 15:11:09 +00:00
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
# always use Vagrants insecure key
|
|
|
|
config.ssh.insert_key = false
|
2016-05-18 02:52:57 +00:00
|
|
|
config.vm.box = $box
|
2017-06-04 15:31:39 +00:00
|
|
|
if SUPPORTED_OS[$os].has_key? :box_url
|
|
|
|
config.vm.box_url = SUPPORTED_OS[$os][:box_url]
|
|
|
|
end
|
2017-06-02 23:51:09 +00:00
|
|
|
config.ssh.username = SUPPORTED_OS[$os][:user]
|
2016-05-08 15:11:09 +00:00
|
|
|
# plugin conflict
|
|
|
|
if Vagrant.has_plugin?("vagrant-vbguest") then
|
|
|
|
config.vbguest.auto_update = false
|
|
|
|
end
|
|
|
|
(1..$num_instances).each do |i|
|
|
|
|
config.vm.define vm_name = "%s-%02d" % [$instance_name_prefix, i] do |config|
|
|
|
|
config.vm.hostname = vm_name
|
|
|
|
|
2016-10-28 21:32:56 +00:00
|
|
|
if Vagrant.has_plugin?("vagrant-proxyconf")
|
|
|
|
config.proxy.http = ENV['HTTP_PROXY'] || ENV['http_proxy'] || ""
|
|
|
|
config.proxy.https = ENV['HTTPS_PROXY'] || ENV['https_proxy'] || ""
|
|
|
|
config.proxy.no_proxy = $no_proxy
|
|
|
|
end
|
|
|
|
|
2016-05-08 15:11:09 +00:00
|
|
|
if $expose_docker_tcp
|
|
|
|
config.vm.network "forwarded_port", guest: 2375, host: ($expose_docker_tcp + i - 1), auto_correct: true
|
|
|
|
end
|
|
|
|
|
|
|
|
$forwarded_ports.each do |guest, host|
|
|
|
|
config.vm.network "forwarded_port", guest: guest, host: host, auto_correct: true
|
|
|
|
end
|
|
|
|
|
|
|
|
["vmware_fusion", "vmware_workstation"].each do |vmware|
|
|
|
|
config.vm.provider vmware do |v|
|
|
|
|
v.vmx['memsize'] = $vm_memory
|
|
|
|
v.vmx['numvcpus'] = $vm_cpus
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-11 15:59:11 +00:00
|
|
|
config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__args: ['--verbose', '--archive', '--delete', '-z']
|
|
|
|
|
2017-06-09 21:19:28 +00:00
|
|
|
$shared_folders.each do |src, dst|
|
2018-04-11 15:59:11 +00:00
|
|
|
config.vm.synced_folder src, dst, type: "rsync", rsync__args: ['--verbose', '--archive', '--delete', '-z']
|
2017-06-09 21:19:28 +00:00
|
|
|
end
|
|
|
|
|
2016-05-08 15:11:09 +00:00
|
|
|
config.vm.provider :virtualbox do |vb|
|
|
|
|
vb.gui = $vm_gui
|
|
|
|
vb.memory = $vm_memory
|
|
|
|
vb.cpus = $vm_cpus
|
|
|
|
end
|
|
|
|
|
2018-01-11 18:29:01 +00:00
|
|
|
config.vm.provider :libvirt do |lv|
|
|
|
|
lv.memory = $vm_memory
|
|
|
|
end
|
|
|
|
|
2016-05-08 15:11:09 +00:00
|
|
|
ip = "#{$subnet}.#{i+100}"
|
|
|
|
host_vars[vm_name] = {
|
2017-02-28 21:31:28 +00:00
|
|
|
"ip": ip,
|
2017-10-03 10:16:13 +00:00
|
|
|
"bootstrap_os": SUPPORTED_OS[$os][:bootstrap_os],
|
2017-02-24 21:41:27 +00:00
|
|
|
"local_release_dir" => $local_release_dir,
|
2017-02-28 21:31:28 +00:00
|
|
|
"download_run_once": "False",
|
2017-10-03 10:16:13 +00:00
|
|
|
"kube_network_plugin": $network_plugin
|
2016-05-08 15:11:09 +00:00
|
|
|
}
|
2017-10-03 10:16:13 +00:00
|
|
|
|
2016-05-08 15:11:09 +00:00
|
|
|
config.vm.network :private_network, ip: ip
|
2018-01-11 18:09:37 +00:00
|
|
|
|
2017-10-27 16:57:12 +00:00
|
|
|
# Disable swap for each vm
|
|
|
|
config.vm.provision "shell", inline: "swapoff -a"
|
|
|
|
|
2018-01-11 18:28:33 +00:00
|
|
|
if $kube_node_instances_with_disks
|
|
|
|
# Libvirt
|
|
|
|
driverletters = ('a'..'z').to_a
|
|
|
|
config.vm.provider :libvirt do |lv|
|
|
|
|
# always make /dev/sd{a/b/c} so that CI can ensure that
|
|
|
|
# virtualbox and libvirt will have the same devices to use for OSDs
|
|
|
|
(1..$kube_node_instances_with_disks_number).each do |d|
|
|
|
|
lv.storage :file, :device => "hd#{driverletters[d]}", :path => "disk-#{i}-#{d}-#{DISK_UUID}.disk", :size => $kube_node_instances_with_disks_size, :bus => "ide"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-08 15:11:09 +00:00
|
|
|
# Only execute once the Ansible provisioner,
|
|
|
|
# when all the machines are up and ready.
|
|
|
|
if i == $num_instances
|
|
|
|
config.vm.provision "ansible" do |ansible|
|
|
|
|
ansible.playbook = "cluster.yml"
|
|
|
|
if File.exist?(File.join(File.dirname($inventory), "hosts"))
|
|
|
|
ansible.inventory_path = $inventory
|
|
|
|
end
|
2017-12-12 10:47:04 +00:00
|
|
|
ansible.become = true
|
2016-05-08 15:11:09 +00:00
|
|
|
ansible.limit = "all"
|
|
|
|
ansible.host_key_checking = false
|
2017-10-03 10:16:13 +00:00
|
|
|
ansible.raw_arguments = ["--forks=#{$num_instances}", "--flush-cache"]
|
2016-05-08 15:11:09 +00:00
|
|
|
ansible.host_vars = host_vars
|
2016-05-18 04:30:01 +00:00
|
|
|
#ansible.tags = ['download']
|
2016-05-08 15:11:09 +00:00
|
|
|
ansible.groups = {
|
2017-02-16 20:46:04 +00:00
|
|
|
"etcd" => ["#{$instance_name_prefix}-0[1:#{$etcd_instances}]"],
|
|
|
|
"kube-master" => ["#{$instance_name_prefix}-0[1:#{$kube_master_instances}]"],
|
|
|
|
"kube-node" => ["#{$instance_name_prefix}-0[1:#{$kube_node_instances}]"],
|
2016-05-08 15:11:09 +00:00
|
|
|
"k8s-cluster:children" => ["kube-master", "kube-node"],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|