Containerd的使用

1、简介

containerd是行业标准的容器运行时,重点是简单性,健壮性和可移植性。它可以作为Linux和Windows的守护程序使用,可以管理其主机系统的完整容器生命周期:图像传输和存储,容器执行和监控,低级存储和网络附件等。

容器化的设计旨在嵌入到更大的系统中,而不是由开发人员或最终用户直接使用。

cri是Kubernetes[容器运行时接口(CRI)的容器化插件实现

2、配置

containerd是一个可以在任何系统上运行的简单守护程序,配置文件的默认路径位于/etc/containerd/config.toml--config,-c引导守护程序时,可以通过标志更改此路径。

Containerd在主机系统上也有两个不同的存储位置。一种用于持久性数据,另一种用于运行时状态。

root将用于存储任何类型的容器持久化数据。快照,内容,容器和图像的元数据以及任何插件数据都将保留在此位置。根也为容器加载的插件命名空间。每个插件都有其自己的目录,用于存储数据。容器本身实际上并不需要存储任何持久性数据,它的功能来自于已加载的插件。

1
2
3
4
5
6
7
8
9
10
11
12
13
/var/lib/containerd/
├── io.containerd.content.v1.content
│ ├── blobs
│ └── ingest
├── io.containerd.metadata.v1.bolt
│ └── meta.db
├── io.containerd.runtime.v1.linux
│ ├── default
│ └── example
├── io.containerd.snapshotter.v1.btrfs
└── io.containerd.snapshotter.v1.overlayfs
├── metadata.db
└── snapshots

state将用于存储任何类型的临时数据。套接字,PID,运行时状态,安装点以及在重新启动之间不得保留的其他插件数据都存储在此位置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/run/containerd
├── containerd.sock
├── debug.sock
├── io.containerd.runtime.v1.linux
│ └── default
│ └── redis
│ ├── config.json
│ ├── init.pid
│ ├── log.json
│ └── rootfs
│ ├── bin
│ ├── data
│ ├── dev
│ ├── etc
│ ├── home
│ ├── lib
│ ├── media
│ ├── mnt
│ ├── proc
│ ├── root
│ ├── run
│ ├── sbin
│ ├── srv
│ ├── sys
│ ├── tmp
│ ├── usr
│ └── var
└── runc
└── default
└── redis
└── state.json

3、插件

containerd在内部使用插件,以确保内部实现解耦,稳定并与外部插件平等对待。要查看容器中包含的所有插件,请使用ctr plugins ls

插件是使用[plugins]containerd的config部分配置的。每个插件都可以使用模式有其自己的部分[plugins.<plugin id>]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[plugins]
[plugins.cgroups]
no_prometheus = false
[plugins.cri]
stream_server_address = ""
stream_server_port = "10010"
enable_selinux = false
sandbox_image = "k8s.gcr.io/pause:3.5"
stats_collect_period = 10
systemd_cgroup = false
[plugins.cri.containerd]
snapshotter = "overlayfs"
[plugins.cri.containerd.default_runtime]
runtime_type = "io.containerd.runtime.v1.linux"
runtime_engine = ""
runtime_root = ""
[plugins.cri.containerd.untrusted_workload_runtime]
runtime_type = ""
runtime_engine = ""
runtime_root = ""
[plugins.cri.cni]
bin_dir = "/opt/cni/bin"
conf_dir = "/etc/cni/net.d"
[plugins.cri.registry]
[plugins.cri.registry.mirrors]
[plugins.cri.registry.mirrors."docker.io"]
endpoint = ["https://registry-1.docker.io"]

4、命令行工具

语法

1
ctr [global options] command [command options] [arguments...]

命令选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
plugins, plugin            提供关于容器插件的信息
version 打印客户端和服务器版本
containers, c, container 管理容器
content 管理内容
events, event 显示containerd事件
images, image, i 管理镜像
leases 管理租赁协定
namespaces, namespace, ns 管理名称空间
pprof 为containerd提供golang pprof输出
run 运行一个容器
snapshots, snapshot 管理快照
tasks, t, task 管理任务
install 安装一个新包
oci OCI工具
shim 直接与垫片互动
help, h 帮助

全局选项

1
2
3
4
5
--debug                      在日志中打开调试输出
--address value, -a value containerd的GRPC服务器地址(default: "/run/containerd/containerd.sock") [$CONTAINERD_ADDRESS]
--timeout value CTR命令总超时时间 (default: 0s)
--connect-timeout value 连接到containerd的超时(default: 0s)
--namespace value, -n value 与命令一起使用的命名空间(default: "default") [$CONTAINERD_NAMESPACE]