containerd

1 概述

containerd(container daemon)是一个daemon进程用来管理和运行容器,可以用来拉取/推送镜像和管理容器的存储和网络。可以调用runc来创建和运行容器。

2 containerd 各组件功能

  • /usr/lib/systemd/system/containerd.service:systemd标准的Unit文件,被systemd管理:systemctl start|stop containerd.service。

  • /usr/bin/containerd:containerd的守护进程文件,在containerd.service Unit文件中通过ExecStart=/usr/bin/containerd调用,以启动containerd守护进程。

  • /etc/containerd/config.toml:在启动过程中加载此配置文件,可以在该配置文件中进行丰富多样的配置,以令containerd更贴合我们的实际需要(比如配置私有镜像源等)。

  • /usr/bin/containerd-shim:containerd套件,其目的主要是隔离containerd和容器。containerd守护进程收到gRPC调用请求(比如来自Kubelet或Docker的创建容器请求),便会启动/usr/bin/containerd-shim套件。

  • /usr/bin/containerd-shim-runc-v2:containerd-shim启动后会去启动/usr/bin/containerd-shim-runc-v2,然后立即退出,此时containerd-shim-runc-v2的父进程就变成了systemd(1),这样containerd-shim-runc-v2就和containerd脱离了关系,即便containerd退出也不会影响到容器(这也是containerd-shim套件的作用)。

  • /usr/bin/runc:OCI标准的具体实现就是runc,真正创建和维护容器最终便是由runc来完成的。/usr/bin/containerd-shim-runc-v2会启动runc去create、start容器,然后runc立即退出,容器的父进程就变成了containerd-shim-runc-v2,这也是容器内部可以看到的PID=1的进程。

  • /usr/bin/ctr:容器管理的客户端工具,可以对标docker命令。

3 配置文件

/etc/containerd/config.toml

#   Copyright 2018-2020 Docker Inc.

#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at

#       http://www.apache.org/licenses/LICENSE-2.0

#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

disabled_plugins = ["cri"]

#root = "/var/lib/containerd"
#state = "/run/containerd"
#subreaper = true
#oom_score = 0

#[grpc]
#  address = "/run/containerd/containerd.sock"
#  uid = 0
#  gid = 0

#[debug]
#  address = "/run/containerd/debug.sock"
#  uid = 0
#  gid = 0
#  level = "info"

root 配置的目录(/var/lib/containerd)是用来保存持久化数据的目录,包括content, snapshot, metadata和runtime。

若磁盘满的话,将会创建容器失败

[ERROR][url:http://127.0.0.1:4500/containers/1.scs-bak-ptasjlodklxm-bj_riflzxjpbdqm_itf_0-AZONE-DQ.scs/start] Request start docker failed: code[500], return_data[{"message":"mkdir /var/lib/containerd/io.containerd.runtime.v2.task/moby/bb5017006a04cbc9192b0111d81b32485969c8fd779e23f0423f2f5851d65eca: no space left on device: unknown"}

4 PS 进程

ps axjf

 PPID   PID  PGID   SID TTY      TPGID STAT   UID   TIME COMMAND
    1 14571 14456  9634 ?           -1 Sl       0  44:46 /usr/bin/dockerd --containerd=/run/containerd/containerd.sock -H tcp://127.0.0.1:4243 ...
    1 12183 12146 34215 ?           -1 Sl       0 576:54 /usr/bin/containerd
    1  6832  6832 34215 ?           -1 Sl       0   0:17 /usr/bin/containerd-shim-runc-v2 -namespace moby -id ee2595a5680b72f7edb89f39610df13f11bef2b0b9d91092d43a53006933efe1 -address /run/containerd/containerd.sock
 6832  6851  6851  6851 ?           -1 Ss       0   0:23  \_ /bin/sh -c while true;do sleep 1;echo 'hello';done
 6851 20351  6851  6851 ?           -1 S        0   0:00  |   \_ sleep 1
 6832 15712 15712 15712 pts/0    15712 Ss+      0   0:00  \_ /bin/bash
 6832  6368  6368  6368 ?         6368 Ss+      0   0:00  \_ /bin/bash

Last updated