Prepare for HA control plane

This commit is contained in:
Emil Dabrowski 2023-01-02 00:50:42 +01:00
parent 8c4615b2c7
commit 23edc91bab
6 changed files with 26 additions and 24 deletions

View File

@ -1,6 +1,6 @@
IMAGE_NAME = "bento/ubuntu-22.04" IMAGE_NAME = "bento/ubuntu-22.04"
CONTROLPLANE_IP = "192.168.56.11" CONTROL_PLANES = 1
NODES = 1 NODES = 0
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
config.ssh.insert_key = false config.ssh.insert_key = false
@ -10,19 +10,21 @@ Vagrant.configure("2") do |config|
v.cpus = 2 v.cpus = 2
end end
config.vm.define "controlplane" do |master| (1..CONTROL_PLANES).each do |i|
master.vm.box = IMAGE_NAME config.vm.define "control-plane-#{i}" do |control_plane|
master.vm.network "private_network", ip: CONTROLPLANE_IP control_plane.vm.box = IMAGE_NAME
master.vm.hostname = "controlplane" control_plane.vm.network "private_network", ip: "192.168.56.#{10 + i}"
master.vm.provision "ansible" do |ansible| control_plane.vm.hostname = "control-plane-#{i}"
control_plane.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yaml" ansible.playbook = "playbook.yaml"
ansible.extra_vars = { ansible.extra_vars = {
cluster_name: "gerar", cluster_name: "gerar",
node_ip: CONTROLPLANE_IP, node_ip: "192.168.56.#{10 + i}",
is_controlplane: true, is_control_plane: true,
} }
end end
end end
end
(1..NODES).each do |i| (1..NODES).each do |i|
config.vm.define "node-#{i}" do |node| config.vm.define "node-#{i}" do |node|
@ -34,8 +36,8 @@ Vagrant.configure("2") do |config|
ansible.extra_vars = { ansible.extra_vars = {
cluster_name: "gerar", cluster_name: "gerar",
node_ip: "192.168.56.#{20 + i}", node_ip: "192.168.56.#{20 + i}",
controlplane_ip: CONTROLPLANE_IP, is_control_plane: false,
is_controlplane: false, control_plane_endpoint: "192.168.56.11",
} }
end end
end end

View File

@ -7,13 +7,13 @@
- include_role: - include_role:
name: kubernetes/any name: kubernetes/any
- include_role: - include_role:
name: kubernetes/controlplane name: kubernetes/control_plane
when: is_controlplane when: is_control_plane
- include_role: - include_role:
name: kubernetes/node name: kubernetes/node
when: not is_controlplane when: not is_control_plane
# - hosts: controlplane # - hosts: control_plane
# gather_facts: yes # gather_facts: yes
# become: yes # become: yes
# tasks: # tasks:

View File

@ -7,15 +7,15 @@
path: /etc/hosts path: /etc/hosts
state: present state: present
regexp: '^\d+\.\d+\.\d+\.\d+\ .*-cluster-endpoint$' regexp: '^\d+\.\d+\.\d+\.\d+\ .*-cluster-endpoint$'
line: "{{ controlplane_ip }} {{ cluster_name }}-cluster-endpoint" line: "{{ control_plane_endpoint }} {{ cluster_name }}-cluster-endpoint"
- name: Obtain join command from controlplane - name: Obtain join command from control_plane
ansible.builtin.command: "kubeadm token create --print-join-command" ansible.builtin.command: "kubeadm token create --print-join-command"
when: inventory_hostname != "controlplane" when: inventory_hostname != "control_plane"
register: join_cmd register: join_cmd
delegate_to: "{{ item }}" delegate_to: "{{ item }}"
delegate_facts: true delegate_facts: true
with_items: ["controlplane"] with_items: ["control_plane"]
- name: Execute join command - name: Execute join command
become: true become: true