hincky的主页 hincky的主页
  • 学习笔记

    • Vue笔记
    • Vuepress
    • nginx
  • 语言类

    • java
    • go
    • python
    • 设计模式
  • 框架类

    • Spring
    • Spring Security
    • Mybatis
  • 容器技术

    • docker
    • k8s
    • helm
    • prometheus
    • grafana
    • jenkins
  • 命令集合

    • linux命令
    • docker命令
    • git命令
    • vim命令
    • k8s命令
  • 数据库

    • sql
    • mysql
  • 协议

    • 网络模型
    • http/1.1
    • WebSocket
    • http/2
    • TLS/SSL
    • tcp
    • IP
    • tcpdump抓包命令
    • wireshark抓包工具
  • 通用

    • Git
  • 技术分享

    • git push/pull总是超时怎么办
    • idea debug技巧
    • postman使用
    • 问题总结
    • idea使用技巧
  • Oauth2

    • Oauth2原理
  • 项目列表

    • redis项目
    • 微服务项目
  • 分类
  • 标签
  • 归档
  • 随笔
GitHub (opens new window)

Hincky

当有趣的人,做想做的事
  • 学习笔记

    • Vue笔记
    • Vuepress
    • nginx
  • 语言类

    • java
    • go
    • python
    • 设计模式
  • 框架类

    • Spring
    • Spring Security
    • Mybatis
  • 容器技术

    • docker
    • k8s
    • helm
    • prometheus
    • grafana
    • jenkins
  • 命令集合

    • linux命令
    • docker命令
    • git命令
    • vim命令
    • k8s命令
  • 数据库

    • sql
    • mysql
  • 协议

    • 网络模型
    • http/1.1
    • WebSocket
    • http/2
    • TLS/SSL
    • tcp
    • IP
    • tcpdump抓包命令
    • wireshark抓包工具
  • 通用

    • Git
  • 技术分享

    • git push/pull总是超时怎么办
    • idea debug技巧
    • postman使用
    • 问题总结
    • idea使用技巧
  • Oauth2

    • Oauth2原理
  • 项目列表

    • redis项目
    • 微服务项目
  • 分类
  • 标签
  • 归档
  • 随笔
GitHub (opens new window)
  • 容器技术

    • docker

    • k8s

    • helm

    • rancher

    • prometheus

    • grafana

    • containerd

      • 容器管理工具 Containerd
        • 1.0 前言
        • 1.1 Containerd前世今生
        • 1.2 Containerd架构
          • 1.2.1 架构图
          • 1.2.2 常用插件
          • 1.2.3 架构缩略图
          • 1.2.4 与其它容器运行时工具性能对比
      • 安装containerd
        • 2.1 YUM方式安装
          • 2.1.1 获取YUM源
          • 2.1.2 使用yum命令安装
          • 2.1.3 验证安装及启动服务
          • 2.1.4 验证可用性
        • 2.2 二进制方式安装
          • 2.2.1 获取安装包
          • 2.2.2 安装并测试可用性
          • 2.2.2.1 安装containerd
          • 2.2.2.2 查看containerd安装位置
          • 2.2.2.3 复制containerd运行时文件至系统
          • 2.2.2.4 添加containerd.service文件至系统
          • 2.2.2.5 查看containerd使用帮助
          • 2.2.2.6 生成containerd模块配置文件
          • 2.2.2.6.1 生成默认模块配置文件
          • 2.2.2.6.2 替换默认配置文件
          • 2.2.2.7 启动containerd服务并设置开机自启动
          • 2.2.2.8 复制ctr命令至系统
          • 2.2.2.9 查看已安装containerd服务版本
          • 2.2.2.10 安装runC
          • 2.2.2.10.1 获取runC
          • 2.2.2.10.2 安装runC并验证安装结果
      • 镜像管理
        • 3.1 Containerd容器镜像管理命令
        • 3.2 查看镜像
        • 3.3 下载镜像
        • 3.4 镜像挂载
        • 3.5 镜像导出
        • 3.6 镜像删除
        • 3.7 镜像导入
        • 3.8 修改镜像tag
      • 容器管理
        • 4.1 获取命令帮助
          • 4.1.1 获取ctr命令帮助
          • 4.1.2 获取创建静态容器命令帮助
          • 4.1.3 获取动态容器命令帮助
        • 4.2 查看容器
        • 4.3 查看任务
        • 4.4 创建静态容器
        • 4.5 静态容器启动为动态容器
        • 4.6 进入容器操作
        • 4.7 直接运行一个动态容器
        • 4.8 暂停容器
        • 4.9 恢复容器
        • 4.10 停止容器
        • 4.11 删除容器
      • 私有镜像仓库harbor
        • 5.1 Harbor准备
        • 5.2 配置Containerd使用Harbor仓库
          • 5.2.1 Harbor主机名解析
          • 5.2.2 修改Containerd配置文件
          • 5.2.3 ctr下载镜像
          • 5.2.4 ctr上传镜像
      • 命名空间管理
        • 查看帮助
        • ns操作
          • 查看
          • 创建
          • 删除
        • 查看用户进程
        • 查看镜像
        • 创建静态容器
          • 查看容器
        • 与其它Containerd容器共享命名空间
      • 网络管理
        • 7.1 创建CNI网络
          • 7.1.1 获取CNI工具源码
          • 7.1.2 获取CNI Plugins(CNI插件)
          • 7.1.3 准备CNI网络配置文件
          • 7.1.4 生成CNI网络
        • 7.2 为Containerd容器配置网络功能
          • 7.2.1 创建一个容器
          • 7.2.2 进入容器查看其网络情况
          • 7.2.3 获取容器进程ID及其网络命名空间
          • 7.2.4 为指定容器添加网络配置
      • 持久化存储
        • 利用静态容器实现
        • 验证
      • docker集成containerd容器管理
        • 安装docker相关组件
        • 修改docker服务文件
    • jenkins

  • 命令集合

  • 软路由

  • 容量保障技术

  • 运维
  • 容器技术
  • containerd
hincky
2022-11-12
目录

私有镜像仓库harbor

# 5.1 Harbor准备

image-20220218211611942

image-20220218211755113

# 5.2 配置Containerd使用Harbor仓库

# 5.2.1 Harbor主机名解析

在所有安装containerd宿主机上添加此配置信息。

# vim /etc/hosts
# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.165 harbor.kubemsb.com
1
2
3
4
5
说明
* 192.168.10.165是harbor的IP

* harbor.kubemsb.com建议用FQDN形式,如果用类似harbor这种短名,后面下载镜像会出问题
1
2
3
4

# 5.2.2 修改Containerd配置文件

此配置文件已提前替换过,仅修改本地容器镜像仓库地址即可。
# vim /etc/containerd/config.toml
# cat /etc/containerd/config.toml
root = "/var/lib/containerd"
state = "/run/containerd"
oom_score = -999

[grpc]
  address = "/run/containerd/containerd.sock"
  uid = 0
  gid = 0
  max_recv_message_size = 16777216
  max_send_message_size = 16777216

[debug]
  address = ""
  uid = 0
  gid = 0
  level = ""

[metrics]
  address = ""
  grpc_histogram = false

[cgroup]
  path = ""

[plugins]
  [plugins.cgroups]
    no_prometheus = false
  [plugins.cri]
    stream_server_address = "127.0.0.1"
    stream_server_port = "0"
    enable_selinux = false
    sandbox_image = "easzlab/pause-amd64:3.2"
    stats_collect_period = 10
    systemd_cgroup = false
    enable_tls_streaming = false
    max_container_log_line_size = 16384
    [plugins.cri.containerd]
      snapshotter = "overlayfs"
      no_pivot = false
      [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/kube/bin"
      conf_dir = "/etc/cni/net.d"
      conf_template = "/etc/cni/net.d/10-default.conf"
    [plugins.cri.registry]
      [plugins.cri.registry.mirrors]
        [plugins.cri.registry.mirrors."docker.io"]
          endpoint = [
            "https://docker.mirrors.ustc.edu.cn",
            "http://hub-mirror.c.163.com"
          ]
        [plugins.cri.registry.mirrors."gcr.io"]
          endpoint = [
            "https://gcr.mirrors.ustc.edu.cn"
          ]
        [plugins.cri.registry.mirrors."k8s.gcr.io"]
          endpoint = [
            "https://gcr.mirrors.ustc.edu.cn/google-containers/"
          ]
        [plugins.cri.registry.mirrors."quay.io"]
          endpoint = [
            "https://quay.mirrors.ustc.edu.cn"
          ]
        [plugins.cri.registry.mirrors."harbor.kubemsb.com"]   在此处添加,在镜像加速器下面添加这一段
          endpoint = [
            "http://harbor.kubemsb.com"
          ]
    [plugins.cri.x509_key_pair_streaming]
      tls_cert_file = ""
      tls_key_file = ""
  [plugins.diff-service]
    default = ["walking"]
  [plugins.linux]
    shim = "containerd-shim"
    runtime = "runc"
    runtime_root = ""
    no_shim = false
    shim_debug = false
  [plugins.opt]
    path = "/opt/containerd"
  [plugins.restart]
    interval = "10s"
  [plugins.scheduler]
    pause_threshold = 0.02
    deletion_threshold = 0
    mutation_threshold = 100
    schedule_delay = "0s"
    startup_delay = "100ms"
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
重启containerd,以便于重新加载配置文件。
# systemctl restart containerd
1
2

# 5.2.3 ctr下载镜像

下载容器镜像
# ctr images pull --platform linux/amd64 docker.io/library/nginx:latest
1
2
说明:
* --platform linux/amd64 指定系统平台,也可以使用--all-platforms指定所有平台镜像。

1
2
3
输出:
docker.io/library/nginx:latest:                                                   resolved       |++++++++++++++++++++++++++++++++++++++|
index-sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767:    done           |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:bb129a712c2431ecce4af8dde831e980373b26368233ef0f3b2bae9e9ec515ee: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:b559bad762bec166fd028483dd2a03f086d363ee827d8c98b7268112c508665a:    done           |++++++++++++++++++++++++++++++++++++++|
config-sha256:c316d5a335a5cf324b0dc83b3da82d7608724769f6454f6d9a621f3ec2534a5a:   done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:5eb5b503b37671af16371272f9c5313a3e82f1d0756e14506704489ad9900803:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:1ae07ab881bd848493ad54c2ba32017f94d1d8dbfd0ba41b618f17e80f834a0f:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:78091884b7bea0fa918527207924e9993bcc21bf7f1c9687da40042ceca31ac9:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:091c283c6a66ad0edd2ab84cb10edacc00a1a7bc5277f5365c0d5c5457a75aff:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:55de5851019b8f65ed6e28120c6300e35e556689d021e4b3411c7f4e90a9704b:    done           |++++++++++++++++++++++++++++++++++++++|
elapsed: 20.0s                                                                    total:  53.2 M (2.7 MiB/s)
unpacking linux/amd64 sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767...
done: 3.028652226s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
查看已下载容器镜像
# ctr images ls
REF                              TYPE                                                      DIGEST                                                                  SIZE      PLATFORMS                                                                                                                          LABELS

docker.io/library/nginx:latest   application/vnd.docker.distribution.manifest.list.v2+json sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767 54.1 MiB  linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x                            -
1
2
3
4
5

# 5.2.4 ctr上传镜像

上传到Harbor library公有项目

重新生成新的tag
# ctr images tag docker.io/library/nginx:latest harbor.kubemsb.com/library/nginx:latest
harbor.kubemsb.com/library/nginx:latest
1
2
3
查看已生成容器镜像
# ctr images ls
REF                                     TYPE                                                      DIGEST                                                                  SIZE      PLATFORMS                                                                                                                          LABELS
docker.io/library/nginx:latest          application/vnd.docker.distribution.manifest.list.v2+json sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767 54.1 MiB  linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x                            -
harbor.kubemsb.com/library/nginx:latest application/vnd.docker.distribution.manifest.list.v2+json sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767 54.1 MiB  linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x                            -
1
2
3
4
5
推送容器镜像至Harbor
# ctr images push --platform linux/amd64 --plain-http -u admin:Harbor12345 harbor.kubemsb.com/library/nginx:latest
1
2
说明:

* 先tag再push
* 因为我们harbor是http协议,不是https协议,所以需要加上`--plain-http`
* `--user admin:Harbor12345`指定harbor的用户名与密码
1
2
3
4
5
输出:
manifest-sha256:0fd68ec4b64b8dbb2bef1f1a5de9d47b658afd3635dc9c45bf0cbeac46e72101: done           |++++++++++++++++++++++++++++++++++++++|
config-sha256:dd025cdfe837e1c6395365870a491cf16bae668218edb07d85c626928a60e478:   done           |++++++++++++++++++++++++++++++++++++++|
elapsed: 0.5 s                                                                    total:  9.3 Ki (18.1 KiB/s)
1
2
3
4

image-20220220111100489

下载已上传容器镜像
# ctr images pull --plain-http harbor.kubemsb.com/library/nginx:latest
1
2
编辑 (opens new window)
#containerd
容器管理
命名空间管理

← 容器管理 命名空间管理→

最近更新
01
人生前期重要的能力
05-17
02
防火墙命令
04-11
03
docker-compose部署mysql主从集群
03-22
更多文章>
Theme by Vdoing | Copyright © 2022-2023 Hincky | MIT License | 粤ICP备2022120427号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式