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:

- name: Enable kernel module
    path: /etc/modules-load.d/containerd.conf
    line: "{{ item }}"
    state: present
    create: true
    mode: '0644'
    - overlay
    - br_netfilter

- name: Reload kernel modules
    name: "{{ item }}"
    state: present
    - overlay
    - br_netfilter

- name: Setup required sysctl params
    name: "{{ }}"
    value: "{{ item.value }}"
    sysctl_file: /etc/sysctl.d/99-kubernetes-cri.conf
    reload: true
    - { name: net.bridge.bridge-nf-call-iptables, value: 1 }
    - { name: net.ipv4.ip_forward, value: 1}
    - { name: net.bridge.bridge-nf-call-ip6tables, value: 1}

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:

- name: Install containerd
  include_tasks: "install_{{ ansible_distribution | lower }}.yaml"

So each supported operating system calls its own yaml file as below:

- name: Install on CentOS 7
    - name: Install required packages
          - yum-utils
          - device-mapper-persistent-data
          - lvm2
        state: present

    - name: Create docker-ce package repository
        url: ""
        dest: /etc/yum.repos.d/docker-ce.repo
        owner: root
        group: root
        mode: '0644'

    - name: Install
        state: present
  when: ansible_distribution_major_version | int == 7

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.


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:

- name: Create /etc/containerd
    path: /etc/containerd
    state: directory
    mode: '0755'

- name: Check if /etc/containerd/config.toml exists
    path: /etc/containerd/config.toml
  register: containerd_config

- name: Copy containerd configuration
  shell: "containerd config default > /etc/containerd/config.toml"
    warn: no
  tags: ['skip_ansible_lint']
  when: not containerd_config.stat.exists
  notify: restart containerd

- name: Enable containerd
    name: containerd
    enabled: true

Putting things together

All the above steps are included in the main playbook of the role as below:

- name: Handle prereqs
  include_tasks: prereq.yaml

- name: Install containerd
  include_tasks: "install_{{ ansible_distribution | lower }}.yaml"

- name: Configure containerd
  include_tasks: configure.yaml

Calling this role will enable us to install containerd on supported operating systems. Now we can continue with installing kubeadm, kubelet, and kubectl.

Last updated