diff --git a/kubernetes/tasks/install/agent/install_k3s.yml b/kubernetes/tasks/install/agent/install_k3s.yml index 94a064a..2fd0ec6 100644 --- a/kubernetes/tasks/install/agent/install_k3s.yml +++ b/kubernetes/tasks/install/agent/install_k3s.yml @@ -1,13 +1,12 @@ - name: Install K3s agent command: /root/k3s_install.sh {{ type }} register: command - changed_when: "'No change detected' in command.stdout" + changed_when: "'No change detected' not in command.stdout" until: "command is not failed" retries: 2 delay: 10 -- name: Restart when config changed, but install already done +- name: Make sure service is started / restarted on config change service: - name: k3s - status: restarted - when: "inventory_hostname != groups['kubernetes'][0] and not command.changed and config.changed" + name: k3s-agent + state: "{{ 'restarted' if not command.changed and config.changed else 'started' }}" diff --git a/kubernetes/tasks/install/server/install_k3s.yml b/kubernetes/tasks/install/server/install_k3s.yml index b4a3076..5454e48 100644 --- a/kubernetes/tasks/install/server/install_k3s.yml +++ b/kubernetes/tasks/install/server/install_k3s.yml @@ -2,13 +2,13 @@ command: /root/k3s_install.sh {{ type }} when: "inventory_hostname == groups['kubernetes'][0]" register: command - changed_when: "'No change detected' in command.stdout" + changed_when: "'No change detected' not in command.stdout" -- name: Restart when config changed, but install already done +- name: Make sure service is started / restarted on config change service: name: k3s - status: restarted - when: "inventory_hostname == groups['kubernetes'][0] and not command.changed and config.changed" + state: "{{ 'restarted' if not command.changed and config.changed else 'started' }}" + when: "inventory_hostname == groups['kubernetes'][0]" - name: Waiting for K3s-server to accept connections ansible.builtin.wait_for: @@ -21,16 +21,16 @@ command: /root/k3s_install.sh {{ type }} when: "inventory_hostname != groups['kubernetes'][0]" register: command - changed_when: "'No change detected' in command.stdout" + changed_when: "'No change detected' not in command.stdout" until: "command is not failed" retries: 2 delay: 10 -- name: Restart when config changed, but install already done +- name: Make sure service is started / restarted on config change service: name: k3s - status: restarted - when: "inventory_hostname != groups['kubernetes'][0] and not command.changed and config.changed" + state: "{{ 'restarted' if not command.changed and config.changed else 'started' }}" + when: "inventory_hostname != groups['kubernetes'][0]" - name: Waiting for K3s-server to accept connections on other nodes ansible.builtin.wait_for: diff --git a/kubernetes/tasks/install/server/network-plugin/deploy_calico.yml b/kubernetes/tasks/install/server/network-plugin/deploy_calico.yml index 7cd2955..8c8a802 100644 --- a/kubernetes/tasks/install/server/network-plugin/deploy_calico.yml +++ b/kubernetes/tasks/install/server/network-plugin/deploy_calico.yml @@ -3,6 +3,8 @@ register: command changed_when: "'created' in command.stdout" run_once: true + failed_when: + - "command.rc == 1 and 'AlreadyExists' not in command.stderr" - name: Deploy calico ressource template ansible.builtin.template: diff --git a/kubernetes/templates/k3s/agent/config.yaml.jinja2 b/kubernetes/templates/k3s/agent/config.yaml.jinja2 index f42ec8e..91c6644 100644 --- a/kubernetes/templates/k3s/agent/config.yaml.jinja2 +++ b/kubernetes/templates/k3s/agent/config.yaml.jinja2 @@ -1,11 +1,8 @@ -server: https://{{ kubernetes.control_plane.dns_name }}:6443 +server: https://{{ hostvars[groups['kubernetes'][0]]['nodeip_ipv4'] }}:6443 token: '{{ kubernetes.token }}' {% if nodeip_ipv6 != "" and kubernetes.ipPool.ipv6 is defined %} node-ip: {{ nodeip_ipv4 }},{{ nodeip_ipv6 }} - -# FIXME: Workaround for bug in Kubernetes 1.24/1.25 ignoring node IPv6 addresses -kubelet-arg: "--node-ip=0.0.0.0" {% else %} node-ip: {{ nodeip_ipv4 }} {% endif %} diff --git a/kubernetes/templates/k3s/server/config.yaml.jinja2 b/kubernetes/templates/k3s/server/config.yaml.jinja2 index ab58922..d9168b2 100644 --- a/kubernetes/templates/k3s/server/config.yaml.jinja2 +++ b/kubernetes/templates/k3s/server/config.yaml.jinja2 @@ -15,9 +15,6 @@ tls-san: node-ip: {{ nodeip_ipv4 }},{{ nodeip_ipv6 }} cluster-cidr: {{ kubernetes.ipPool.ipv4.cluster_cidr }},{{ kubernetes.ipPool.ipv6.cluster_cidr }} service-cidr: {{ kubernetes.ipPool.ipv4.service_cidr }},{{ kubernetes.ipPool.ipv6.service_cidr }} - -# FIXME: Workaround for bug in Kubernetes 1.24/1.25 ignoring node IPv6 addresses -kubelet-arg: "--node-ip=0.0.0.0" {% else %} node-ip: {{ nodeip_ipv4 }} cluster-cidr: {{ kubernetes.ipPool.ipv4.cluster_cidr }} @@ -27,7 +24,7 @@ service-cidr: {{ kubernetes.ipPool.ipv4.service_cidr }} egress-selector-mode: disabled # Network-plugin -{% if kubernetes.network_plugin == "flannel" %} +{% if kubernetes.network.plugin == "flannel" %} flannel-backend: vxlan {% else %} disable-network-policy: true