ansible-playbooks/k8s/roles/common-kubernetes/tasks/main.yml

106 lines
3.0 KiB
YAML

# Это базовое ядро, необходимое для инициализации кластера K8s
# Данную роль необходимо использовать на всех узлах кластера.
- name: Update and upgrade apt packages
apt:
update_cache: yes
upgrade: dist
autoremove: yes
- name: Remove existing Kubernetes repository if it exists
file:
path: /etc/apt/sources.list.d/kubernetes.list
state: absent
- name: Remove existing Kubernetes GPG key if it exists
file:
path: /etc/apt/keyrings/kubernetes-apt-keyring.gpg
state: absent
- name: Remove existing CRI-O repository if it exists
file:
path: /etc/apt/sources.list.d/cri-o.list
state: absent
- name: Remove existing CRI-O GPG key if it exists
file:
path: /etc/apt/keyrings/cri-o-apt-keyring.gpg
state: absent
- name: Disable swap
shell: |
swapoff -a
sed -i '/swap/d' /etc/fstab
- name: Load overlay kernel module
modprobe:
name: overlay
state: present
- name: Load br_netfilter kernel module
modprobe:
name: br_netfilter
state: present
- name: Ensure overlay is added to /etc/modules
lineinfile:
path: /etc/modules
line: "overlay"
create: yes
state: present
- name: Ensure br_netfilter is added to /etc/modules
lineinfile:
path: /etc/modules
line: "br_netfilter"
create: yes
state: present
- name: Enable ip_forward
sysctl:
name: net.ipv4.ip_forward
value: 1
state: present
- name: Ensure IPv4 forwarding is enabled permanently
lineinfile:
path: /etc/sysctl.conf
line: "net.ipv4.ip_forward=1"
regexp: "^net.ipv4.ip_forward="
state: present
- name: Install required packages
apt:
name:
- software-properties-common
- apt-transport-https
- ca-certificates
- gnupg2
- gpg
- curl
- iptables
state: present
- name: Download K8s GPG key
shell: |
curl -fsSL https://pkgs.k8s.io/core:/stable:/{{ k8s_version }}/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
- name: Add K8s repository
shell: |
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/{{ k8s_version }}/deb/ /' | tee /etc/apt/sources.list.d/kubernetes.list
- name: Installing kubectl, kubeadm, kubelet
apt:
update_cache: yes
name:
- kubelet
- kubeadm
- kubectl
- name: Disable auto upgrade
command: apt-mark hold kubectl kubeadm kubelet
- name: Download cri-o GPG key
shell: |
curl -fsSL https://pkgs.k8s.io/addons:/cri-o:/stable:/{{crio_version}}/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/cri-o-apt-keyring.gpg
- name: Add cri-o repository
shell: |
echo "deb [signed-by=/etc/apt/keyrings/cri-o-apt-keyring.gpg] https://pkgs.k8s.io/addons:/cri-o:/stable:/{{crio_version}}/deb/ /" | tee /etc/apt/sources.list.d/cri-o.list
- name: Installing cri-o
apt:
update_cache: yes
name:
- cri-o
- name: Enable and starting cri-o
systemd:
name: crio
state: started
enabled: true