Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 486f91c

Browse files
aaronlevyhongchaodeng
authored andcommitted
hack/multi-node: Add option to launch with self-hosted etcd
1 parent 9315176 commit 486f91c

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

hack/multi-node/Vagrantfile

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ $controller_count = 1
1313
$controller_vm_memory = 2048
1414
$worker_count = 1
1515
$worker_vm_memory = 1024
16-
$etcd_count = 1
17-
$etcd_vm_memory = 512
1816

1917
if $worker_vm_memory < 1024
2018
puts "Workers should have at least 1024 MB of memory"
2119
end
2220

2321
CONTROLLER_CLUSTER_IP="10.3.0.1"
24-
ETCD_CLOUD_CONFIG_PATH = File.expand_path("./etcd-cloud-config.yaml")
2522
CONTROLLER_USER_DATA_PATH = File.expand_path("./cluster/user-data-controller")
2623
WORKER_USER_DATA_PATH = File.expand_path("./cluster/user-data-worker")
2724

@@ -37,8 +34,14 @@ def workerIP(num)
3734
return "172.17.4.#{num+200}"
3835
end
3936

40-
etcdIPs = [*1..$etcd_count].map{ |i| etcdIP(i) }
41-
initial_etcd_cluster = etcdIPs.map.with_index{ |ip, i| "e#{i+1}=http://#{ip}:2380" }.join(",")
37+
$self_host_etcd = true if ENV['SELF_HOST_ETCD'] == "true"
38+
if !$self_host_etcd
39+
$etcd_count = 1
40+
$etcd_vm_memory = 512
41+
ETCD_CLOUD_CONFIG_PATH = File.expand_path("./etcd-cloud-config.yaml")
42+
etcdIPs = [*1..$etcd_count].map{ |i| etcdIP(i) }
43+
initial_etcd_cluster = etcdIPs.map.with_index{ |ip, i| "e#{i+1}=http://#{ip}:2380" }.join(",")
44+
end
4245

4346
Vagrant.configure("2") do |config|
4447
# always use Vagrant's insecure key
@@ -78,32 +81,34 @@ Vagrant.configure("2") do |config|
7881
vb.gui = false
7982
end
8083

81-
(1..$etcd_count).each do |i|
82-
config.vm.define vm_name = "e%d" % i do |etcd|
84+
if !$self_host_etcd
85+
(1..$etcd_count).each do |i|
86+
config.vm.define vm_name = "e%d" % i do |etcd|
8387

84-
data = YAML.load(IO.readlines(ETCD_CLOUD_CONFIG_PATH)[1..-1].join)
85-
data['coreos']['etcd2']['initial-cluster'] = initial_etcd_cluster
86-
data['coreos']['etcd2']['name'] = vm_name
87-
etcd_config_file = Tempfile.new('etcd_config')
88-
etcd_config_file.write("#cloud-config\n#{data.to_yaml}")
89-
etcd_config_file.close
88+
data = YAML.load(IO.readlines(ETCD_CLOUD_CONFIG_PATH)[1..-1].join)
89+
data['coreos']['etcd2']['initial-cluster'] = initial_etcd_cluster
90+
data['coreos']['etcd2']['name'] = vm_name
91+
etcd_config_file = Tempfile.new('etcd_config')
92+
etcd_config_file.write("#cloud-config\n#{data.to_yaml}")
93+
etcd_config_file.close
9094

91-
etcd.vm.hostname = vm_name
95+
etcd.vm.hostname = vm_name
9296

93-
["vmware_fusion", "vmware_workstation"].each do |vmware|
94-
etcd.vm.provider vmware do |v|
95-
v.vmx['memsize'] = $etcd_vm_memory
97+
["vmware_fusion", "vmware_workstation"].each do |vmware|
98+
etcd.vm.provider vmware do |v|
99+
v.vmx['memsize'] = $etcd_vm_memory
100+
end
96101
end
97-
end
98102

99-
etcd.vm.provider :virtualbox do |vb|
100-
vb.memory = $etcd_vm_memory
101-
end
103+
etcd.vm.provider :virtualbox do |vb|
104+
vb.memory = $etcd_vm_memory
105+
end
102106

103-
etcd.vm.network :private_network, ip: etcdIP(i)
107+
etcd.vm.network :private_network, ip: etcdIP(i)
104108

105-
etcd.vm.provision :file, source: etcd_config_file.path, destination: "/tmp/vagrantfile-user-data"
106-
etcd.vm.provision :shell, inline: "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", privileged: true
109+
etcd.vm.provision :file, source: etcd_config_file.path, destination: "/tmp/vagrantfile-user-data"
110+
etcd.vm.provision :shell, inline: "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", privileged: true
111+
end
107112
end
108113
end
109114

hack/multi-node/bootkube-up

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@ if [ ${un} == 'Darwin' ]; then
77
local_os="darwin"
88
fi
99

10+
SELF_HOST_ETCD=${SELF_HOST_ETCD:-false}
11+
if [ ${SELF_HOST_ETCD} = "true" ]; then
12+
etcd_render_flags="--etcd-servers=http://10.3.0.15:2379 --storage-backend=etcd3 --experimental-self-hosted-etcd"
13+
etcd_start_flags="--etcd-server=http://172.17.4.101:12379,http://10.3.0.15:2379 --experimental-self-hosted-etcd"
14+
else
15+
etcd_render_flags="--etcd-servers=http://172.17.4.51:2379"
16+
etcd_start_flags="--etcd-server=http://172.17.4.51:2379"
17+
fi
18+
1019
# Render assets
1120
if [ ! -d "cluster" ]; then
12-
../../_output/bin/${local_os}/bootkube render --asset-dir=cluster --api-servers=https://172.17.4.101:443 --etcd-servers=http://172.17.4.51:2379
21+
../../_output/bin/${local_os}/bootkube render --asset-dir=cluster --api-servers=https://172.17.4.101:443 ${etcd_render_flags}
1322
# Add rendered kubeconfig to the node user-data
1423
cat user-data.sample > cluster/user-data && sed 's/^/ /' cluster/auth/kubeconfig >> cluster/user-data
1524
cp cluster/user-data{,-worker}
@@ -26,7 +35,7 @@ scp -q -F ssh_config -r cluster core@c1:/home/core/cluster
2635
scp -q -F ssh_config ../../_output/bin/linux/bootkube core@c1:/home/core
2736

2837
# Run bootkube
29-
ssh -q -F ssh_config core@c1 "sudo /home/core/bootkube start --asset-dir=/home/core/cluster --etcd-server=http://172.17.4.51:2379 2>> /home/core/bootkube.log"
38+
ssh -q -F ssh_config core@c1 "sudo /home/core/bootkube start --asset-dir=/home/core/cluster ${etcd_start_flags} 2>> /home/core/bootkube.log"
3039

3140
echo
3241
echo "Bootstrap complete. Access your kubernetes cluster using:"

0 commit comments

Comments
 (0)