Create and stated write role for deploy k8s cluster
This commit is contained in:
79
ansible/roles/k8s-deploy-cluster/tasks/k8s-pre.yml
Normal file
79
ansible/roles/k8s-deploy-cluster/tasks/k8s-pre.yml
Normal file
@ -0,0 +1,79 @@
|
||||
---
|
||||
- name: Turn off swap
|
||||
command: swapoff -a
|
||||
when: ansible_swaptotal_mb > 0
|
||||
|
||||
- name: Delete swap from /etc/fstab
|
||||
replace:
|
||||
path: /etc/fstab
|
||||
regexp: '^\s*([^#\s]+\s+){2}swap\s+.*$'
|
||||
replace: '# \1swap was disabled by Ansible'
|
||||
|
||||
- name: Setup sysctl for k8s
|
||||
copy:
|
||||
dest: /etc/sysctl.d/k8s.conf
|
||||
content: |
|
||||
net.bridge.bridge-nf-call-iptables=1
|
||||
net.ipv4.ip_forward=1
|
||||
net.bridge.bridge-nf-call-ip6tables=1
|
||||
|
||||
notify: Reload_sysctl
|
||||
|
||||
- name: Check if Kubernetes keyring already exists
|
||||
stat:
|
||||
path: /etc/apt/keyrings/kubernetes-apt-keyring.gpg
|
||||
register: kube_keyring
|
||||
|
||||
- name: Download Kubernetes apt GPG key
|
||||
get_url:
|
||||
url: "{{ k8s_apt_key_url }}"
|
||||
dest: "/tmp/kubernetes-apt-keyring.key"
|
||||
when: not kube_keyring.stat.exists
|
||||
|
||||
- name: Convert Kubernetes key to GPG format
|
||||
command: >
|
||||
gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg /tmp/kubernetes-apt-keyring.key
|
||||
|
||||
args:
|
||||
creates: /etc/apt/keyrings/kubernetes-apt-keyring.gpg
|
||||
when: not kube_keyring.stat.exists
|
||||
|
||||
|
||||
- name: Add Kubernetes apt repository
|
||||
apt_repository:
|
||||
repo: "{{ k8s_repo_url }}"
|
||||
filename: "kubernetes"
|
||||
state: present
|
||||
|
||||
- name: Run "apt update / upgrade"
|
||||
apt:
|
||||
upgrade: yes
|
||||
update_cache: yes
|
||||
retries: 10
|
||||
delay: 30
|
||||
|
||||
- name: Install k8s pkgs
|
||||
apt:
|
||||
pkg: "{{ k8s_pkg_list }}"
|
||||
state: present
|
||||
|
||||
- name: Configure containerd
|
||||
shell: |
|
||||
containerd config default > /etc/containerd/config.toml
|
||||
|
||||
args:
|
||||
creates: /etc/containerd/config.toml
|
||||
|
||||
- name: Ensure SystemdCgroup = true
|
||||
replace:
|
||||
path: /etc/containerd/config.toml
|
||||
regexp: '^(\s*SystemdCgroup\s*=\s*)false'
|
||||
replace: '\1true'
|
||||
notify: Restart_containerd
|
||||
|
||||
- name: Update pause image to 3.9
|
||||
replace:
|
||||
path: /etc/containerd/config.toml
|
||||
regexp: 'registry.k8s.io/pause:3.6'
|
||||
replace: 'registry.k8s.io/pause:3.9'
|
||||
notify: Restart_containerd
|
Reference in New Issue
Block a user