recover docker + containerd install
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
---
|
||||
# ansible/tasks/kubernetes/debug-containerd.yml
|
||||
|
||||
- name: Get containerd status
|
||||
command: systemctl status containerd
|
||||
register: containerd_status
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
|
||||
- name: Display containerd status
|
||||
debug:
|
||||
var: containerd_status.stdout_lines
|
||||
|
||||
- name: Get containerd configuration
|
||||
command: cat /etc/containerd/config.toml
|
||||
register: containerd_config
|
||||
changed_when: false
|
||||
|
||||
- name: Display containerd configuration
|
||||
debug:
|
||||
var: containerd_config.stdout_lines
|
||||
|
||||
- name: Fix containerd configuration directly
|
||||
block:
|
||||
- name: Create a minimal containerd configuration
|
||||
copy:
|
||||
content: |
|
||||
version = 2
|
||||
|
||||
[plugins]
|
||||
[plugins."io.containerd.grpc.v1.cri"]
|
||||
sandbox_image = "registry.k8s.io/pause:3.10"
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd]
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
|
||||
runtime_type = "io.containerd.runc.v2"
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
|
||||
SystemdCgroup = true
|
||||
dest: /etc/containerd/config.toml
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
register: new_config
|
||||
|
||||
- name: Restart containerd
|
||||
systemd:
|
||||
name: containerd
|
||||
state: restarted
|
||||
when: new_config.changed
|
||||
|
||||
- name: Pull the pause image manually
|
||||
command: crictl pull registry.k8s.io/pause:3.10
|
||||
register: pull_result
|
||||
changed_when: pull_result.rc == 0
|
||||
failed_when: false
|
||||
|
||||
- name: Display pull result
|
||||
debug:
|
||||
var: pull_result.stdout_lines
|
||||
|
||||
- name: Verify sandbox image
|
||||
command: crictl images
|
||||
register: images
|
||||
changed_when: false
|
||||
|
||||
- name: Display available images
|
||||
debug:
|
||||
var: images.stdout_lines
|
||||
|
||||
- name: Reset kubeadm if needed
|
||||
command: kubeadm reset -f
|
||||
register: reset_result
|
||||
changed_when: reset_result.rc == 0
|
||||
failed_when: false
|
||||
|
||||
- name: Display reset result
|
||||
debug:
|
||||
var: reset_result.stdout_lines
|
||||
|
||||
- name: Clean up Kubernetes directories
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- /etc/kubernetes
|
||||
- /var/lib/kubelet
|
||||
- /var/lib/etcd
|
||||
changed_when: false
|
||||
@@ -1,5 +1,10 @@
|
||||
---
|
||||
# ansible/tasks/kubernetes/install-containerd.yml
|
||||
- name: Ensure runc is installed (Debian/Ubuntu)
|
||||
apt:
|
||||
name: runc
|
||||
state: present
|
||||
when: ansible_os_family == "Debian"
|
||||
|
||||
- name: Create work directory for containerd installation
|
||||
file:
|
||||
@@ -61,16 +66,33 @@
|
||||
path: "{{ containerd_config_root }}/config.toml"
|
||||
regexp: 'SystemdCgroup = false'
|
||||
replace: 'SystemdCgroup = true'
|
||||
when: config_written.changed
|
||||
when: config_written.changed or containerd_binary.stat.exists
|
||||
notify: Restart containerd
|
||||
|
||||
- name: Update containerd config for Kubernetes sandbox image
|
||||
lineinfile:
|
||||
path: "{{ containerd_config_root }}/config.toml"
|
||||
regexp: '(\s*)sandbox_image = ".*"'
|
||||
regexp: '(\s*)sandbox_image\s*=\s*".*"'
|
||||
line: '\1sandbox_image = "registry.k8s.io/pause:3.10"'
|
||||
backrefs: yes
|
||||
when: config_written.changed
|
||||
when: config_written.changed or containerd_binary.stat.exists
|
||||
notify: Restart containerd
|
||||
|
||||
- name: Ensure containerd config has sandbox_image set
|
||||
lineinfile:
|
||||
path: "{{ containerd_config_root }}/config.toml"
|
||||
insertafter: '^\[plugins\."io\.containerd\.grpc\.v1\.cri"\]'
|
||||
line: ' sandbox_image = "registry.k8s.io/pause:3.10"'
|
||||
state: present
|
||||
when: containerd_binary.stat.exists
|
||||
notify: Restart containerd
|
||||
|
||||
- name: Make sure CRI plugin is not disabled
|
||||
replace:
|
||||
path: "{{ containerd_config_root }}/config.toml"
|
||||
regexp: 'disabled_plugins\s*=\s*\[\s*"cri"\s*\]'
|
||||
replace: 'disabled_plugins = []'
|
||||
when: containerd_binary.stat.exists
|
||||
notify: Restart containerd
|
||||
|
||||
- name: Update containerd config for GRPC socket group (gid)
|
||||
@@ -78,7 +100,7 @@
|
||||
path: "{{ containerd_config_root }}/config.toml"
|
||||
regexp: '^(\s*gid\s*=\s*)0'
|
||||
replace: '\g<1>{{ containerd_gid_cmd.stdout }}'
|
||||
when: config_written.changed
|
||||
when: config_written.changed or containerd_binary.stat.exists
|
||||
notify: Restart containerd
|
||||
|
||||
- name: Create containerd systemd service file
|
||||
@@ -122,6 +144,22 @@
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
- name: Restart containerd immediately if needed
|
||||
systemd:
|
||||
name: containerd
|
||||
state: restarted
|
||||
when: containerd_binary.stat.exists
|
||||
|
||||
- name: Configure crictl to use containerd
|
||||
copy:
|
||||
dest: /etc/crictl.yaml
|
||||
content: |
|
||||
runtime-endpoint: unix:///run/containerd/containerd.sock
|
||||
image-endpoint: unix:///run/containerd/containerd.sock
|
||||
timeout: 10
|
||||
debug: false
|
||||
mode: '0644'
|
||||
|
||||
- name: Set permissions for containerd socket
|
||||
file:
|
||||
path: /run/containerd/containerd.sock
|
||||
|
||||
Reference in New Issue
Block a user