Skip to content

Commit

Permalink
Enable containerd service, Add fix for single machine
Browse files Browse the repository at this point in the history
  • Loading branch information
rafzei committed Feb 15, 2022
1 parent 65d8f41 commit 435a639
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 38 deletions.
1 change: 1 addition & 0 deletions ansible/playbooks/roles/containerd/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
systemd:
name: containerd
state: restarted
enabled: true

- name: Restart kubelet
systemd:
Expand Down
39 changes: 39 additions & 0 deletions ansible/playbooks/roles/containerd/tasks/configure-kubelet-env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# To be replaced by filter plugin (https://github.com/epiphany-platform/epiphany/issues/2943)
- name: Reconfigure kubelet args
notify:
- Restart containerd
- Restart kubelet
block:
- name: Get kubeadm-flags.env file content
slurp:
src: /var/lib/kubelet/kubeadm-flags.env
register: kubelet_kubeadm_args

- name: Set kubelet_kubeadmn_args_content
set_fact:
kubelet_kubeadmn_args_content: "{{ kubelet_kubeadm_args.content | b64decode }}"

- name: Modify container-runtime
replace:
path: /var/lib/kubelet/kubeadm-flags.env
regexp: '{{ item.regexp }}'
replace: '{{ item.replace }}'
backup: true
loop:
- { regexp: '^(KUBELET_KUBEADM_ARGS=\")(.*)(--container-runtime=[a-zA-Z0-9_]+)(.*)', replace: '\1\2--container-runtime=remote\4' }
- { regexp: '^(KUBELET_KUBEADM_ARGS=\")(.*)(--container-runtime-endpoint=.*\.sock)(.*)', replace: '\1\2--container-runtime-endpoint=/run/containerd/containerd.sock\4' }
when: kubelet_kubeadmn_args_content.find('--container-runtime') != -1

- name: Append container-runtime to kubelet config
replace:
path: /var/lib/kubelet/kubeadm-flags.env
regexp: '^(KUBELET_KUBEADM_ARGS=\")(.*)(\")$'
replace: '\1\2 --container-runtime=remote"'
when: kubelet_kubeadmn_args_content.find('--container-runtime') == -1

- name: Append container-runtime-endpoint to kubelet config
replace:
path: /var/lib/kubelet/kubeadm-flags.env
regexp: '^(KUBELET_KUBEADM_ARGS=\")(.*)(\")$'
replace: '\1\2 --container-runtime-endpoint=/run/containerd/containerd.sock"'
when: kubelet_kubeadmn_args_content.find('--container-runtime-endpoint') == -1
38 changes: 0 additions & 38 deletions ansible/playbooks/roles/containerd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,6 @@
- name: Configure containerd
include_tasks: configure-containerd.yml

# To be replaced by filter plugin (https://github.com/epiphany-platform/epiphany/issues/2943)
- name: Reconfigure kubelet args
when: is_upgrade_run
block:
- name: Get kubeadm-flags.env file content
slurp:
src: /var/lib/kubelet/kubeadm-flags.env
register: kubelet_kubeadm_args

- name: Set kubelet_kubeadmn_args_content
set_fact:
kubelet_kubeadmn_args_content: "{{ kubelet_kubeadm_args.content | b64decode }}"

- name: Modify container-runtime
replace:
path: /var/lib/kubelet/kubeadm-flags.env
regexp: '{{ item.regexp }}'
replace: '{{ item.replace }}'
backup: true
loop:
- { regexp: '^(KUBELET_KUBEADM_ARGS=\")(.*)(--container-runtime=[a-zA-Z0-9_]+)(.*)', replace: '\1\2--container-runtime=remote\4' }
- { regexp: '^(KUBELET_KUBEADM_ARGS=\")(.*)(--container-runtime-endpoint=.*\.sock)(.*)', replace: '\1\2--container-runtime-endpoint=/run/containerd/containerd.sock\4' }
when: kubelet_kubeadmn_args_content.find('--container-runtime') != -1

- name: Append container-runtime to kubelet config
replace:
path: /var/lib/kubelet/kubeadm-flags.env
regexp: '^(KUBELET_KUBEADM_ARGS=\")(.*)(\")$'
replace: '\1\2 --container-runtime=remote"'
when: kubelet_kubeadmn_args_content.find('--container-runtime') == -1

- name: Append container-runtime-endpoint to kubelet config
replace:
path: /var/lib/kubelet/kubeadm-flags.env
regexp: '^(KUBELET_KUBEADM_ARGS=\")(.*)(\")$'
replace: '\1\2 --container-runtime-endpoint=/run/containerd/containerd.sock"'
when: kubelet_kubeadmn_args_content.find('--container-runtime-endpoint') == -1

- name: Provide crictl.yaml file
copy:
src: crictl.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
backup: true
register: apply_kubelet_custom_config

- name: Configure kubelet-env
include_role:
name: containerd
tasks_from: configure-kubelet-env
when:
- is_upgrade_run or inventory_hostname in groups.image_registry

- name: Restart kubelet service
systemd:
name: kubelet
Expand Down

0 comments on commit 435a639

Please sign in to comment.