recover docker + containerd install
This commit is contained in:
@@ -6,15 +6,15 @@ all:
|
|||||||
control_plane:
|
control_plane:
|
||||||
hosts:
|
hosts:
|
||||||
controlplane:
|
controlplane:
|
||||||
ansible_host: 10.203.146.166
|
ansible_host: 10.203.146.25
|
||||||
workers:
|
workers:
|
||||||
hosts:
|
hosts:
|
||||||
node01:
|
node01:
|
||||||
ansible_host: 10.203.146.180
|
ansible_host: 10.203.146.23
|
||||||
node02:
|
node02:
|
||||||
ansible_host: 10.203.146.62
|
ansible_host: 10.203.146.117
|
||||||
node03:
|
node03:
|
||||||
ansible_host: 10.203.146.185
|
ansible_host: 10.203.146.104
|
||||||
vars:
|
vars:
|
||||||
ansible_user: ubuntu
|
ansible_user: ubuntu
|
||||||
ansible_become: yes
|
ansible_become: yes
|
||||||
|
|||||||
@@ -58,3 +58,13 @@
|
|||||||
- validate
|
- validate
|
||||||
tasks:
|
tasks:
|
||||||
- include_tasks: ../tasks/kubernetes/validate-cluster.yml
|
- include_tasks: ../tasks/kubernetes/validate-cluster.yml
|
||||||
|
|
||||||
|
- name: Debug and fix containerd issues
|
||||||
|
hosts: control_plane
|
||||||
|
become: yes
|
||||||
|
vars_files:
|
||||||
|
- ../defaults/kubernetes.yml
|
||||||
|
tags:
|
||||||
|
- debug-containerd
|
||||||
|
tasks:
|
||||||
|
- include_tasks: ../tasks/kubernetes/debug-containerd.yml
|
||||||
|
|||||||
@@ -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
|
# 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
|
- name: Create work directory for containerd installation
|
||||||
file:
|
file:
|
||||||
@@ -61,16 +66,33 @@
|
|||||||
path: "{{ containerd_config_root }}/config.toml"
|
path: "{{ containerd_config_root }}/config.toml"
|
||||||
regexp: 'SystemdCgroup = false'
|
regexp: 'SystemdCgroup = false'
|
||||||
replace: 'SystemdCgroup = true'
|
replace: 'SystemdCgroup = true'
|
||||||
when: config_written.changed
|
when: config_written.changed or containerd_binary.stat.exists
|
||||||
notify: Restart containerd
|
notify: Restart containerd
|
||||||
|
|
||||||
- name: Update containerd config for Kubernetes sandbox image
|
- name: Update containerd config for Kubernetes sandbox image
|
||||||
lineinfile:
|
lineinfile:
|
||||||
path: "{{ containerd_config_root }}/config.toml"
|
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"'
|
line: '\1sandbox_image = "registry.k8s.io/pause:3.10"'
|
||||||
backrefs: yes
|
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
|
notify: Restart containerd
|
||||||
|
|
||||||
- name: Update containerd config for GRPC socket group (gid)
|
- name: Update containerd config for GRPC socket group (gid)
|
||||||
@@ -78,7 +100,7 @@
|
|||||||
path: "{{ containerd_config_root }}/config.toml"
|
path: "{{ containerd_config_root }}/config.toml"
|
||||||
regexp: '^(\s*gid\s*=\s*)0'
|
regexp: '^(\s*gid\s*=\s*)0'
|
||||||
replace: '\g<1>{{ containerd_gid_cmd.stdout }}'
|
replace: '\g<1>{{ containerd_gid_cmd.stdout }}'
|
||||||
when: config_written.changed
|
when: config_written.changed or containerd_binary.stat.exists
|
||||||
notify: Restart containerd
|
notify: Restart containerd
|
||||||
|
|
||||||
- name: Create containerd systemd service file
|
- name: Create containerd systemd service file
|
||||||
@@ -122,6 +144,22 @@
|
|||||||
enabled: yes
|
enabled: yes
|
||||||
state: started
|
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
|
- name: Set permissions for containerd socket
|
||||||
file:
|
file:
|
||||||
path: /run/containerd/containerd.sock
|
path: /run/containerd/containerd.sock
|
||||||
|
|||||||
Reference in New Issue
Block a user