2023-08-13 17:21:15 +00:00
|
|
|
---
|
2024-07-27 16:41:57 +00:00
|
|
|
- name: Reconfigure Kubernetes worker nodes
|
|
|
|
hosts:
|
|
|
|
- storage
|
|
|
|
- workers
|
|
|
|
tasks:
|
|
|
|
- name: Configure grub defaults
|
|
|
|
copy:
|
|
|
|
dest: "/etc/default/grub"
|
|
|
|
content: |
|
|
|
|
GRUB_DEFAULT=0
|
|
|
|
GRUB_TIMEOUT_STYLE=countdown
|
|
|
|
GRUB_TIMEOUT=5
|
|
|
|
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
|
|
|
|
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash memhp_default_state=online"
|
|
|
|
GRUB_CMDLINE_LINUX="memhp_default_state=online rootflags=pquota"
|
|
|
|
register: grub_defaults
|
2024-07-28 17:06:04 +00:00
|
|
|
when: ansible_architecture == 'x86_64'
|
|
|
|
|
2024-08-08 15:54:48 +00:00
|
|
|
|
2024-07-27 16:41:57 +00:00
|
|
|
- name: Load grub defaults
|
|
|
|
ansible.builtin.shell: update-grub
|
2024-08-08 15:54:48 +00:00
|
|
|
when: grub_defaults.changed
|
2024-07-27 16:41:57 +00:00
|
|
|
|
2024-07-28 17:06:04 +00:00
|
|
|
- name: Ensure nfs-common is installed
|
|
|
|
ansible.builtin.apt:
|
|
|
|
name: nfs-common
|
|
|
|
state: present
|
|
|
|
|
2024-07-26 22:05:55 +00:00
|
|
|
- name: Reconfigure Kubernetes nodes
|
2023-08-15 18:58:23 +00:00
|
|
|
hosts: kubernetes
|
2024-07-26 22:05:55 +00:00
|
|
|
vars:
|
2024-08-08 16:45:46 +00:00
|
|
|
KUBERNETES_VERSION: v1.30.3
|
|
|
|
IP: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
|
2023-08-15 18:58:23 +00:00
|
|
|
tasks:
|
2024-07-26 22:05:55 +00:00
|
|
|
- name: Remove APT packages
|
|
|
|
ansible.builtin.apt:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: absent
|
|
|
|
loop:
|
|
|
|
- kubelet
|
|
|
|
- kubeadm
|
|
|
|
- kubectl
|
|
|
|
|
2024-07-27 08:46:39 +00:00
|
|
|
- name: Download kubectl, kubeadm, kubelet
|
2024-07-26 22:05:55 +00:00
|
|
|
ansible.builtin.get_url:
|
2024-07-27 08:46:39 +00:00
|
|
|
url: "https://cdn.dl.k8s.io/release/{{ KUBERNETES_VERSION }}/bin/linux/{{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }}/{{ item }}"
|
|
|
|
dest: "/usr/bin/{{ item }}-{{ KUBERNETES_VERSION }}"
|
2024-07-26 22:05:55 +00:00
|
|
|
mode: '0755'
|
2024-07-27 08:46:39 +00:00
|
|
|
loop:
|
|
|
|
- kubelet
|
|
|
|
- kubectl
|
|
|
|
- kubeadm
|
2024-07-26 22:05:55 +00:00
|
|
|
|
2024-07-27 08:46:39 +00:00
|
|
|
- name: Create symlinks for kubectl, kubeadm, kubelet
|
|
|
|
ansible.builtin.file:
|
|
|
|
src: "/usr/bin/{{ item }}-{{ KUBERNETES_VERSION }}"
|
|
|
|
dest: "/usr/bin/{{ item }}"
|
|
|
|
state: link
|
|
|
|
loop:
|
|
|
|
- kubelet
|
|
|
|
- kubectl
|
|
|
|
- kubeadm
|
|
|
|
register: kubelet
|
2024-07-26 22:05:55 +00:00
|
|
|
|
2024-07-27 08:46:39 +00:00
|
|
|
- name: Restart Kubelet
|
|
|
|
service:
|
|
|
|
name: kubelet
|
|
|
|
enabled: true
|
|
|
|
state: restarted
|
|
|
|
when: kubelet.changed
|
2024-07-26 22:05:55 +00:00
|
|
|
|
|
|
|
- name: Create /etc/systemd/system/kubelet.service
|
|
|
|
ansible.builtin.copy:
|
|
|
|
content: |
|
|
|
|
[Unit]
|
|
|
|
Description=kubelet: The Kubernetes Node Agent
|
|
|
|
Documentation=https://kubernetes.io/docs/home/
|
|
|
|
Wants=network-online.target
|
|
|
|
After=network-online.target
|
|
|
|
[Service]
|
|
|
|
ExecStart=/usr/local/bin/kubelet
|
|
|
|
Restart=always
|
|
|
|
StartLimitInterval=0
|
|
|
|
RestartSec=10
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
dest: /etc/systemd/system/kubelet.service
|
|
|
|
|
2023-08-15 18:58:23 +00:00
|
|
|
- name: Reconfigure shutdownGracePeriod
|
|
|
|
ansible.builtin.lineinfile:
|
|
|
|
path: /var/lib/kubelet/config.yaml
|
|
|
|
regexp: '^shutdownGracePeriod:'
|
|
|
|
line: 'shutdownGracePeriod: 5m'
|
2024-07-26 22:05:55 +00:00
|
|
|
|
2023-08-15 18:58:23 +00:00
|
|
|
- name: Reconfigure shutdownGracePeriodCriticalPods
|
|
|
|
ansible.builtin.lineinfile:
|
|
|
|
path: /var/lib/kubelet/config.yaml
|
|
|
|
regexp: '^shutdownGracePeriodCriticalPods:'
|
|
|
|
line: 'shutdownGracePeriodCriticalPods: 5m'
|
2024-07-26 22:05:55 +00:00
|
|
|
|
2023-08-15 19:41:54 +00:00
|
|
|
- name: Work around unattended-upgrades
|
|
|
|
ansible.builtin.lineinfile:
|
|
|
|
path: /lib/systemd/logind.conf.d/unattended-upgrades-logind-maxdelay.conf
|
|
|
|
regexp: '^InhibitDelayMaxSec='
|
|
|
|
line: 'InhibitDelayMaxSec=5m0s'
|
2023-08-15 18:58:23 +00:00
|
|
|
|
2024-07-26 22:05:55 +00:00
|
|
|
- name: Disable unneccesary services
|
|
|
|
ignore_errors: true
|
2023-08-13 17:21:15 +00:00
|
|
|
loop:
|
2024-07-26 22:05:55 +00:00
|
|
|
- gdm3
|
|
|
|
- snapd
|
|
|
|
- bluetooth
|
|
|
|
- multipathd
|
|
|
|
service:
|
|
|
|
name: "{{item}}"
|
|
|
|
state: stopped
|
|
|
|
enabled: no
|
|
|
|
|
|
|
|
- name: Reset /etc/containers/registries.conf
|
2023-08-13 17:21:15 +00:00
|
|
|
ansible.builtin.copy:
|
2024-07-26 22:05:55 +00:00
|
|
|
content: "unqualified-search-registries = [\"docker.io\"]\n"
|
|
|
|
dest: /etc/containers/registries.conf
|
|
|
|
register: registries
|
2023-08-13 17:21:15 +00:00
|
|
|
|
2024-07-26 22:05:55 +00:00
|
|
|
- name: Restart CRI-O
|
|
|
|
service:
|
|
|
|
name: cri-o
|
|
|
|
state: restarted
|
|
|
|
when: registries.changed
|
2023-08-13 17:21:15 +00:00
|
|
|
|
2024-07-26 22:05:55 +00:00
|
|
|
- name: Reset /etc/modules
|
|
|
|
ansible.builtin.copy:
|
|
|
|
content: |
|
|
|
|
overlay
|
|
|
|
br_netfilter
|
|
|
|
dest: /etc/modules
|
|
|
|
register: kernel_modules
|
|
|
|
- name: Load kernel modules
|
|
|
|
ansible.builtin.shell: "cat /etc/modules | xargs -L 1 -t modprobe"
|
|
|
|
when: kernel_modules.changed
|
2023-08-13 17:21:15 +00:00
|
|
|
|
2024-07-26 22:05:55 +00:00
|
|
|
- name: Reset /etc/sysctl.d/99-k8s.conf
|
|
|
|
ansible.builtin.copy:
|
|
|
|
content: |
|
|
|
|
net.ipv4.conf.all.accept_redirects = 0
|
|
|
|
net.bridge.bridge-nf-call-iptables = 1
|
|
|
|
net.ipv4.ip_forward = 1
|
|
|
|
net.bridge.bridge-nf-call-ip6tables = 1
|
|
|
|
vm.max_map_count = 524288
|
|
|
|
fs.inotify.max_user_instances = 1280
|
|
|
|
fs.inotify.max_user_watches = 655360
|
|
|
|
dest: /etc/sysctl.d/99-k8s.conf
|
|
|
|
register: sysctl
|
|
|
|
|
|
|
|
- name: Reload sysctl config
|
|
|
|
ansible.builtin.shell: "sysctl --system"
|
|
|
|
when: sysctl.changed
|
2024-07-27 11:24:53 +00:00
|
|
|
|
2024-08-08 16:45:46 +00:00
|
|
|
- name: Reconfigure kube-apiserver to use Passmower OIDC endpoint
|
2024-07-27 11:24:53 +00:00
|
|
|
ansible.builtin.template:
|
|
|
|
src: kube-apiserver.j2
|
|
|
|
dest: /etc/kubernetes/manifests/kube-apiserver.yaml
|
|
|
|
mode: 600
|
2024-08-08 16:45:46 +00:00
|
|
|
register: apiserver
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups["masters"]
|
|
|
|
|
|
|
|
- name: Restart kube-apiserver
|
|
|
|
ansible.builtin.shell: "killall kube-apiserver"
|
|
|
|
when: apiserver.changed
|