87 lines
2.5 KiB
YAML
87 lines
2.5 KiB
YAML
- hosts: all
|
|
become: yes
|
|
|
|
tasks:
|
|
- name: update package cache
|
|
apt:
|
|
update_cache: yes
|
|
|
|
- name: install required packages
|
|
apt:
|
|
name:
|
|
- apt-transport-https
|
|
- ca-certificates
|
|
- curl
|
|
- gnupg
|
|
- containerd
|
|
state: present
|
|
|
|
- name: create br_netfilter
|
|
command: modprobe br_netfilter
|
|
|
|
- name: create a containerd directory
|
|
file:
|
|
path: /etc/containerd
|
|
state: directory
|
|
|
|
- name: generate containerd default configuration
|
|
command: containerd config default
|
|
register: containerd_output # Capture the output of the command
|
|
|
|
- name: save configuration to /home/kubew2/config.toml
|
|
copy:
|
|
content: "{{ containerd_output.stdout }}"
|
|
dest: $HOME/config.toml
|
|
|
|
- name: move it (can't directly create on /etc/containerd for some reason)
|
|
command: mv $HOME/config.toml /etc/containerd/config.toml
|
|
|
|
- name: update the containerd config.toml file
|
|
command: sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml
|
|
|
|
- name: turn off swap
|
|
command: swapoff -a
|
|
|
|
- name: uncomment net.ipv4.ip_forward in sysctl.conf
|
|
lineinfile:
|
|
path: /etc/sysctl.conf
|
|
regexp: '^#?net.ipv4.ip_forward='
|
|
line: 'net.ipv4.ip_forward=1'
|
|
state: present
|
|
|
|
- name: edit /proc/sys/net/ipv4/ip_forward
|
|
command: echo "1" | sudo tee /proc/sys/net/ipv4/ip_forward
|
|
|
|
- name: reload sysctl config
|
|
command: sysctl -p
|
|
|
|
- name: check if GPG key file exists
|
|
stat:
|
|
path: /etc/apt/keyrings/kubernetes-apt-keyring.gpg
|
|
register: gpg_key_file
|
|
|
|
|
|
- name: download Kubernetes GPG key
|
|
shell: curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
|
|
when: not gpg_key_file.stat.exists
|
|
|
|
|
|
- name: add Kubernetes repository
|
|
shell: echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
|
|
|
|
- name: update package cache after adding repository
|
|
apt:
|
|
update_cache: yes
|
|
|
|
- name: install Kubernetes components
|
|
apt:
|
|
name:
|
|
- kubelet
|
|
- kubeadm
|
|
- kubectl
|
|
state: present
|
|
|
|
- name: hold Kubernetes packages to prevent automatic updates
|
|
command: sudo apt-mark hold kubelet kubeadm kubectl
|
|
|