Обновить ansible/k8s_setup.yml

This commit is contained in:
2025-12-28 18:20:01 +00:00
parent b392c330b3
commit 675a14c3f5

View File

@@ -1,11 +1,11 @@
---
- name: Подготовка всех узлов (Master и Workers)
hosts: masters,workers
hosts: k8s_nodes
become: true
gather_facts: true
tasks:
- name: 0. Ожидание разблокировки APT
shell: "while fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; do sleep 5; done;"
- name: 0. Ожидание разблокировки APT (усиленное)
shell: "while fuser /var/lib/dpkg/lock-frontend /var/lib/apt/lists/lock /var/lib/dpkg/lock >/dev/null 2>&1; do sleep 5; done;"
changed_when: false
- name: 1. Очистка старых конфигов K8s
@@ -18,11 +18,15 @@
ip link set dev eth0 mtu 1442 || true
changed_when: false
- name: 3. Установка базовых зависимостей
- name: 3. Установка системных зависимостей (с повторами)
apt:
update_cache: yes
name: [apt-transport-https, ca-certificates, curl, gnupg, qemu-guest-agent, socat, conntrack]
state: present
register: apt_res
until: apt_res is success
retries: 20
delay: 10
- name: 4. Отключение SWAP
shell: |
@@ -46,6 +50,10 @@
apt:
name: containerd
state: present
register: cont_res
until: cont_res is success
retries: 10
delay: 5
- name: 7. Конфигурация Containerd (SystemdCgroup)
shell: |
@@ -62,9 +70,8 @@
register: key_res
until: key_res is success
retries: 5
delay: 5
- name: 9. Настройка репозитория (Зеркало Tsinghua)
- name: 9. Настройка репозитория (Tsinghua)
copy:
dest: /etc/apt/sources.list.d/kubernetes.list
content: "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/kubernetes/core:/stable:/v1.32/deb/ /"
@@ -75,25 +82,25 @@
state: present
update_cache: yes
allow_change_held_packages: yes
register: k8s_res
until: k8s_res is success
retries: 10
delay: 10
- name: 11. Фиксация версий
shell: apt-mark hold kubelet kubeadm kubectl
changed_when: false
- name: Инициализация Master-ноды
hosts: masters
hosts: masters_group
become: true
tasks:
- name: Проверка инициализации
stat:
path: /etc/kubernetes/admin.conf
register: kube_init
- name: Kubeadm Init
shell: "kubeadm init --pod-network-cidr=10.244.0.0/16 --skip-phases=addon/kube-proxy"
when: not kube_init.stat.exists
args:
creates: /etc/kubernetes/admin.conf
- name: Настройка конфига для пользователя ubuntu
- name: Настройка конфига для ubuntu
shell: |
mkdir -p /home/ubuntu/.kube
cp -f /etc/kubernetes/admin.conf /home/ubuntu/.kube/config
@@ -110,24 +117,13 @@
join_command: "{{ join_command_raw.stdout }}"
- name: Подключение Worker-нод
hosts: workers
hosts: workers_group
become: true
tasks:
- name: Join к кластеру
shell: "{{ hostvars[groups['masters'][0]]['join_command'] }}"
shell: "{{ hostvars[groups['masters_group'][0]]['join_command'] }}"
args:
creates: /etc/kubernetes/kubelet.conf
- name: Установка Cilium (eBPF)
hosts: masters
become: false
tasks:
- name: Установка Cilium CLI и CNI
shell: |
if [ ! -f /usr/local/bin/cilium ]; then
curl -L --remote-name-all https://github.com/cilium/cilium-cli/releases/latest/download/cilium-linux-amd64.tar.gz
sudo tar xzvf cilium-linux-amd64.tar.gz -C /usr/local/bin
rm cilium-linux-amd64.tar.gz
fi
cilium install --set kubeProxyReplacement=true
ignore_errors: true
- name: Stage 4 - Post-install (CNI & MetalLB)
import_playbook: k8s_post_install.yml