Onur Yasarlar
Search…
Installing Container Runtime Interface

Getting Started

You can select one of the supported container runtime interfaces for your Kubernetes cluster infrastructure. Since Kubernetes is deprecating Docker as a container runtime after v1.20, I choose containerd as my runtime interface and writing an Ansible role to install it. Let's do deep dive on how to install containerd. You can find my Ansible role here.
All installation steps for different container runtimes can be found here.

Installing Prerequisites

containerd expects some kernel parameters and kernel modules to be set persistently. I am handling that step in a separate playbook as below:
1
---
2
- name: Enable kernel module
3
lineinfile:
4
path: /etc/modules-load.d/containerd.conf
5
line: "{{ item }}"
6
state: present
7
create: true
8
mode: '0644'
9
loop:
10
- overlay
11
- br_netfilter
12
13
- name: Reload kernel modules
14
modprobe:
15
name: "{{ item }}"
16
state: present
17
loop:
18
- overlay
19
- br_netfilter
20
21
- name: Setup required sysctl params
22
sysctl:
23
name: "{{ item.name }}"
24
value: "{{ item.value }}"
25
sysctl_file: /etc/sysctl.d/99-kubernetes-cri.conf
26
reload: true
27
loop:
28
- { name: net.bridge.bridge-nf-call-iptables, value: 1 }
29
- { name: net.ipv4.ip_forward, value: 1}
30
- { name: net.bridge.bridge-nf-call-ip6tables, value: 1}
Copied!

Installing containerd runtime interface

I am covering containerd installation on Centos 7, Ubuntu 18.04, and Ubuntu 20.04. Each operating system has its own installation requirements. I prefer to split them into different plays and include them in my tasks/main.yml as below:
1
- name: Install containerd
2
include_tasks: "install_{{ ansible_distribution | lower }}.yaml"
Copied!
So each supported operating system calls its own yaml file as below:
CENTOS 7
Ubuntu 18.04 / 20.04
tasks/install_centos.yaml
1
---
2
- name: Install on CentOS 7
3
block:
4
- name: Install required packages
5
package:
6
name:
7
- yum-utils
8
- device-mapper-persistent-data
9
- lvm2
10
state: present
11
12
- name: Create docker-ce package repository
13
get_url:
14
url: "https://download.docker.com/linux/centos/docker-ce.repo"
15
dest: /etc/yum.repos.d/docker-ce.repo
16
owner: root
17
group: root
18
mode: '0644'
19
20
- name: Install containerd.io
21
package:
22
name: containerd.io
23
state: present
24
when: ansible_distribution_major_version | int == 7
25
Copied!
tasks/install_ubuntu.yaml
1
---
2
- name: Install containerd on Ubuntu 18.04 / 20.04
3
apt:
4
name: containerd
5
update_cache: yes
6
when: (ansible_distribution_version.split(".") | join == "1804") or
7
(ansible_distribution_version.split(".") | join == "2004")
8
Copied!
containerd version is not defined in the current version of the Ansible role. In the near future, I can add it to provide more stability but for now, I will go with the latest version always.

Configuration

Once the binary is installed, we need to create the configuration file under /etc/containerd/config.toml. Then we will need to enable and restart the service so the new configuration can be read by the daemon. Since the configuration step is common on all operating systems, I created a single play and include it in the main play. Let's take a look at the configuration code:
tasks/configure.yaml
1
---
2
- name: Create /etc/containerd
3
file:
4
path: /etc/containerd
5
state: directory
6
mode: '0755'
7
8
- name: Check if /etc/containerd/config.toml exists
9
stat:
10
path: /etc/containerd/config.toml
11
register: containerd_config
12
13
- name: Copy containerd configuration
14
shell: "containerd config default > /etc/containerd/config.toml"
15
args:
16
warn: no
17
tags: ['skip_ansible_lint']
18
when: not containerd_config.stat.exists
19
notify: restart containerd
20
21
- name: Enable containerd
22
service:
23
name: containerd
24
enabled: true
25
Copied!

Putting things together

All the above steps are included in the main playbook of the role as below:
tasks/main.yml
1
- name: Handle prereqs
2
include_tasks: prereq.yaml
3
4
- name: Install containerd
5
include_tasks: "install_{{ ansible_distribution | lower }}.yaml"
6
7
- name: Configure containerd
8
include_tasks: configure.yaml
9
Copied!
Calling this role will enable us to install containerd on supported operating systems. Now we can continue with installing kubeadm, kubelet, and kubectl.
Last modified 1yr ago