diff --git a/playbooks/kubernetes/Vagrantfile b/playbooks/kubernetes/Vagrantfile index 3e3a8a5..22b5ab6 100644 --- a/playbooks/kubernetes/Vagrantfile +++ b/playbooks/kubernetes/Vagrantfile @@ -1,6 +1,6 @@ IMAGE_NAME = "bento/ubuntu-22.04" -CONTROLPLANE_IP = "192.168.56.11" -NODES = 1 +CONTROL_PLANES = 1 +NODES = 0 Vagrant.configure("2") do |config| config.ssh.insert_key = false @@ -10,17 +10,19 @@ Vagrant.configure("2") do |config| v.cpus = 2 end - config.vm.define "controlplane" do |master| - master.vm.box = IMAGE_NAME - master.vm.network "private_network", ip: CONTROLPLANE_IP - master.vm.hostname = "controlplane" - master.vm.provision "ansible" do |ansible| - ansible.playbook = "playbook.yaml" - ansible.extra_vars = { - cluster_name: "gerar", - node_ip: CONTROLPLANE_IP, - is_controlplane: true, - } + (1..CONTROL_PLANES).each do |i| + config.vm.define "control-plane-#{i}" do |control_plane| + control_plane.vm.box = IMAGE_NAME + control_plane.vm.network "private_network", ip: "192.168.56.#{10 + i}" + control_plane.vm.hostname = "control-plane-#{i}" + control_plane.vm.provision "ansible" do |ansible| + ansible.playbook = "playbook.yaml" + ansible.extra_vars = { + cluster_name: "gerar", + node_ip: "192.168.56.#{10 + i}", + is_control_plane: true, + } + end end end @@ -30,12 +32,12 @@ Vagrant.configure("2") do |config| node.vm.network "private_network", ip: "192.168.56.#{20 + i}" node.vm.hostname = "node-#{i}" node.vm.provision "ansible" do |ansible| - ansible.playbook = "playbook.yaml" + ansible.playbook = "playbook.yaml" ansible.extra_vars = { cluster_name: "gerar", node_ip: "192.168.56.#{20 + i}", - controlplane_ip: CONTROLPLANE_IP, - is_controlplane: false, + is_control_plane: false, + control_plane_endpoint: "192.168.56.11", } end end diff --git a/playbooks/kubernetes/playbook.yaml b/playbooks/kubernetes/playbook.yaml index 6ad99a8..1280a54 100644 --- a/playbooks/kubernetes/playbook.yaml +++ b/playbooks/kubernetes/playbook.yaml @@ -7,13 +7,13 @@ - include_role: name: kubernetes/any - include_role: - name: kubernetes/controlplane - when: is_controlplane + name: kubernetes/control_plane + when: is_control_plane - include_role: name: kubernetes/node - when: not is_controlplane + when: not is_control_plane -# - hosts: controlplane +# - hosts: control_plane # gather_facts: yes # become: yes # tasks: diff --git a/roles/kubernetes/controlplane/files/calico/v3.24.5/custom-resources.yaml b/roles/kubernetes/control_plane/files/calico/v3.24.5/custom-resources.yaml similarity index 100% rename from roles/kubernetes/controlplane/files/calico/v3.24.5/custom-resources.yaml rename to roles/kubernetes/control_plane/files/calico/v3.24.5/custom-resources.yaml diff --git a/roles/kubernetes/controlplane/files/calico/v3.24.5/tigera-operator.yaml b/roles/kubernetes/control_plane/files/calico/v3.24.5/tigera-operator.yaml similarity index 100% rename from roles/kubernetes/controlplane/files/calico/v3.24.5/tigera-operator.yaml rename to roles/kubernetes/control_plane/files/calico/v3.24.5/tigera-operator.yaml diff --git a/roles/kubernetes/controlplane/tasks/main.yml b/roles/kubernetes/control_plane/tasks/main.yml similarity index 100% rename from roles/kubernetes/controlplane/tasks/main.yml rename to roles/kubernetes/control_plane/tasks/main.yml diff --git a/roles/kubernetes/node/tasks/main.yml b/roles/kubernetes/node/tasks/main.yml index 2c43889..3f9db44 100644 --- a/roles/kubernetes/node/tasks/main.yml +++ b/roles/kubernetes/node/tasks/main.yml @@ -7,15 +7,15 @@ path: /etc/hosts state: present 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" - when: inventory_hostname != "controlplane" + when: inventory_hostname != "control_plane" register: join_cmd delegate_to: "{{ item }}" delegate_facts: true - with_items: ["controlplane"] + with_items: ["control_plane"] - name: Execute join command become: true