How to Install Containerd on Ubuntu 22.04 / Ubuntu 20.04

containerd is an industry-standard container runtime that manages the complete container lifecycle of its host system. It handles image transfer and storage, container execution and supervision, low-level storage and network attachments, etc.

containerd is one of the container runtimes that works with Kubernetes, and it will be suitable for your environment due to its simplicity.

Here, we will see how to install containerd on Ubuntu 22.04 / Ubuntu 20.04.

Install Containerd on Ubuntu 22.04 / 20.04

You can install containerd using official binaries or from the Docker repository.

Install Containerd Using Official Binaries

Install Containerd

First, download the latest version of containerd from GitHub and extract the files to the /usr/local/ directory.

When writing this post, containerd v1.6.3 has a bug and doesn’t start containers due to issues with CNI on Kubernetes v1.23. So, I recommend you use the older or the newer version of containerd.
wget https://github.com/containerd/containerd/releases/download/v1.6.2/containerd-1.6.2-linux-amd64.tar.gz

sudo tar Czxvf /usr/local containerd-1.6.2-linux-amd64.tar.gz

Then, download the systemd service file and set it up so that you can manage the service via systemd.

wget https://raw.githubusercontent.com/containerd/containerd/main/containerd.service

sudo mv containerd.service /usr/lib/systemd/system/

Finally, start the containerd service using the below command.

sudo systemctl daemon-reload

sudo systemctl enable --now containerd

Then, check the status of the containerd service.

sudo systemctl status containerd

Output:

 containerd.service - containerd container runtime
     Loaded: loaded (/lib/systemd/system/containerd.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-05-01 13:59:49 EDT; 18s ago
       Docs: https://containerd.io
    Process: 2182 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
   Main PID: 2183 (containerd)
      Tasks: 8
     Memory: 18.8M
        CPU: 63ms
     CGroup: /system.slice/containerd.service
             └─2183 /usr/local/bin/containerd

May 01 13:59:49 ubuntu-2204 containerd[2183]: time="2022-05-01T13:59:49.941358574-04:00" level=info msg=serving... address=/run/containerd/containerd.sock.ttrpc
May 01 13:59:49 ubuntu-2204 containerd[2183]: time="2022-05-01T13:59:49.941402747-04:00" level=info msg=serving... address=/run/containerd/containerd.sock
May 01 13:59:49 ubuntu-2204 systemd[1]: Started containerd container runtime.

Install runC

runC is an open-source container runtime for spawning and running containers on Linux according to the OCI specification.

Download the latest version of runC from GitHub and install it as /usr/local/sbin/runc.

wget https://github.com/opencontainers/runc/releases/download/v1.1.1/runc.amd64

sudo install -m 755 runc.amd64 /usr/local/sbin/runc

Containerd configuration for Kubernetes

containerd uses a configuration file config.toml for handling its demons. When installing containerd using official binaries, you will not get the configuration file. So, generate the default configuration file using the below commands.

sudo mkdir -p /etc/containerd/

containerd config default | sudo tee /etc/containerd/config.toml

If you plan to use containerd as the runtime for Kubernetes, configure the systemd cgroup driver for runC.

sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml

Next, use the below command to restart the containerd service.

sudo systemctl restart containerd

Using Docker Repository

Docker offers the containerd containerd.io package in the .deb format through the Docker repository. So, install the required packages for containerd installation.

sudo apt update

sudo apt install -y ca-certificates curl gnupg lsb-release

Set up Docker Repository

Then, add the Docker’s GPG key to your system.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

And then, add the Docker repository to the system by running the below command.

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list

Install Containerd

After adding the Docker’s repository, update the repository index.

sudo apt update

Then, install containerd using the apt command.

sudo apt install -y containerd.io

By now, the containerd service should be up and running.

sudo systemctl status containerd

Output:

 containerd.service - containerd container runtime
     Loaded: loaded (/lib/systemd/system/containerd.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-05-01 13:59:49 EDT; 18s ago
       Docs: https://containerd.io
    Process: 2182 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
   Main PID: 2183 (containerd)
      Tasks: 8
     Memory: 18.8M
        CPU: 63ms
     CGroup: /system.slice/containerd.service
             └─2183 /usr/local/bin/containerd

May 01 13:59:49 ubuntu-2204 containerd[2183]: time="2022-05-01T13:59:49.941358574-04:00" level=info msg=serving... address=/run/containerd/containerd.sock.ttrpc
May 01 13:59:49 ubuntu-2204 containerd[2183]: time="2022-05-01T13:59:49.941402747-04:00" level=info msg=serving... address=/run/containerd/containerd.sock
May 01 13:59:49 ubuntu-2204 systemd[1]: Started containerd container runtime.

Containerd configuration for Kubernetes

containerd uses a configuration file config.toml for managing demons. For Kubernetes, you need to configure the Systemd group driver for runC.

cat <<EOF | sudo tee -a /etc/containerd/config.toml
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
EOF

Then, enable CRI plugins by commenting out disabled_plugins = ["cri"] in the config.toml file.

sudo sed -i 's/^disabled_plugins \=/\#disabled_plugins \=/g' /etc/containerd/config.toml

Next, use the below commands to restart the containerd service.

sudo systemctl restart containerd

Install CNI Plugins For Containerd

For the container to run, you need to install CNI plugins. So, download the latest version of CNI plugins from GitHub and place them in the /opt/cni/bin directory.

sudo mkdir -p /opt/cni/bin/

sudo wget https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz

sudo tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.1.1.tgz

Restart the containerd service.

sudo systemctl restart containerd

Install nerdctl (CLI)

nerdctl is a Docker-compliant command-line interface for containerd. It is not part of the core package. So, this has to be installed separately.

Download the latest version of nerdctl from GitHub and extract it to the /usr/local/bin directory.

wget https://github.com/containerd/nerdctl/releases/download/v0.19.0/nerdctl-0.19.0-linux-amd64.tar.gz

sudo tar Cxzvf /usr/local/bin nerdctl-0.19.0-linux-amd64.tar.gz

A sample command:

sudo nerdctl run -d -p 80:80 --name=nginx nginx

Conclusion

That’s All. I hope you have learned how to install containerd on Ubuntu 22.04 / Ubuntu 20.04.

containerddockerkubernetesubuntu 20.04ubuntu 22.04
Comments (0)
Add Comment