diff --git a/ansible/inventory/group_vars/kubernetes/k3s.yml b/ansible/inventory/group_vars/kubernetes/k3s.yml index 443c6335..eb83f640 100644 --- a/ansible/inventory/group_vars/kubernetes/k3s.yml +++ b/ansible/inventory/group_vars/kubernetes/k3s.yml @@ -30,30 +30,34 @@ k3s_registration_address: "{{ kubevip_address }}" k3s_server_manifests_urls: # Kube-vip - url: https://raw.githubusercontent.com/kube-vip/kube-vip/main/docs/manifests/rbac.yaml - filename: kube-vip-rbac.yaml + filename: custom-kube-vip-rbac.yaml # Tigera Operator - url: https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/tigera-operator.yaml - filename: calico-tigera-operator.yaml + filename: custom-calico-tigera-operator.yaml # Prometheus Operator - - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.61.1/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml - filename: prometheus-alertmanagerconfigs.yaml - - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.61.1/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagers.yaml - filename: prometheus-alertmanagers.yaml - - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.61.1/example/prometheus-operator-crd/monitoring.coreos.com_podmonitors.yaml - filename: prometheus-podmonitors.yaml - - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.61.1/example/prometheus-operator-crd/monitoring.coreos.com_probes.yaml - filename: prometheus-probes.yaml - - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.61.1/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml - filename: prometheus-prometheuses.yaml - - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.61.1/example/prometheus-operator-crd/monitoring.coreos.com_prometheusrules.yaml - filename: prometheus-prometheusrules.yaml - - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.61.1/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml - filename: prometheus-servicemonitors.yaml - - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.61.1/example/prometheus-operator-crd/monitoring.coreos.com_thanosrulers.yaml - filename: prometheus-thanosrulers.yaml + - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml + filename: custom-prometheus-alertmanagerconfigs.yaml + - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagers.yaml + filename: custom-prometheus-alertmanagers.yaml + - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_podmonitors.yaml + filename: custom-prometheus-podmonitors.yaml + - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_probes.yaml + filename: custom-prometheus-probes.yaml + - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml + filename: custom-prometheus-prometheuses.yaml + - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_prometheusrules.yaml + filename: custom-prometheus-prometheusrules.yaml + - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml + filename: custom-prometheus-servicemonitors.yaml + - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_thanosrulers.yaml + filename: custom-prometheus-thanosrulers.yaml + - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_scrapeconfigs.yaml + filename: custom-prometheus-scrapeconfigs.yaml + - url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml + filename: custom-prometheus-prometheusagents.yaml # (list) A flat list of templates to deploy on the primary control plane # /var/lib/rancher/k3s/server/manifests k3s_server_manifests_templates: - - calico-installation.yaml.j2 - - kube-vip-daemonset.yaml.j2 + - custom-calico-installation.yaml.j2 + - custom-kube-vip-daemonset.yaml.j2 diff --git a/ansible/playbooks/cluster-installation.yml b/ansible/playbooks/cluster-installation.yml index 7f93264a..e8bc8ade 100644 --- a/ansible/playbooks/cluster-installation.yml +++ b/ansible/playbooks/cluster-installation.yml @@ -10,18 +10,6 @@ ansible.builtin.pause: seconds: 5 tasks: - - name: Check if cluster is installed - check_mode: false - ansible.builtin.stat: - path: "/etc/rancher/k3s/config.yaml" - register: k3s_check_installed - - - name: Set manifest facts - ansible.builtin.set_fact: - k3s_server_manifests_templates: [] - k3s_server_manifests_urls: [] - when: k3s_check_installed.stat.exists - - name: Install Kubernetes ansible.builtin.include_role: name: xanmanning.k3s @@ -92,19 +80,20 @@ name: servicemonitors.monitoring.coreos.com - kind: CustomResourceDefinition name: thanosrulers.monitoring.coreos.com + - kind: CustomResourceDefinition + name: scrapeconfigs.monitoring.coreos.com + - kind: CustomResourceDefinition + name: prometheusagents.monitoring.coreos.com when: - k3s_server_manifests_templates | length > 0 or k3s_server_manifests_urls | length > 0 - k3s_control_node is defined - k3s_control_node - # Cleaning up the manifests from the /var/lib/rancher/k3s/server/manifests - # directory is needed because k3s has an awesome "feature" to always deploy - # these on restarting the k3s systemd service. Removing them does NOT - # uninstall the manifests. - - # Removing them means we can manage the lifecycle of these components - # outside of the /var/lib/rancher/k3s/server/manifests directory + # NOTE + # Cleaning up the manifests from the /var/lib/rancher/k3s/server/manifests directory + # is needed because k3s has an awesome "feature" to always re-deploy them when the k3s + # service is restarted. Removing them does not uninstall the manifests from your cluster. - name: Remove deployed manifest templates ansible.builtin.file: diff --git a/ansible/playbooks/cluster-nuke.yml b/ansible/playbooks/cluster-nuke.yml index eada1970..e238e56a 100644 --- a/ansible/playbooks/cluster-nuke.yml +++ b/ansible/playbooks/cluster-nuke.yml @@ -28,12 +28,14 @@ public: true vars: k3s_state: uninstalled + - name: Gather list of CNI files ansible.builtin.find: paths: /etc/cni/net.d patterns: "*" hidden: true register: directory_contents + - name: Delete CNI files ansible.builtin.file: path: "{{ item.path }}" diff --git a/ansible/playbooks/cluster-prepare.yml b/ansible/playbooks/cluster-prepare.yml index db1886c4..8d89f545 100644 --- a/ansible/playbooks/cluster-prepare.yml +++ b/ansible/playbooks/cluster-prepare.yml @@ -15,6 +15,7 @@ - name: Locale | Set timezone community.general.timezone: name: "{{ timezone | default('Etc/UTC') }}" + - name: Networking block: - name: Networking | Set hostname to inventory hostname @@ -25,6 +26,7 @@ path: /etc/hosts block: | 127.0.1.1 {{ inventory_hostname }} + - name: Packages | Fedora block: - name: Packages | Install required packages @@ -36,6 +38,7 @@ ansible.builtin.dnf: autoremove: true when: ansible_facts['distribution'] == 'Fedora' + - name: Packages | Ubuntu block: - name: Packages | Install required packages @@ -53,6 +56,7 @@ notify: Reboot when: "'raspi' in ansible_kernel" when: ansible_facts['distribution'] == 'Ubuntu' + - name: User Configuration block: - name: User Configuration | Add additional SSH public keys @@ -60,6 +64,7 @@ user: "{{ ansible_user }}" key: "{{ item }}" loop: "{{ public_ssh_keys | default([]) }}" + - name: System Configuration (1) block: - name: System Configuration (1) | Disable firewalld | Fedora @@ -80,6 +85,7 @@ ansible.builtin.systemd: service: fstrim.timer enabled: true + - name: System Configuration (2) block: - name: System Configuration (2) | Enable kernel modules now diff --git a/ansible/playbooks/templates/calico-installation.yaml.j2 b/ansible/playbooks/templates/custom-calico-installation.yaml.j2 similarity index 100% rename from ansible/playbooks/templates/calico-installation.yaml.j2 rename to ansible/playbooks/templates/custom-calico-installation.yaml.j2 diff --git a/ansible/playbooks/templates/kube-vip-daemonset.yaml.j2 b/ansible/playbooks/templates/custom-kube-vip-daemonset.yaml.j2 similarity index 100% rename from ansible/playbooks/templates/kube-vip-daemonset.yaml.j2 rename to ansible/playbooks/templates/custom-kube-vip-daemonset.yaml.j2