104 lines
2.8 KiB
YAML
104 lines
2.8 KiB
YAML
---
|
|
# tasks file for k8s_common
|
|
|
|
- name: Disable swap
|
|
ansible.builtin.command: swapoff -a
|
|
become: true
|
|
|
|
- name: Add Docker APT repository key
|
|
ansible.builtin.apt_key:
|
|
url: https://download.docker.com/linux/ubuntu/gpg
|
|
|
|
- name: Add Docker APT repository
|
|
ansible.builtin.apt_repository:
|
|
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable
|
|
|
|
- name: create an empty file for the Containerd module
|
|
ansible.builtin.copy:
|
|
content: ""
|
|
dest: /etc/modules-load.d/containerd.conf
|
|
force: no
|
|
|
|
- name: configure modules for Containerd
|
|
ansible.builtin.blockinfile:
|
|
path: /etc/modules-load.d/containerd.conf
|
|
block: |
|
|
overlay
|
|
br_netfilter
|
|
|
|
- name: Install required packages
|
|
ansible.builtin.apt:
|
|
name: "{{ item }}"
|
|
state: latest
|
|
become: true
|
|
loop:
|
|
- docker-ce
|
|
- docker-ce-cli
|
|
- curl
|
|
- apt-transport-https
|
|
- containerd.io
|
|
|
|
- name: create Containerd directory
|
|
ansible.builtin.file:
|
|
path: /etc/containerd
|
|
state: directory
|
|
|
|
- name: add Containerd configuration
|
|
ansible.builtin.shell: /usr/bin/containerd config default > /etc/containerd/config.toml
|
|
|
|
- name: configuring the systemd cgroup driver for Containerd
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/containerd/config.toml
|
|
regexp: 'SystemdCgroup = false'
|
|
line: 'SystemdCgroup = true'
|
|
|
|
- name: enable the Containerd service and start it
|
|
systemd:
|
|
name: containerd
|
|
state: restarted
|
|
enabled: yes
|
|
daemon-reload: yes
|
|
|
|
- name: Add Kubernetes APT key
|
|
ansible.builtin.shell: curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
|
|
become: true
|
|
|
|
- name: Add Kubernetes repository
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/apt/sources.list
|
|
line: "deb https://apt.kubernetes.io/ kubernetes-xenial main"
|
|
state: present
|
|
become: true
|
|
|
|
- name: Update apt cache
|
|
ansible.builtin.apt:
|
|
update_cache: yes
|
|
become: true
|
|
|
|
- name: Install Kubernetes packages
|
|
ansible.builtin.package:
|
|
name: "{{ item }}"
|
|
state: latest
|
|
become: true
|
|
loop:
|
|
- kubectl
|
|
- kubeadm
|
|
- kubelet
|
|
- kubernetes-cni
|
|
|
|
- name: enable the Kubelet service, and enable it persistently
|
|
service:
|
|
name: kubelet
|
|
enabled: yes
|
|
|
|
- name: check Kubelet args in Kubelet config
|
|
ansible.builtin.shell: grep "^Environment=\"KUBELET_EXTRA_ARGS=" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf || true
|
|
register: check_args
|
|
|
|
- name: add runtime args in Kubelet config
|
|
ansible.builtin.lineinfile:
|
|
dest: "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf"
|
|
line: "Environment=\"KUBELET_EXTRA_ARGS= --runtime-cgroups=/system.slice/containerd.service --container-runtime-endpoint=unix:///run/containerd/containerd.sock\""
|
|
insertafter: '\[Service\]'
|
|
when: check_args.stdout == ""
|