-
Notifications
You must be signed in to change notification settings - Fork 4
/
Vagrantfile
151 lines (124 loc) · 7.33 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Size of the cluster created by Vagrant
num_instances = 2
# Change basename of the VM
instance_name_prefix="calico-mesos"
calico_node_ver = "v0.8.0"
calicoctl_url = "https://github.com/projectcalico/calico-containers/releases/download/#{calico_node_ver}/calicoctl"
Vagrant.configure("2") do |config|
config.vm.box = 'centos/7'
config.ssh.insert_key = false
# The vagrant centos:7 box has a bug where it automatically tries to sync /home/vagrant/sync using rsync, so disable it:
# https://github.com/mitchellh/vagrant/issues/6154#issuecomment-135949010
config.vm.synced_folder ".", "/home/vagrant/sync", disabled: true
config.vm.provider :virtualbox do |vbox|
# On VirtualBox, we don't have guest additions or a functional vboxsf
# in CoreOS, so tell Vagrant that so it can be smarter.
vbox.functional_vboxsf = false
vbox.check_guest_additions = false
vbox.memory = 2048
vbox.cpus = 2
end
config.vm.provider :vsphere do |vsphere, override|
# The following section sets login credentials for the vagrant-vsphere
# plugin to allow use of this Vagrant script in vSphere.
# This is not recommended for demo purposes, only internal testing.
override.vm.box_url = 'file://dummy.box'
vsphere.host = ENV['VSPHERE_HOSTNAME']
vsphere.compute_resource_name = ENV['VSPHERE_COMPUTE_RESOURCE_NAME']
vsphere.template_name = ENV['VSPHERE_TEMPLATE_NAME']
vsphere.user = ENV['VSPHERE_USER']
vsphere.password = ENV['VSPHERE_PASSWORD']
vsphere.insecure=true
vsphere.customization_spec_name = 'vagrant-vsphere'
end
master_ip = "172.24.197.101"
# Set up each box
(1..num_instances).each do |i|
vm_name = "%s-%02d" % [instance_name_prefix, i]
config.vm.define vm_name do |host|
# Provision the FQDN
host.vm.hostname = vm_name
# Assign IP and prepend IP/hostname pair to /etc/hosts for correct FQDN IP resolution
ip = "172.24.197.#{i+100}"
host.vm.network :private_network, ip: ip
# Selinux => permissive
host.vm.provision :shell, inline: "setenforce permissive", privileged: true
# Generate certs
host.vm.provision :shell, inline: "mkdir /keys", privileged: true
host.vm.provision :shell, inline: "openssl genrsa -f4 -out /keys/key.pem 4096", privileged: true
host.vm.provision :shell, inline: "openssl req -new -batch -x509 -days 365 -key /keys/key.pem -out /keys/cert.pem", privileged: true
# Install docker, and load in the custom mesos-calico image
host.vm.provision :docker
# If the MESOS_CALICO_TAR environment variable is true, load the local calico-mesos docker image from file
if ENV["MESOS_CALICO_TAR"] == "true"
host.vm.provision "file", source: "dist/docker/mesos-calico.tar", destination: "mesos-calico.tar"
host.vm.provision :shell, inline: "sudo docker load < mesos-calico.tar"
else
host.vm.provision :docker, images: ["calico/mesos-calico"]
end
# Configure the Master node of the cluster.
# The Master needs to run the mesos-master service, etcd, zookeeper, and marathon.
if i == 1
# Get the unit files
["etcd", "zookeeper", "marathon", "mesos-master"].each do |service_name|
host.vm.provision "file", source: "units/#{service_name}.service", destination: "#{service_name}.service"
end
# Set firewall rules
host.vm.provision :shell, inline: "systemctl restart firewalld", privileged: true
[2181, 5050, 2379, 4001, 8080].each do |port|
host.vm.provision :shell, inline: "sudo firewall-cmd --zone=public --add-port=#{port}/tcp --permanent"
end
host.vm.provision :shell, inline: "systemctl restart firewalld", privileged: true
host.vm.provision :shell, inline: "systemctl restart docker", privileged: true
# Etcd
host.vm.provision :shell, inline: "echo FQDN=`hostname -f` > /etc/sysconfig/etcd"
host.vm.provision :shell, inline: "mv etcd.service /usr/lib/systemd/system/", privileged: true
host.vm.provision :shell, inline: "systemctl enable etcd.service", privileged: true
host.vm.provision :shell, inline: "systemctl start etcd.service", privileged: true
# Zookeeper
host.vm.provision :shell, inline: "mv zookeeper.service /usr/lib/systemd/system/", privileged: true
host.vm.provision :shell, inline: "systemctl enable zookeeper.service", privileged: true
host.vm.provision :shell, inline: "systemctl start zookeeper.service", privileged: true
# Mesos-master
host.vm.provision :shell, inline: "sh -c 'echo IP=#{ip} > /etc/sysconfig/mesos-master'", privileged: true
host.vm.provision :shell, inline: "mv mesos-master.service /usr/lib/systemd/system/", privileged: true
host.vm.provision :shell, inline: "systemctl enable mesos-master.service", privileged: true
host.vm.provision :shell, inline: "systemctl start mesos-master.service", privileged: true
# Marathon
host.vm.provision :shell, inline: "mv marathon.service /usr/lib/systemd/system/", privileged: true
host.vm.provision :shell, inline: "systemctl enable marathon.service", privileged: true
host.vm.provision :shell, inline: "systemctl start marathon.service", privileged: true
end
# Configure the Agent nodes of the cluster.
if i > 1
["calico", "mesos-agent"].each do |service_name|
host.vm.provision "file", source: "units/#{service_name}.service", destination: "#{service_name}.service"
end
# Set firewall rules
host.vm.provision :shell, inline: "systemctl restart firewalld", privileged: true
[179, 5051].each do |port|
host.vm.provision :shell, inline: "firewall-cmd --zone=public --add-port=#{port}/tcp --permanent", privileged: true
end
host.vm.provision :shell, inline: "systemctl restart firewalld", privileged: true
# Calicoctl
host.vm.provision :shell, inline: "yum install -y wget", privileged: true
host.vm.provision :shell, inline: "wget -qO /usr/bin/calicoctl #{calicoctl_url}", privileged: true
host.vm.provision :shell, inline: "chmod +x /usr/bin/calicoctl"
host.vm.provision :shell, inline: "sh -c 'echo ETCD_AUTHORITY=#{master_ip}:4001 > /etc/sysconfig/calico'", privileged: true
# Start calico service with systemd and check status
host.vm.provision :shell, inline: "mv calico.service /usr/lib/systemd/system/", privileged: true
host.vm.provision :shell, inline: "systemctl enable calico.service", privileged: true
host.vm.provision :shell, inline: "systemctl start calico.service", privileged: true
host.vm.provision :shell, inline: "calicoctl status"
# Configure mesos-agent
host.vm.provision :shell, inline: "sh -c 'echo ZK=#{master_ip} > /etc/sysconfig/mesos-agent'", privileged: true
host.vm.provision :shell, inline: "sh -c 'echo IP=#{ip} >> /etc/sysconfig/mesos-agent'", privileged: true
host.vm.provision :shell, inline: "mv mesos-agent.service /usr/lib/systemd/system/", privileged: true
host.vm.provision :shell, inline: "systemctl enable mesos-agent.service", privileged: true
host.vm.provision :shell, inline: "systemctl start mesos-agent.service", privileged: true
end
end
end
end