An understanding of Containerd container runtime and installation

1. Introduction to Containerd

1. What is Containerd?

Containerd is an open source container runtime, which is part of the Docker engine and a project of CNCF. Containerd provides a standard container runtime interface, and of course it can also manage containers. It is often used to integrate Kubernetes, Docker Compose and other orchestration tools.

2. What is the difference between Containerd and Docker?

Both Docker and containerd are implemented by container technology, with the following differences:

  • Docker is a complete container platform, including container engine, image warehouse, network, storage and other components, while Containerd is a lightweight container runtime that only provides container lifecycle management and basic image operations.
  • Docker's API and CLI are more abundant, and it is convenient to perform container creation, stop, start, delete and other operations, while containerd's API and CLI are relatively simple.
  • Docker is more secure and stable, while Containerd is more lightweight.
    In short, the scenarios used by Docker and Containerd are different. Containerd is generally used as an integrated orchestration tool, and is rarely used alone.

2. Install Containerd using the yum repository

1. Add yum source

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

2. Install containerd

yum -y install containerd.io-1.6.6

3. Generate containerd configuration file

mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml

4. To modify the configuration file, modify the following two configurations.

vim /etc/containerd/config.toml

SystemdCgroup = true
sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.7"
  • SystemdCgroup: use SystemdCgroup driver
  • sandbox_image: configure the domestic sandbox image address

A sandbox image is a special image that contains the files and tools needed for the container to run, as well as resource control mechanisms such as namespaces and cgroups for isolating containers. When a new sandbox needs to be created when the container is running, the image specified by this configuration item will be used as the base image to create the sandbox.

5. Start && set self-start

systemctl enable containerd  --now

3. Install Containerd using source code

1. Download cri-containerd
official website download:

wget -c https://github.com/containerd/containerd/releases/download/v1.6.6/cri-containerd-1.6.6-linux-amd64.tar.gz

Domestic download:

wget https://gitee.com/qinziteng/K8S/raw/master/Package/cri-containerd-1.6.6-linux-amd64.tar.gz

2. Copy the containerd command && systemd management file

tar zxf cri-containerd-1.6.6-linux-amd64.tar.gz -C /usr/local/src/
cp /usr/local/src/usr/local/bin/* /usr/bin/
cp /usr/local/src/usr/local/bin/* /usr/local/bin/
cp /usr/local/src/etc/systemd/system/containerd.service  /usr/lib/systemd/system/

3. Generate containerd configuration file

mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml

4. To modify the configuration file, modify the following two configurations.

vim /etc/containerd/config.toml

SystemdCgroup = true
sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.7"

4. Start containerd

systemctl start containerd

5. Install runC, if there is no runC command, the container cannot be created

wget https://github.com/opencontainers/runc/releases/download/v1.1.7/runc.amd64
mv runc.amd64 /usr/bin/runc
chmod +x /usr/bin/runc

4. Configure the domestic image acceleration address

1. Configure the acceleration address

mkdir /etc/containerd/certs.d/docker.io/ -p
vim /etc/containerd/certs.d/docker.io/hosts.toml

[host."http://hub-mirror.c.163.com",host."https://registry.docker-cn.com"]
  capabilities = ["pull"]

2. Specify the acceleration directory

vim /etc/containerd/config.toml

config_path = "/etc/containerd/certs.d"

3. Restart containerd

systemctl restart containerd

4. Download the image to try the effect

ctr images pull docker.io/library/nginx:1.18.0

This is the end! This article introduces what is containerd and its installation. Please pay attention to the follow-up articles on how to use containerd~

Guess you like

Origin blog.csdn.net/weixin_45310323/article/details/130423510