首页 > 其他分享 >保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?

保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?

时间:2023-07-12 19:32:33浏览次数:43  
标签:Dragonfly harbor Anolis Nydus image 镜像 nydus

保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?_数据



文/云原生 SIG

01

背景

镜像是容器技术的基础之一,在云原生场景下,业务的正常运作离不开对镜像的制作、分发和运行。当前的镜像在使用的过程中,需要将镜像从仓库中全量拉取到本地,再由容器 engine 进行解压,堆叠挂载,然后才能构造成 rootfs 提供给容器。而在实际生产过程中,由于镜像版本的迭代, 镜像的体积往往越来越大 ,因而导致镜像拉取耗时往往占据了容器启动阶段的大部分时间。

2016 年的 usenix 的论文 Slacker:Fast Distribution with Lazy Docker Containers (链接见文末) 中曾发表数据,在容器启动的过程中,平均只需要读取镜像数据中的7%不到的数据,因此在实际应用过程中,通常不需要全量拉取数据我们就可以完成业务的发布过程。同时,镜像的拉取速度受限于镜像仓库和运行节点之间的网络带宽,而容器镜像的下载的承接主体是 node,即一个容器如果运行在不同的 node 上,就需要在不同的 node 中各自拉取数据,在集群规模较大的情况下,容器并发程度较高的时候,都会对容器镜像仓库造成一定的压力。

基于以上问题,龙蜥社区引入了 Nydus 镜像加速方案以及基于 Dragonfly 的 P2P 镜像加速系统,其中 Nydus 提供了镜像按需加载能力,Dragonfly 提供了集群镜像 P2P 加速能力,通过以上能力的组合减少容器启动过程中镜像的拉取时间,提升集群间的镜像分发效率。

本文将介绍如何在龙蜥 OS 上构建基于 Nydus 和 Dragonfly 的镜像加速端到端解决方案,其中会包含:

  • harbor 镜像仓库构建以及 Nydus 插件的支持
  • 单机 Nydus 镜像加速组件的配置以及使用
  • Nydus 格式镜像的制作、提交和使用
  • 单机 Dragonfly P2P 加速组件的配置以及使用
  • 使用 Nydus 以 Dragonfly 在特定场景下的效果对比

注:Harbor、Nydus、Dragonfly 这 3 个组件是相互独立的,您可以根据自己的实际应用场景对 3 个组件进行组合应用。

基于本解决方案,可以在特定的实验 case 下,将集群的扩容速度提升 100%,集群的计算性能提升 127%,具体实验结果请参考:https://openanolis.cn/sig/cloud-native/doc/664655138551659287。

另外,龙蜥社区推出了ACNS(OpenAnolis Cloud Native Suite),您可以用一键部署的方式完成 Nydus & Dragonfly 在集群内的部署应用,欢迎大家试用!



https://openanolis.cn/sig/cloud-native/doc/658259907494416166

02



在龙蜥 OS 上构建 Harbor 以及服务与 Harbor 的 Nydus 插件

Harbor 是一个开源的企业级的容器 Registry 管理项目,提供容器 Registry 管理 UI,提供的功能包括:基 于角色访问的控制权限管理(RBAC)、AD/LDAP 集成、日志审核、管理界面、自我注册、镜像复制和中文支持 等。在使用 Harbor 时,您可以在您的集群内迅速搭建一个企业级的容器 registry 服务,不仅可以保证生产镜像的安全,还可以获得更高的稳定性保障。

Nydus 镜像加速服务针对 Harbor 进行了适配,您可以在您的 harbor 镜像仓库中添加对 Nydus 的支持,这样,用户在推送一个镜像的时候,harbor 镜像仓库会自动完成对于镜像格式的转换,避免手动修改、转换镜像的负载工作。本章将介绍如何在 Harbor 仓库中对接使能 Nydus 服务。

首先,您需要有一个已经建立完成的 Harbor 镜像仓库,如果您还没有,可以参考龙蜥的 Harbor 部署文档:https://openanolis.cn/sig/cloud-native/doc/663184185494429473。

然后,我们需要开始适配 Nydus 的 acceld 服务,这里我们将 accld 与 Harbor 部署在同一台宿主机环境上:



配置 harbor 的 webhook,选择我们需要使能 Nydus 的 project,点击进入项目,这里采用默认的project library:

保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?_数据_02

在相应的 project 中选择添加 webhook:

保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?_linux_03



配置 webhook:

保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?_linux_04

其中,事件类型选择 Artifact pushed ,即在推送镜像的时候,调用此 webhook,然后,在 Endpoint 地址中,填写 http://{要部署的acceld的主机IP}:2077/api/v1/conversions 。

保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?_数据_05

在  Auth Header  中填写  header ,然后选择添加。然后开始添加机器人账户: 

保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?_nginx_06

保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?_数据_07

在点击添加之后,会出现账户的令牌, 请务必记录令牌的内容 ,将账目名和 secret 用 base64 工具生成 auth 序列: 

保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?_数据_08

下载 acceld 组件,并配置好 acceld 的配置文件 config.yaml.nydus :

wget https://github.com/goharbor/acceleration-service/releases/download/v0.1.1/harbor-acceld-v0.1.1-linux-amd64.tgz
tar -xf harbor-acceld-v0.1.1-linux-amd64.tgz
cd harbor-acceld/
# Configuration file of Harbor Acceleration Service

# http related config
server:
  name: API
  # listened host for http
  host: 0.0.0.0
  # port for http
  port: 2077

metric:
  # export metrics on `/metrics` endpoint
  enabled: true

provider:
  source:
    # hostname of harbor service
    registry.anolis.com:
      # base64 encoded `<robot-name>:<robot-secret>` for robot
      # account created in harbor
      auth: cm9ib3QkbnlkdXM6cUpDTmtiUWhzem1ydEpiQnUyZURzUWRVZ2NXTlI2TzU=
      # skip verifying server certs for HTTPS source registry
      insecure: true
      webhook:
        # webhook request auth header configured in harbor
        auth_header: header
    localhost:
      auth: YWRtaW46SGFyYm9yMTIzNDU=
  containerd:
    # ensure containerd service listening on this address
    address: /run/containerd/containerd.sock
    snapshotter: overlayfs

converter:
  # number of worker for executing conversion task
  worker: 5
  # enable to add harbor specified annotations to converted image for tracking.
  harbor_annotation: true
  driver:
    # accelerator driver type: `nydus`
    type: nydus
    config:
      work_dir: /tmp

      # `nydus-image` binary path, download it from:
      # https://github.com/dragonflyoss/image-service/releases (require v2.0.0 or higher)
      builder: nydus-image

      # specify nydus format version, possible values: `5`, `6` (EROFS-compatible), default is `5`
      # fs_version: 5

      # specify nydus blob compression algorithm, possible values: `none`, `lz4_block`, `gzip`, `zstd`, default is `lz4_block`
      # compressor: zstd

      # ensure that both OCIv1 manifest and nydus manifest are present as manifest index in the target image.
      # it's used for containerd to support running OCIv1 image or nydus image simultaneously with a single image reference.
      # note: please ensure that OCIv1 manifest already exists in target image reference.
      # merge_manifest: true

      # nydus chunk dict image reference, used for chunk-leveled data deduplication.
      # chunk_dict_ref: localhost/chunk_dict/image:latest

      # specify a storage backend for storing nydus blob, optional, possible values: oss, localfs
      # backend_type: oss
      # backend_config: '{"endpoint":"","access_key_id":"","access_key_secret":"","bucket_name":""}'

      # backend_type: localfs
      # backend_config: '{"dir":"/path/to/dir"}'
  rules:
    # add suffix to tag of source image reference as target image reference
    - tag_suffix: -nydus


首先配置 harbor 的域名,然后将刚才生产的序列号补充到 auth 中,最后将 insecure 字段配置为 true : 

保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?_nginx_09

最后,运行 acceld:

./acceld --config config.yaml.nydus >log.txt 2>&1  &


在您运行 acceld 的机器上,需要有 nydus-image 工具用于镜像转换,如果您使用的是龙蜥 OS,那么只需要安装 nydus-rs 包,否则需要自行下载该工具,具体步骤请参考:https://openanolis.cn/sig/cloud-native/doc/624244092113272868。

此时,只要有用户往该 harbor 仓库中上传任意镜像,acceld 都会自动将其转换成 Nydus 格式的镜像,以  {original_tag}-nydus  作为 tag,比如: 

保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?_nginx_10

可以看到这时harbor仓库中会多出现一个  ubuntu:latest-nydus 的镜像: 

保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?_linux_11

03

单机 Nydus 镜像加速组件的配置以及使用

在单机上安装、使用 Nydus 组件,请参考以下文档:https://openanolis.cn/sig/cloud-native/doc/624244092113272868



04

Nydus 格式镜像的制作、提交和使用



4.1 对 Harbor 仓库中已有镜像进行转换



如果您的 Harbor 仓库中已经存在了一定的镜像,需要进行 Nydus 格式转换,可以采用如下方式:

首先,在已经运行了 acceld 的机器上,安装 acceldctl 工具:

wget https://github.com/goharbor/acceleration-service/releases/download/v0.1.1/harbor-acceld-v0.1.1-linux-amd64.tgz
tar -xf harbor-acceld-v0.1.1-linux-amd64.tgz
cd harbor-acceld/


然后,进行转换,比如 harbor 中已经有 nginx 的镜像,我们需要进行转换,可以采用:

./accelctl task create <harbor-service-address>/library/nginx:latest
./accelctl task list




4.2 在任意安装了 Nydus 的机器上进行本地镜像的转换



请参考 https://openanolis.cn/sig/cloud-native/doc/624244092113272868  中的第六章,您使用 nydusify convert 时,如果目标的镜像指明了仓库,nydusify 会自动帮您推送到相应的仓库中去。



4.3 使用 buildkit 进行基于 dockerfile 的镜像制作



我们可以使用 buildkit 工具基于 Dockerfile 构建 Nydus 格式的容器镜像,Dockerfile  是一个文本文件,其内包含了一条条的 指令(Instruction) ,每一条指令构建一层,因此每一条指令的内容,就是描述该层应当如何构建。

  • 先创建一个 nginx 的 Dockerfile
tee Dockerfile << EOF
FROM nginx
RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
EOF
  • 安装 Nydus 与 nerdctl
sudo yum --enablerepo Plus install -y nydus-rs
sudo yum update -y anolis-repos && sudo yum install -y anolis-experimental-release && sudo yum install -y nerdctl
  • 下载并启动支持 Nydus 版本的 buildkit
wget https://gitee.com/anolis/buildkit/releases/download/v0.10.5-rc.1/buildkit-0.10.5~rc.1-1.an8.x86_64.rpm
rpm -ivh buildkit-0.10.5~rc.1-1.an8.x86_64.rpm
sudo env NYDUS_BUILDER=/usr/bin/nydus-image buildkitd


  • 启动本地镜像中心
sudo nerdctl run -d --restart=always -p 5000:5000 registry


  • 构建并转换镜像
sudo buildctl build \
    --frontend=dockerfile.v0 \
    --local context=. \
    --local dockerfile=. \
    --output type=image,name=localhost:5000/nginx:latest,push=true,compression=nydus,oci-mediatypes=true


  • 启动镜像
sudo nerdctl --snapshotter nydus run --rm -it -p 80:80 localhost:5000/nginx:latest

4.4 Nydus 镜像制作限制

  • 当前 Nydus 格式还不支持使用 nerdctl 或者 docker commit 进行镜像制作。
  • 当前 Nydus 格式镜像不支持使用 buildkit 的时候,用 from nydus 格式镜像的方式制作镜像。

05

Dragonfly P2P 加速组件的配置以及使用

首先,我们先要在集群内部署 Dragonfly,如果您的集群内还没有 Dragonfly,请参考文章部署:https://openanolis.cn/sig/cloud-native/doc/663184381485245340

然后,我们开始进行 Dragonfly 和 Harbor 私有仓库的对接,这里介绍用代理的方式来配置 Dragonfly 的方式。首先,生成 worker 节点的证书,用于 Dragonfly 的 https 劫持:

openssl genrsa -out ca.key 4096
openssl req -x509 -new -nodes -sha512 -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=localhost.com" -key ca.key -out ca.crt
mkdir -p /etc/dragonfly/cert
mv ca.key ca.crt /etc/dragonfly/cert/


修改 Dragonfly 的 daemon 配置文件 (/etc/dragonfly/dfget.yaml) ,将证书以及加速域名添加到配置文件中:

保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?_数据_12


注意,在 /etc/containerd/config.toml 中,不能在registry.anolis.com中配置127.0.0.1:65001的endpoint:


保姆级教程!如何在 Anolis 8 上构建基于 Nydus 和 Dragonfly 的镜像加速解决方案?_nginx_13

mkdir /etc/systemd/system/containerd.service.d
echo "[Service]" >/etc/systemd/system/containerd.service.d/http-proxy.conf
echo 'Envirnotallow="HTTP_PROXY=http://127.0.0.1:65001"' >>/etc/systemd/system/containerd.service.d/http-proxy.conf
echo 'Envirnotallow="HTTPS_PROXY=http://127.0.0.1:65001"' >>/etc/systemd/system/containerd.service.d/http-proxy.conf
systemctl daemon-reload
systemctl restart containerd
systemctl restart dfget-daemon


至此,Dragonfly 对接我们的自建 harbor 已经构建完毕。

更多内容还请前往龙蜥社区云原生 SIG 查看,链接地址:

2016 年 usenix 论文:

https://www.usenix.org/system/files/conference/fast16/fast16-papers-harter.pdf

—— 完 ——



微信公众号 - OpenAnolis龙蜥(OpenAnolis)。


标签:Dragonfly,harbor,Anolis,Nydus,image,镜像,nydus
From: https://blog.51cto.com/u_15308345/6703252

相关文章

  • anolis 8.8 (CentOS 8) 环境下搭建青岛大学OJ
    #yum-yinstallpython3-pip  //systemreplied:Packagepython3-pip-9.0.3-22.an8.noarchisalreadyinstalled.#pipinstalldocker-compose //systemreplied:  bash:pip:commandnotfound...#whereispip //systemreplied:  pip:/usr/bin/pip3.6#cd/u......
  • Anolis 8.8 (CentOS 8) install snapper to support system snapshot.
    Anolis8.8(CentOS8)installsnappertosupportsystemsnapshot.cd/etc/yum.repos.d/wgethttps://download.opensuse.org/repositories/filesystems:snapper/CentOS_8/filesystems:snapper.repoyuminstallsnappersudoyuminstallpython3python3-setuptools......
  • Anolis 8.x (8.6, 8.8, CentOS )安装记录
    硬件:一台DellPowerEdgeT130服务器,2*2T Harddisk软件:Anolis8.6 2023.7.3,发现系统自动下载了很多updates等待安装,选择安装更新,并重新启动系统。启动系统后,在屏幕左上角出现闪烁光标,系统长达10分钟以上无反应。按Ctrl+Alt+del, 系统的Anolis图形标志闪现后,系统重......
  • 记一次用一块新硬盘扩容Anolis文件系统
    新开了一个虚拟机,给它分配了一块300G的硬盘: 三个月后,客户抱怨说硬盘太小,遂进来df-h看一下,发现只有8g: 我已经忘了开这台机器时干了些什么,所以使用fdisk-l看一下: 发现300G的硬盘是在的,放心了。对这块硬盘使用fdisk/dev/sda,输入m命令看看能做什么: 按n添加新分区,按p规......
  • 开源内存数据库 DragonflyDB 1.0 正式 GA,可替代 Redis
    DragonflyDB是一个现代化的开源内存数据库,兼容Redis和MemcachedAPI,迁移时无需修改任何代码,可作为两者的替代方案。与传统的内存数据存储相比,DragonflyDB提供了更......
  • Dragonfly 最新正式版本 v2.0.9 已经发布!
    作者:戚文博-蚂蚁集团Dragonfly最新正式版本v2.0.9已经发布!感谢Dragonfly的贡献者们,同时也感谢默默支持Dragonfly项目的各个公有云团队。欢迎访问d7y.io[1]网......
  • dragonflydb 1.0 发布了
    就在昨天dragonflydb发布1.0了,同时也标志着可以生产可用了,同时也支持了masterreplication能力说明dragonflydb发展很快,目前来说还是缺少对于ha模式的支持,类似的keydb就......
  • 【linux系统安装】Anolis OS-龙蜥操作系统实机安装流程整理
    【安装准备】1、准备一个U盘,可储存空间不低于20G,U盘内资料移出去,待会儿要格式化做U盘启动盘2、windows操作系统上下载“Rufus”,官网:http://rufus.ie/zh/,制作U盘启动盘所......
  • 实用指南:如何在Anolis OS上轻松使用 Kata 安全容器?
    文/云原生SIG本篇文章我们将详细介绍怎么轻松在AnolisOS上使用KataContainers安全容器,我们将介绍KataContainer社区于2022年10月10日最新发行的Kata3.0.0......
  • CentOS即将停止维护,拥抱阿里“龙蜥“(Anolis OS),VMware安装Anolis OS与介绍
    一、前言大家在自己电脑来进行服务器的一些操作时,基本都是使用CentOS7或者是CentOS8,但是2021年底CentOS8宣布停止了维护;CentOS7在2024年6月30日也会停止维护!所以我......