2023-11-08 22:42:11 +01:00
|
|
|
# ENV['VAGRANT_NO_PARALLEL'] = 'no'
|
|
|
|
NODE_ROLES = ["server-0", "server-1", "server-2", "agent-0", "agent-1"]
|
|
|
|
NODE_BOXES = ['generic/ubuntu2004', 'generic/ubuntu2004', 'generic/ubuntu2004', 'generic/ubuntu2004', 'generic/ubuntu2004']
|
|
|
|
NODE_CPUS = 2
|
|
|
|
NODE_MEMORY = 2048
|
|
|
|
# Virtualbox >= 6.1.28 require `/etc/vbox/network.conf` for expanded private networks
|
|
|
|
NETWORK_PREFIX = "10.10.10"
|
|
|
|
|
|
|
|
def provision(vm, role, node_num)
|
|
|
|
vm.box = NODE_BOXES[node_num]
|
|
|
|
vm.hostname = role
|
2023-11-14 23:36:15 +01:00
|
|
|
# We use a private network because the default IPs are dynamically assigned
|
2023-11-08 23:00:52 +01:00
|
|
|
# during provisioning. This makes it impossible to know the server-0 IP when
|
|
|
|
# provisioning subsequent servers and agents. A private network allows us to
|
|
|
|
# assign static IPs to each node, and thus provide a known IP for the API endpoint.
|
2023-11-08 22:42:11 +01:00
|
|
|
node_ip = "#{NETWORK_PREFIX}.#{100+node_num}"
|
2023-11-08 23:00:52 +01:00
|
|
|
# An expanded netmask is required to allow VM<-->VM communication, virtualbox defaults to /32
|
2023-11-08 22:42:11 +01:00
|
|
|
vm.network "private_network", ip: node_ip, netmask: "255.255.255.0"
|
|
|
|
|
|
|
|
vm.provision "ansible", run: 'once' do |ansible|
|
|
|
|
ansible.compatibility_mode = "2.0"
|
2023-11-09 21:56:38 +01:00
|
|
|
ansible.playbook = "playbook/site.yml"
|
2023-11-08 22:42:11 +01:00
|
|
|
ansible.groups = {
|
|
|
|
"server" => NODE_ROLES.grep(/^server/),
|
|
|
|
"agent" => NODE_ROLES.grep(/^agent/),
|
|
|
|
"k3s_cluster:children" => ["server", "agent"],
|
|
|
|
}
|
|
|
|
ansible.extra_vars = {
|
2023-11-09 21:56:38 +01:00
|
|
|
k3s_version: "v1.26.9+k3s1",
|
2023-11-08 22:42:11 +01:00
|
|
|
api_endpoint: "#{NETWORK_PREFIX}.100",
|
2023-11-09 00:16:28 +01:00
|
|
|
token: "myvagrant",
|
2023-11-08 23:00:52 +01:00
|
|
|
# Required to use the private network configured above
|
|
|
|
extra_server_args: "--node-external-ip #{node_ip} --flannel-iface eth1",
|
2023-11-09 00:16:28 +01:00
|
|
|
extra_agent_args: "--node-external-ip #{node_ip} --flannel-iface eth1",
|
2023-11-13 23:09:15 +01:00
|
|
|
# Optional, left as reference for ruby-ansible syntax
|
2023-11-09 21:30:18 +01:00
|
|
|
# extra_service_envs: [ "NO_PROXY='localhost'" ],
|
2023-12-06 22:55:32 +01:00
|
|
|
# server_config_yaml: <<~YAML
|
2023-11-13 23:09:15 +01:00
|
|
|
# write-kubeconfig-mode: 644
|
2023-12-06 22:55:32 +01:00
|
|
|
# kube-apiserver-arg:
|
|
|
|
# - advertise-port=1234
|
2023-11-13 23:09:15 +01:00
|
|
|
# YAML
|
2023-11-08 22:42:11 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
# Default provider is libvirt, virtualbox is only provided as a backup
|
|
|
|
config.vm.provider "libvirt" do |v|
|
|
|
|
v.cpus = NODE_CPUS
|
|
|
|
v.memory = NODE_MEMORY
|
|
|
|
end
|
|
|
|
config.vm.provider "virtualbox" do |v|
|
|
|
|
v.cpus = NODE_CPUS
|
|
|
|
v.memory = NODE_MEMORY
|
2023-11-27 18:46:30 +01:00
|
|
|
v.linked_clone = true
|
2023-11-08 22:42:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
NODE_ROLES.each_with_index do |name, i|
|
|
|
|
config.vm.define name do |node|
|
|
|
|
provision(node.vm, name, i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|