-
Notifications
You must be signed in to change notification settings - Fork 376
/
Copy pathVagrantfile
129 lines (114 loc) · 4.25 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
VAGRANTFILE_API_VERSION = "2"
NUM_WORKERS = 1
MODE = ENV['K8S_IP_FAMILY'] || "v4"
if MODE != "v4" && MODE != "v6" && MODE != "dual"
raise "K8S_IP_FAMILY env variable should be one of 'v4', 'v6' or 'dual'"
end
K8S_POD_NETWORK_V4_CIDR = "10.10.0.0/16"
K8S_POD_NETWORK_V6_CIDR = "fd02::/48"
if MODE == "v4"
K8S_POD_NETWORK_CIDR = K8S_POD_NETWORK_V4_CIDR
elsif MODE == "v6"
K8S_POD_NETWORK_CIDR = K8S_POD_NETWORK_V6_CIDR
else
K8S_POD_NETWORK_CIDR = K8S_POD_NETWORK_V4_CIDR + "," + K8S_POD_NETWORK_V6_CIDR
end
# Only used for IPv6 clusters
K8S_NODE_CP_GW_V4_IP = "10.10.0.1"
K8S_NODE_CP_GW_V6_IP = "fd02::1"
K8S_NODE_CP_GW_IP = (MODE == "v6") ? K8S_NODE_CP_GW_V6_IP : K8S_NODE_CP_GW_V4_IP
K8S_SERVICE_NETWORK_V4_CIDR = "10.96.0.0/12"
K8S_SERVICE_NETWORK_V6_CIDR = "fd03::/112"
if MODE == "v4"
K8S_SERVICE_NETWORK_CIDR = K8S_SERVICE_NETWORK_V4_CIDR
elsif MODE == "v6"
K8S_SERVICE_NETWORK_CIDR = K8S_SERVICE_NETWORK_V6_CIDR
else
K8S_SERVICE_NETWORK_CIDR = K8S_SERVICE_NETWORK_V4_CIDR + "," + K8S_SERVICE_NETWORK_V6_CIDR
end
NODE_NETWORK_V4_PREFIX = "192.168.77."
NODE_NETWORK_V6_PREFIX = "fd3b:fcf5:3e92:d732::"
MEMORY = 2048
KUBE_PROXY_MODE = ENV['KUBE_PROXY_MODE'] || "iptables"
if KUBE_PROXY_MODE == "iptables" || KUBE_PROXY_MODE == "none"
KUBE_PROXY_IPVS_STRICT_ARP = false
elsif KUBE_PROXY_MODE == "ipvs"
# For now, we always enable strict ARP, which is required to use MetalLB
KUBE_PROXY_IPVS_STRICT_ARP = true
else
raise "KUBE_PROXY_MODE env variable should be one of 'iptables', 'ipvs' or 'none'"
end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/jammy64"
config.vm.provider "virtualbox" do |v|
v.memory = MEMORY
# 2 CPUS required to initialize K8s cluster with "kubeadm init"
v.cpus = 2
end
groups = {
"controlplane" => ["k8s-node-control-plane"],
"workers" => ["k8s-node-worker-[1:#{NUM_WORKERS}]"],
}
config.vm.define "k8s-node-control-plane" do |node|
node.vm.hostname = "k8s-node-control-plane"
node_ipv4 = NODE_NETWORK_V4_PREFIX + "100"
node_ipv6 = NODE_NETWORK_V6_PREFIX + "100"
# The network will be configured using the Ansible playbook
# Despite setting auto_config to false, it seems that it is necessary to
# provide an IP address, even though it won't be used.
# See https://github.com/hashicorp/vagrant/issues/7583
node.vm.network "private_network", ip: node_ipv4, auto_config: false
if MODE == "v4"
node_ip = node_ipv4
elsif MODE == "v6"
node_ip = node_ipv6
else
node_ip = node_ipv4 + "," + node_ipv6
end
node.vm.provision :ansible do |ansible|
ansible.playbook = "playbook/k8s.yml"
ansible.groups = groups
ansible.extra_vars = {
# Ubuntu bionic does not ship with python2
ansible_python_interpreter:"/usr/bin/python3",
node_ip: node_ip,
node_ipv4: (MODE != "v6") ? node_ipv4 : "",
node_ipv6: (MODE != "v4") ? node_ipv6 : "",
node_name: "k8s-node-control-plane",
k8s_pod_network_cidr: K8S_POD_NETWORK_CIDR,
k8s_service_network_cidr: K8S_SERVICE_NETWORK_CIDR,
k8s_api_server_ip: (MODE == "v6") ? node_ipv6 : node_ipv4,
k8s_ip_family: MODE,
k8s_antrea_gw_ip: K8S_NODE_CP_GW_IP,
kube_proxy_mode: KUBE_PROXY_MODE,
kube_proxy_ipvs_strict_arp: KUBE_PROXY_IPVS_STRICT_ARP,
}
end
end
(1..NUM_WORKERS).each do |node_id|
config.vm.define "k8s-node-worker-#{node_id}" do |node|
node.vm.hostname = "k8s-node-worker-#{node_id}"
node_ipv4 = NODE_NETWORK_V4_PREFIX + "#{100 + node_id}"
node_ipv6 = NODE_NETWORK_V6_PREFIX + "#{100 + node_id}"
node.vm.network "private_network", ip: node_ipv4, auto_config: false
if MODE == "v4"
node_ip = node_ipv4
elsif MODE == "v6"
node_ip = node_ipv6
else
node_ip = node_ipv4 + "," + node_ipv6
end
node.vm.provision :ansible do |ansible|
ansible.playbook = "playbook/k8s.yml"
ansible.groups = groups
ansible.extra_vars = {
ansible_python_interpreter:"/usr/bin/python3",
node_ip: node_ip,
node_ipv4: (MODE != "v6") ? node_ipv4 : "",
node_ipv6: (MODE != "v4") ? node_ipv6 : "",
node_name: "k8s-node-worker-#{node_id}",
}
end
end
end
end