You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.2 KiB
76 lines
2.2 KiB
- name: Install Kube tools (Kubeadm, Kubelet, Kubectl) using OS tools
|
|
hosts: all
|
|
become: yes
|
|
become_method: sudo
|
|
become_user: root
|
|
tasks:
|
|
- name: Install apt tools and accesories
|
|
package:
|
|
name: "{{ item }}"
|
|
state: present
|
|
with_items:
|
|
- "apt-transport-https"
|
|
- "ca-certificates"
|
|
- "curl"
|
|
- "gpg"
|
|
- name: Creates keyrings directory
|
|
file:
|
|
path: /etc/apt/keyrings
|
|
state: directory
|
|
mode: '755'
|
|
- name: Check if keyring exists
|
|
stat:
|
|
path: /etc/apt/keyrings/kubernetes-apt-keyring.gpg
|
|
register: keyring_file
|
|
- name: Install certificate
|
|
command: "{{ item }} chdir=/tmp"
|
|
with_items:
|
|
- "curl -o Release.key -fsSL https://pkgs.k8s.io/core:/stable:/{{ K8S_VERSION }}/deb/Release.key"
|
|
- "gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg Release.key"
|
|
- "rm Release.key"
|
|
when: not keyring_file.stat.exists
|
|
- name: Check if apt repo exists
|
|
stat:
|
|
path: /etc/apt/sources.list.d/kubernetes.list
|
|
register: apt_repo
|
|
- name: Setup APT repo
|
|
copy:
|
|
dest: /etc/apt/sources.list.d/kubernetes.list
|
|
content: "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/{{ K8S_VERSION }}/deb/ /"
|
|
when: not apt_repo.stat.exists
|
|
- name: Update cache
|
|
apt:
|
|
update_cache: yes
|
|
- name: Setup tools
|
|
package:
|
|
name: "{{ item }}"
|
|
state: present
|
|
with_items:
|
|
- "kubelet"
|
|
- "kubeadm"
|
|
- "kubectl"
|
|
- name: Hold packages
|
|
dpkg_selections:
|
|
name: "{{ item }}"
|
|
selection: hold
|
|
with_items:
|
|
- "kubelet"
|
|
- "kubeadm"
|
|
- name: Check /etc/default/kubelet
|
|
stat:
|
|
path: /etc/default/kubelet
|
|
register: kubelet_defaults
|
|
- name: Create /etc/default/kubelet
|
|
copy:
|
|
dest: /etc/default/kubelet
|
|
content: "KUBELET_EXTRA_ARGS=\"--container-runtime-endpoint=unix:///run/containerd/containerd.sock\""
|
|
when: not kubelet_defaults.stat.exists
|
|
- name: Set containerd in extraargs
|
|
blockinfile:
|
|
dest: /etc/default/kubelet
|
|
block: "KUBELET_EXTRA_ARGS=\"--container-runtime-endpoint=unix:///run/containerd/containerd.sock\""
|
|
- name: Start kubelet
|
|
service:
|
|
name: kubelet
|
|
enabled: true
|
|
state: started |