SlideShare a Scribd company logo
Copyright(c)2022 NTT Corp. All Rights Reserved.
P2P Container Image Distribution on IPFS
With containerd and nerdctl
Kohei Tokunaga, NTT Corporation
FOSDEM 2022 (February 6)
Copyright(c)2022 NTT Corp. All Rights Reserved.
Summary
2
l nerdctl experimentally supports P2P image distribution on IPFS
• simple UI/UX for P2P
• allows IPFS-agnostic tools to get images from IPFS (e.g. BuildKit, Kubernetes)
• fast image distribution from bandwidth-limited seeder
l Combination with existing OCI image distribution techniques
• lazy pulling of eStargz
• distributing encrypted image by OCIcrypt
Registry
nerdctl push nerdctl pull
pusher node receiver node
peer peer
nerdctl push nerdctl pull
Registry-based image distribution IPFS-based image distribution
IPFS
Copyright(c)2022 NTT Corp. All Rights Reserved.
Problems in image distribu1on
3
Registry
push pull
pusher node receiver node
l Pulling is time-consuming
• Pulling packages accounts for 76% of container start
time [Harter et al. 2016]
• Can be slower under limited bandwidth between
registry and node
l Images can’t be shared if no access to the registry (e.g.,
registry outage, rate limited, no access to the internet, …)
Copyright(c)2022 NTT Corp. All Rights Reserved.
IPFS-based P2P image distribution with nerdctl
4
l nerdctl CLI (>= v0.14) of containerd experimentally supports image distribution on IPFS
• Images are shared in P2P manner without relying on the centralized registry
• Simple UI/UX for P2P image distribution
• Fast image distribution from bandwidth-limited seeder (discussed later)
Registry
nerdctl push nerdctl pull
pusher node receiver node
peer peer
nerdctl push nerdctl pull
Registry-based image distribution IPFS-based image distribution
IPFS
Copyright(c)2022 NTT Corp. All Rights Reserved.
nerdctl: Docker-compatible CLI of containerd
5
l Has same UI/UX as Docker
https://github.com/containerd/nerdctl
l Supports cutting-edge features
• rootless
• lazy-pulling (eStargz)
• encrypted images (OCIcrypt)
• P2P image distribution (IPFS)
• container image signing and verifying (cosign)
l Adopted by lima and Rancher Desktop
• container management tool for desktop
• https://medium.com/nttlabs/containerd-and-lima-39e0b64d2a59
nerdctl CLI
nerdctl run -it --rm alpine
nerdctl build -t foo /dockerfile-dir
nerdctl push ghcr.io/ktock/myalpine:latest
containerd API
Copyright(c)2022 NTT Corp. All Rights Reserved.
IPFS
6
l P2P and content addressable data sharing protocol
l No central server is needed
l Content addressable by CID
h@ps://ipfs.io
ipfs add myfile.txt ipfs get QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN
Content Addressable by CID (identifier based on the content’s hash)
peer peer
IPFS
Copyright(c)2022 NTT Corp. All Rights Reserved.
Configura)on of OCI image for IPFS
7
{
“schemaVersion”: 2,
“manifests”: [
{
“mediaType”: “application/vnd.oci.image.manifest.v1+json”,
“digest”: “sha256:f6eed19a2880f1000be1d46fb5d114d094a59e350f9d025580f7297c8d9527d5”,
“size”: 506,
“urls”: [
“ipfs://bafkreihw53izukea6eaaxyoun625cfgqsssz4niptubflahxff6i3fjh2u”
],
・・・
application/vnd.oci.image.
manifest.v1+json
application/vnd.oci.
image.config.v1+json
application/vnd.oci.image.
layer.v1.tar+gzip
CID
CID
{
"mediaType": "application/vnd.oci.image.index.v1+json",
"digest": "sha256:28bfa1fc6d491d3bee91bab451cab29c747e72917efacb0adc4e73faffe1f51c",
"size": 313,
"urls": [
"ipfs://bafkreibix6q7y3kjdu565en2wri4vmu4or7hfel67lfqvxcoop5p7ypvdq"
]
}
ipfs:// bafkreicq4dg6nkef5ju422ptedcwfz6kcvpvvhuqeykfrwq5krazf3muze
application/vnd.oci.image.
index.v1+json
CID
Each item in OCI image supports arbitrary URLs as the data source
→ we store CID (formed as IPFS URL)
l Constructing DAG by CIDs
l Image is referenced by CID of the topmost “OCI descriptor” JSON
OCI descriptor JSON
Copyright(c)2022 NTT Corp. All Rights Reserved.
Adding an image to IPFS
8
nerdctl push ipfs://ubuntu:20.04
l nerdctl supports ipfs:// prefix for an arbitrary image name
l nerdctl pushes the image to IPFS instead of registry
• Automatically configures the OCI image for IPFS (see previous slide)
l The image is distributed on IPFS in a p2p manner without registry
peer peer
IPFS
Copyright(c)2022 NTT Corp. All Rights Reserved.
Pulling an image from IPFS
9
nerdctl pull ipfs://bafkreicq4dg6nkef5ju422ptedcwfz6kcvpvvhuqeykfrwq5krazf3muze
l ipfs://CID references an image on IPFS
l nerdctl gets the image from IPFS instead of the registry
l The image needs to be configured for IPFS
• “nerdctl push ipfs://” automatically does this
nerdctl run ipfs://bafkreicq4dg6nkef5ju422ptedcwfz6kcvpvvhuqeykfrwq5krazf3muze
peer peer
IPFS
Copyright(c)2022 NTT Corp. All Rights Reserved.
Building image based on images on IPFS
10
FROM localhost:5050/ipfs/bafkreicq4dg6nkef5ju422ptedcwfz6kcvpvvhuqeykfrwq5krazf3muze
RUN echo hello > /hello
Dockerfile
l localhost:5050/ipfs/CID references an image on IPFS
• Dockerfile should support “ipfs://CID” image reference in the future
l Base image is acquired from IPFS
l The result image can also be pushed to IPFS using “nerdctl push ipfs://”
peer peer
IPFS
Copyright(c)2022 NTT Corp. All Rights Reserved.
IPFS-based image distribution for IPFS-agnostic tools
11
l Provides a read-only localhost registry backed by IPFS
• image is accessible via localhost:5050/ipfs/CID
l IPFS-agnostic tools (e.g. Kubernetes) can pull images from IPFS
• nerdctl build (backed by BuildKit) uses this functionality
nerdctl ipfs
registry
・・・
IPFS-agnostic
tools
peer
IPFS
node
RO Registry API
(via localhost)
nerdctl ipfs registry subcommand
localhost:5050/ipfs/bafkreicq4dg6nkef5ju422ptedcwfz6kcvpvvhuqeykfrwq5krazf3muze
ipfs://bafkreicq4dg6nkef5ju422ptedcwfz6kcvpvvhuqeykfrwq5krazf3muze
Kubernetes CRI
BuildKit
Copyright(c)2022 NTT Corp. All Rights Reserved.
Example: node-to-node image sharing on Kubernetes
12
nerdctl ipfs registry
DaemonSet
Pull from IPFS
nerdctl ipfs registry
DaemonSet
Pull from IPFS
node node
l “nerdctl ipfs registry” can be used
for node-to-node image sharing
l In the future, Kubernetes should support
“ipfs://CID” image reference
l Example configuration: running ipfs
daemon as DaemonSet on each node
https://github.com/containerd/nerdctl/pull/678
Kubernetes cluster IPFS
IPFS node (seeder)
l nerdctl build
l nerdctl push ipfs://…
l ・・・
Build image, push it to IPFS, …
share images
among nodes
IPFS daemon IPFS daemon
IPFS IPFS
・・・
Distribute images via IPFS
(WIP)
Copyright(c)2022 NTT Corp. All Rights Reserved.
Image distribution latency
13
l GKE v1.21.5-gke.1302 (20 nodes)
• instance: e2-standard-8 (asia-northeast1-a)
• OS: ubuntu_containerd (upgraded containerd to v1.5.8 manually)
l private seeder/registry (1 node)
• instance: e2-standard-8 (asia-northeast1-a)
• OS: Ubuntu 20.04
l image: ghcr.io/stargz-containers/jenkins:2.60.3-org (726.4 MiB)
l Measured the worst time to take for pull with configuring bandwidth using linux tc
l commit: https://github.com/containerd/nerdctl/commit/3b5ed0df186d05d986b9cdb7c47773f29febed29
• ipfs v0.11.0 (k8s nodes), ipfs v0.10.0 (seeder), nerdctl bb682bc
l benchmarking script: https://github.com/ktock/stargz-snapshotter/tree/nerdctl-ipfs-registry-kubernetes-
benchmark/script/nerdctl-ipfs-registry-kubernetes-benchmark
Measured Zme to take to distribute images under several bandwidth situaZons
IPFS node (seeder)
20 nodes Kubernetes cluster
IPFS
nodes share images via IPFS
container registry
registry API 20 nodes Kubernetes cluster
nodes pull images from registry
several bandwidth situations
several bandwidth situations
Copyright(c)2022 NTT Corp. All Rights Reserved.
0
10000
20000
30000
40000
50000
60000
70000
1 5 10 15 20
time
to
distribute
image
(msec)
number of images to pull
955 Mbits/sec
registry ipfs
0
20000
40000
60000
80000
100000
120000
1 5 10 15 20
Jme
to
distribute
image
(msec)
number of images to pull
478 Mbits/sec
registry ipfs
0
5000
10000
15000
20000
25000
1 5 10 15 20
time
to
distribute
image
(msec)
number of images to pull
3.82 Gbits/sec
registry ipfs
Image distribution latency
14
l On lower bandwidth with many images, IPFS distributes images faster than registry
l On higher bandwidth or with small number of images, IPFS can be slower than registry
• will work on further invesJgaJon and miJgaJon
lower is better lower is better lower is better
Copyright(c)2022 NTT Corp. All Rights Reserved.
Combination with existing
image distribution techniques
15
Copyright(c)2022 NTT Corp. All Rights Reserved.
Lazy pulling: eStargz
16
l Lazy pulling: Starting up containers without waiting for the pull completion
• Each chunk/file in the image is downloaded on-demand
l eStargz: OCI-compatible image format for lazy pulling with prefetch support
• Can be lazily pulled from standard registries
l Stargz Snapshotter: Plugin of containerd for enabling lazy pulling
https://github.com/containerd/stargz-snapshotter
0 5 10 15 20 25 30 35 40 45
estargz
estargz-noopt
legacy
Start up time of python:3.7 (print “hello”)
pull create run [sec]
Figure from “Faster Container Image Distribution on a Variety of Tools with Lazy Pulling - Kohei Tokunaga & Tao Peng.
KubeCon+CloudNativeCon North America 2021. https://sched.co/lV2a “
Copyright(c)2022 NTT Corp. All Rights Reserved.
Lazy pulling (eStargz) on IPFS
17
l eStargz can be stored to IPFS
l Stargz Snapshotter supports lazy pulling of eStargz from IPFS
• mounts eStargz image from IPFS to container’s rootfs
l Chunks are fetched lazily thus hopefully faster cold-start
https://github.com/containerd/stargz-snapshotter
proc
container
Node
Stargz Snapshotter
Fetching files/chunks on demand Moun@ng rooAs as FUSE
Lazy pulling
eStargz
image
IPFS Peer
nerdctl
Copyright(c)2022 NTT Corp. All Rights Reserved.
Image encryption: OCIcrypt
18
l nerdctl supports encryp<on/decryp<on of image layers with key pair
l OCIcrypt (imgcrypt plugin for containerd) is used
Registry
nerdctl image encrypt nerdctl image decrypt
image
image
https://github.com/containerd/imgcrypt
Public key Private key
encrypts an image decrypts an image
Copyright(c)2022 NTT Corp. All Rights Reserved.
Image encryption (OCICrypt) on IPFS
19
l Encrypted image can be pushed to IPFS
l Configuration of the image for IPFS (urls field) is done by
“nerdctl push ipfs://”
nerdctl image encrypt nerdctl image decrypt
image
image
IPFS
Public key Private key
Copyright(c)2022 NTT Corp. All Rights Reserved.
Future works
20
l Performance improvements
• Especially on high bandwidth environment with small number of images
• Pulling hangs when the searching image isn’t found on IPFS
l Enabling “ipfs://CID” reference on a various tools (e.g. BuildKit, Kubernetes, …)
l CID reproducibility
• “nerdctl push ipfs://” will produce different CIDs for different configurations of IPFS
• e.g. different chunk size
l Higher availability of data
• “pinning services” can be used maybe
l …
Copyright(c)2022 NTT Corp. All Rights Reserved.
Related projects about image distribution on IPFS
21
l ipcs: https://github.com/hinshun/ipcs
• Proposed by Edgar Lee (Netflix)
• containerd content store plugin backed by IPFS
• Focuses on content deduplication but incompatible to OCI image
l ipdr: https://github.com/ipdr/ipdr
• Proposed by Miguel Mota
• Docker registry backed by IPFS
• No native integration with runtime (requires a dedicated CLI)
• Lazy pulling unsupported
l EdgePier[1]
• Proposed by Soeren Becker, et al.
• Integrated ipdr (mentioned in the above) with Kubernetes
• Fast image distribution under bandwidth-restricted environment
• No OSS implementation
[1] Soeren Becker, et al."EdgePier: P2P-based Container Image Distribution in Edge Computing Environments". IEEE International Performance
Computing and Communications Conference 2021
Copyright(c)2022 NTT Corp. All Rights Reserved.
Summary
22
l nerdctl experimentally supports P2P image distribution on IPFS
• simple UI/UX for P2P
• allows IPFS-agnostic tools to get images from IPFS (e.g. BuildKit, Kubernetes)
• fast image distribution from bandwidth-limited seeder
l Combination with existing OCI image distribution techniques
• lazy pulling of eStargz, image encryption by OCIcrypt
Registry
nerdctl push nerdctl pull
pusher node receiver node
peer peer
nerdctl push nerdctl pull
Registry-based image distribution IPFS-based image distribution
IPFS
Thanks to Akihiro Suda (NTT) for the discussion!

More Related Content

PDF
コンテナ未経験新人が学ぶコンテナ技術入門
PDF
BuildKitの概要と最近の機能
PDF
Dockerからcontainerdへの移行
PDF
わかる!metadata.managedFields / Kubernetes Meetup Tokyo 48
PDF
DockerとKubernetesをかけめぐる
PDF
containerdの概要と最近の機能
PPTX
Dockerからcontainerdへの移行
PDF
仮想化環境におけるパケットフォワーディング
コンテナ未経験新人が学ぶコンテナ技術入門
BuildKitの概要と最近の機能
Dockerからcontainerdへの移行
わかる!metadata.managedFields / Kubernetes Meetup Tokyo 48
DockerとKubernetesをかけめぐる
containerdの概要と最近の機能
Dockerからcontainerdへの移行
仮想化環境におけるパケットフォワーディング

What's hot (20)

PDF
OpenJDKのコミッタってどんなことしたらなったの?解決してきた技術課題の事例から見えてくる必要な知識と技術(JJUG CCC 2023 Spring)
PDF
PFNのML/DL基盤を支えるKubernetesにおける自動化 / DevOpsDays Tokyo 2021
PDF
DockerとPodmanの比較
PDF
eStargzイメージとlazy pullingによる高速なコンテナ起動
PDF
LinuxのFull ticklessを試してみた
PDF
今話題のいろいろなコンテナランタイムを比較してみた
PDF
eBPFを用いたトレーシングについて
PDF
Kuberneteの運用を支えるGitOps
PDF
KubeCon + CloudNativeCon Europe 2022 Recap - Batch/HPCの潮流とScheduler拡張事例 / Kub...
PDF
KubernetesでRedisを使うときの選択肢
PDF
Stargz Snapshotter: イメージのpullを省略しcontainerdでコンテナを高速に起動する
PPTX
コンテナネットワーキング(CNI)最前線
PDF
Unityによるリアルタイム通信とMagicOnionによるC#大統一理論の実現
PDF
Mercari JPのモノリスサービスをKubernetesに移行した話 PHP Conference 2022 9/24
PDF
Grafana LokiではじめるKubernetesロギングハンズオン(NTT Tech Conference #4 ハンズオン資料)
PDF
Kubernetesのしくみ やさしく学ぶ 内部構造とアーキテクチャー
PDF
20分でわかるgVisor入門
PDF
Ethernetの受信処理
PPTX
Kubernetes introduction
PDF
CyberAgent における OSS の CI/CD 基盤開発 myshoes #CICD2021
OpenJDKのコミッタってどんなことしたらなったの?解決してきた技術課題の事例から見えてくる必要な知識と技術(JJUG CCC 2023 Spring)
PFNのML/DL基盤を支えるKubernetesにおける自動化 / DevOpsDays Tokyo 2021
DockerとPodmanの比較
eStargzイメージとlazy pullingによる高速なコンテナ起動
LinuxのFull ticklessを試してみた
今話題のいろいろなコンテナランタイムを比較してみた
eBPFを用いたトレーシングについて
Kuberneteの運用を支えるGitOps
KubeCon + CloudNativeCon Europe 2022 Recap - Batch/HPCの潮流とScheduler拡張事例 / Kub...
KubernetesでRedisを使うときの選択肢
Stargz Snapshotter: イメージのpullを省略しcontainerdでコンテナを高速に起動する
コンテナネットワーキング(CNI)最前線
Unityによるリアルタイム通信とMagicOnionによるC#大統一理論の実現
Mercari JPのモノリスサービスをKubernetesに移行した話 PHP Conference 2022 9/24
Grafana LokiではじめるKubernetesロギングハンズオン(NTT Tech Conference #4 ハンズオン資料)
Kubernetesのしくみ やさしく学ぶ 内部構造とアーキテクチャー
20分でわかるgVisor入門
Ethernetの受信処理
Kubernetes introduction
CyberAgent における OSS の CI/CD 基盤開発 myshoes #CICD2021
Ad

Similar to P2P Container Image Distribution on IPFS With containerd and nerdctl (20)

PDF
[KubeConNA2023] containerd pavilion
PDF
[Container Plumbing Days 2023] Why was nerdctl made?
PDF
[KubeCon EU 2021] Introduction and Deep Dive Into Containerd
PDF
Introduction and Deep Dive Into Containerd
PDF
[KubeConEU2023] containerd pavilion
PDF
[KubeCon EU 2020] containerd Deep Dive
PDF
20250617 [KubeCon JP 2025] containerd - Project Update and Deep Dive.pdf
PDF
20240320 [KubeCon EU Pavilion] containerd.pdf
PDF
Alternatives to layer-based image distribution: using CERN filesystem for images
ODP
Ipfs installation and demo
PDF
[Paris Container Day 2021] nerdctl: yet another Docker & Docker Compose imple...
PDF
20241113 [KubeCon NA Pavilion] containerd.pdf
PPTX
Decentralized storage
PDF
Docker Application to Scientific Computing
PDF
CernVM-FS for Docker image distribution in Cloud Foundry
PDF
IPFS: The Permanent Web
PDF
20250403 [KubeCon EU Pavilion] containerd.pdf
PPTX
Introduction to IPFS & Filecoin
PDF
Faster Container Image Distribution on a Variety of Tools with Lazy Pulling
PDF
Extended and embedding: containerd update & project use cases
[KubeConNA2023] containerd pavilion
[Container Plumbing Days 2023] Why was nerdctl made?
[KubeCon EU 2021] Introduction and Deep Dive Into Containerd
Introduction and Deep Dive Into Containerd
[KubeConEU2023] containerd pavilion
[KubeCon EU 2020] containerd Deep Dive
20250617 [KubeCon JP 2025] containerd - Project Update and Deep Dive.pdf
20240320 [KubeCon EU Pavilion] containerd.pdf
Alternatives to layer-based image distribution: using CERN filesystem for images
Ipfs installation and demo
[Paris Container Day 2021] nerdctl: yet another Docker & Docker Compose imple...
20241113 [KubeCon NA Pavilion] containerd.pdf
Decentralized storage
Docker Application to Scientific Computing
CernVM-FS for Docker image distribution in Cloud Foundry
IPFS: The Permanent Web
20250403 [KubeCon EU Pavilion] containerd.pdf
Introduction to IPFS & Filecoin
Faster Container Image Distribution on a Variety of Tools with Lazy Pulling
Extended and embedding: containerd update & project use cases
Ad

More from Kohei Tokunaga (9)

PDF
Starting up Containers Super Fast With Lazy Pulling of Images
PDF
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
PDF
BuildKitでLazy Pullを有効にしてビルドを早くする話
PDF
The overview of lazypull with containerd Remote Snapshotter & Stargz Snapshotter
PDF
Startup Containers in Lightning Speed with Lazy Image Distribution
PDF
Stargz Snapshotter: イメージのpullを省略してcontainerdでコンテナを高速に起動する
PDF
OCIランタイムの筆頭「runc」を俯瞰する
PDF
OCIv2?!軽量高速なイケてる次世代イメージ仕様の最新動向を抑えよう!
PDF
5分で振り返るKubeCon EU 2019:ランタイムとイメージの話題ダイジェスト
Starting up Containers Super Fast With Lazy Pulling of Images
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
BuildKitでLazy Pullを有効にしてビルドを早くする話
The overview of lazypull with containerd Remote Snapshotter & Stargz Snapshotter
Startup Containers in Lightning Speed with Lazy Image Distribution
Stargz Snapshotter: イメージのpullを省略してcontainerdでコンテナを高速に起動する
OCIランタイムの筆頭「runc」を俯瞰する
OCIv2?!軽量高速なイケてる次世代イメージ仕様の最新動向を抑えよう!
5分で振り返るKubeCon EU 2019:ランタイムとイメージの話題ダイジェスト

Recently uploaded (20)

PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
history of c programming in notes for students .pptx
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Online Work Permit System for Fast Permit Processing
PPT
Introduction Database Management System for Course Database
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Introduction to Artificial Intelligence
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
ISO 45001 Occupational Health and Safety Management System
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
history of c programming in notes for students .pptx
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Online Work Permit System for Fast Permit Processing
Introduction Database Management System for Course Database
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Introduction to Artificial Intelligence
Odoo Companies in India – Driving Business Transformation.pdf
ManageIQ - Sprint 268 Review - Slide Deck
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
2025 Textile ERP Trends: SAP, Odoo & Oracle
CHAPTER 2 - PM Management and IT Context
Wondershare Filmora 15 Crack With Activation Key [2025
Upgrade and Innovation Strategies for SAP ERP Customers
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Design an Analysis of Algorithms II-SECS-1021-03
ISO 45001 Occupational Health and Safety Management System

P2P Container Image Distribution on IPFS With containerd and nerdctl

  • 1. Copyright(c)2022 NTT Corp. All Rights Reserved. P2P Container Image Distribution on IPFS With containerd and nerdctl Kohei Tokunaga, NTT Corporation FOSDEM 2022 (February 6)
  • 2. Copyright(c)2022 NTT Corp. All Rights Reserved. Summary 2 l nerdctl experimentally supports P2P image distribution on IPFS • simple UI/UX for P2P • allows IPFS-agnostic tools to get images from IPFS (e.g. BuildKit, Kubernetes) • fast image distribution from bandwidth-limited seeder l Combination with existing OCI image distribution techniques • lazy pulling of eStargz • distributing encrypted image by OCIcrypt Registry nerdctl push nerdctl pull pusher node receiver node peer peer nerdctl push nerdctl pull Registry-based image distribution IPFS-based image distribution IPFS
  • 3. Copyright(c)2022 NTT Corp. All Rights Reserved. Problems in image distribu1on 3 Registry push pull pusher node receiver node l Pulling is time-consuming • Pulling packages accounts for 76% of container start time [Harter et al. 2016] • Can be slower under limited bandwidth between registry and node l Images can’t be shared if no access to the registry (e.g., registry outage, rate limited, no access to the internet, …)
  • 4. Copyright(c)2022 NTT Corp. All Rights Reserved. IPFS-based P2P image distribution with nerdctl 4 l nerdctl CLI (>= v0.14) of containerd experimentally supports image distribution on IPFS • Images are shared in P2P manner without relying on the centralized registry • Simple UI/UX for P2P image distribution • Fast image distribution from bandwidth-limited seeder (discussed later) Registry nerdctl push nerdctl pull pusher node receiver node peer peer nerdctl push nerdctl pull Registry-based image distribution IPFS-based image distribution IPFS
  • 5. Copyright(c)2022 NTT Corp. All Rights Reserved. nerdctl: Docker-compatible CLI of containerd 5 l Has same UI/UX as Docker https://github.com/containerd/nerdctl l Supports cutting-edge features • rootless • lazy-pulling (eStargz) • encrypted images (OCIcrypt) • P2P image distribution (IPFS) • container image signing and verifying (cosign) l Adopted by lima and Rancher Desktop • container management tool for desktop • https://medium.com/nttlabs/containerd-and-lima-39e0b64d2a59 nerdctl CLI nerdctl run -it --rm alpine nerdctl build -t foo /dockerfile-dir nerdctl push ghcr.io/ktock/myalpine:latest containerd API
  • 6. Copyright(c)2022 NTT Corp. All Rights Reserved. IPFS 6 l P2P and content addressable data sharing protocol l No central server is needed l Content addressable by CID h@ps://ipfs.io ipfs add myfile.txt ipfs get QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN Content Addressable by CID (identifier based on the content’s hash) peer peer IPFS
  • 7. Copyright(c)2022 NTT Corp. All Rights Reserved. Configura)on of OCI image for IPFS 7 { “schemaVersion”: 2, “manifests”: [ { “mediaType”: “application/vnd.oci.image.manifest.v1+json”, “digest”: “sha256:f6eed19a2880f1000be1d46fb5d114d094a59e350f9d025580f7297c8d9527d5”, “size”: 506, “urls”: [ “ipfs://bafkreihw53izukea6eaaxyoun625cfgqsssz4niptubflahxff6i3fjh2u” ], ・・・ application/vnd.oci.image. manifest.v1+json application/vnd.oci. image.config.v1+json application/vnd.oci.image. layer.v1.tar+gzip CID CID { "mediaType": "application/vnd.oci.image.index.v1+json", "digest": "sha256:28bfa1fc6d491d3bee91bab451cab29c747e72917efacb0adc4e73faffe1f51c", "size": 313, "urls": [ "ipfs://bafkreibix6q7y3kjdu565en2wri4vmu4or7hfel67lfqvxcoop5p7ypvdq" ] } ipfs:// bafkreicq4dg6nkef5ju422ptedcwfz6kcvpvvhuqeykfrwq5krazf3muze application/vnd.oci.image. index.v1+json CID Each item in OCI image supports arbitrary URLs as the data source → we store CID (formed as IPFS URL) l Constructing DAG by CIDs l Image is referenced by CID of the topmost “OCI descriptor” JSON OCI descriptor JSON
  • 8. Copyright(c)2022 NTT Corp. All Rights Reserved. Adding an image to IPFS 8 nerdctl push ipfs://ubuntu:20.04 l nerdctl supports ipfs:// prefix for an arbitrary image name l nerdctl pushes the image to IPFS instead of registry • Automatically configures the OCI image for IPFS (see previous slide) l The image is distributed on IPFS in a p2p manner without registry peer peer IPFS
  • 9. Copyright(c)2022 NTT Corp. All Rights Reserved. Pulling an image from IPFS 9 nerdctl pull ipfs://bafkreicq4dg6nkef5ju422ptedcwfz6kcvpvvhuqeykfrwq5krazf3muze l ipfs://CID references an image on IPFS l nerdctl gets the image from IPFS instead of the registry l The image needs to be configured for IPFS • “nerdctl push ipfs://” automatically does this nerdctl run ipfs://bafkreicq4dg6nkef5ju422ptedcwfz6kcvpvvhuqeykfrwq5krazf3muze peer peer IPFS
  • 10. Copyright(c)2022 NTT Corp. All Rights Reserved. Building image based on images on IPFS 10 FROM localhost:5050/ipfs/bafkreicq4dg6nkef5ju422ptedcwfz6kcvpvvhuqeykfrwq5krazf3muze RUN echo hello > /hello Dockerfile l localhost:5050/ipfs/CID references an image on IPFS • Dockerfile should support “ipfs://CID” image reference in the future l Base image is acquired from IPFS l The result image can also be pushed to IPFS using “nerdctl push ipfs://” peer peer IPFS
  • 11. Copyright(c)2022 NTT Corp. All Rights Reserved. IPFS-based image distribution for IPFS-agnostic tools 11 l Provides a read-only localhost registry backed by IPFS • image is accessible via localhost:5050/ipfs/CID l IPFS-agnostic tools (e.g. Kubernetes) can pull images from IPFS • nerdctl build (backed by BuildKit) uses this functionality nerdctl ipfs registry ・・・ IPFS-agnostic tools peer IPFS node RO Registry API (via localhost) nerdctl ipfs registry subcommand localhost:5050/ipfs/bafkreicq4dg6nkef5ju422ptedcwfz6kcvpvvhuqeykfrwq5krazf3muze ipfs://bafkreicq4dg6nkef5ju422ptedcwfz6kcvpvvhuqeykfrwq5krazf3muze Kubernetes CRI BuildKit
  • 12. Copyright(c)2022 NTT Corp. All Rights Reserved. Example: node-to-node image sharing on Kubernetes 12 nerdctl ipfs registry DaemonSet Pull from IPFS nerdctl ipfs registry DaemonSet Pull from IPFS node node l “nerdctl ipfs registry” can be used for node-to-node image sharing l In the future, Kubernetes should support “ipfs://CID” image reference l Example configuration: running ipfs daemon as DaemonSet on each node https://github.com/containerd/nerdctl/pull/678 Kubernetes cluster IPFS IPFS node (seeder) l nerdctl build l nerdctl push ipfs://… l ・・・ Build image, push it to IPFS, … share images among nodes IPFS daemon IPFS daemon IPFS IPFS ・・・ Distribute images via IPFS (WIP)
  • 13. Copyright(c)2022 NTT Corp. All Rights Reserved. Image distribution latency 13 l GKE v1.21.5-gke.1302 (20 nodes) • instance: e2-standard-8 (asia-northeast1-a) • OS: ubuntu_containerd (upgraded containerd to v1.5.8 manually) l private seeder/registry (1 node) • instance: e2-standard-8 (asia-northeast1-a) • OS: Ubuntu 20.04 l image: ghcr.io/stargz-containers/jenkins:2.60.3-org (726.4 MiB) l Measured the worst time to take for pull with configuring bandwidth using linux tc l commit: https://github.com/containerd/nerdctl/commit/3b5ed0df186d05d986b9cdb7c47773f29febed29 • ipfs v0.11.0 (k8s nodes), ipfs v0.10.0 (seeder), nerdctl bb682bc l benchmarking script: https://github.com/ktock/stargz-snapshotter/tree/nerdctl-ipfs-registry-kubernetes- benchmark/script/nerdctl-ipfs-registry-kubernetes-benchmark Measured Zme to take to distribute images under several bandwidth situaZons IPFS node (seeder) 20 nodes Kubernetes cluster IPFS nodes share images via IPFS container registry registry API 20 nodes Kubernetes cluster nodes pull images from registry several bandwidth situations several bandwidth situations
  • 14. Copyright(c)2022 NTT Corp. All Rights Reserved. 0 10000 20000 30000 40000 50000 60000 70000 1 5 10 15 20 time to distribute image (msec) number of images to pull 955 Mbits/sec registry ipfs 0 20000 40000 60000 80000 100000 120000 1 5 10 15 20 Jme to distribute image (msec) number of images to pull 478 Mbits/sec registry ipfs 0 5000 10000 15000 20000 25000 1 5 10 15 20 time to distribute image (msec) number of images to pull 3.82 Gbits/sec registry ipfs Image distribution latency 14 l On lower bandwidth with many images, IPFS distributes images faster than registry l On higher bandwidth or with small number of images, IPFS can be slower than registry • will work on further invesJgaJon and miJgaJon lower is better lower is better lower is better
  • 15. Copyright(c)2022 NTT Corp. All Rights Reserved. Combination with existing image distribution techniques 15
  • 16. Copyright(c)2022 NTT Corp. All Rights Reserved. Lazy pulling: eStargz 16 l Lazy pulling: Starting up containers without waiting for the pull completion • Each chunk/file in the image is downloaded on-demand l eStargz: OCI-compatible image format for lazy pulling with prefetch support • Can be lazily pulled from standard registries l Stargz Snapshotter: Plugin of containerd for enabling lazy pulling https://github.com/containerd/stargz-snapshotter 0 5 10 15 20 25 30 35 40 45 estargz estargz-noopt legacy Start up time of python:3.7 (print “hello”) pull create run [sec] Figure from “Faster Container Image Distribution on a Variety of Tools with Lazy Pulling - Kohei Tokunaga & Tao Peng. KubeCon+CloudNativeCon North America 2021. https://sched.co/lV2a “
  • 17. Copyright(c)2022 NTT Corp. All Rights Reserved. Lazy pulling (eStargz) on IPFS 17 l eStargz can be stored to IPFS l Stargz Snapshotter supports lazy pulling of eStargz from IPFS • mounts eStargz image from IPFS to container’s rootfs l Chunks are fetched lazily thus hopefully faster cold-start https://github.com/containerd/stargz-snapshotter proc container Node Stargz Snapshotter Fetching files/chunks on demand Moun@ng rooAs as FUSE Lazy pulling eStargz image IPFS Peer nerdctl
  • 18. Copyright(c)2022 NTT Corp. All Rights Reserved. Image encryption: OCIcrypt 18 l nerdctl supports encryp<on/decryp<on of image layers with key pair l OCIcrypt (imgcrypt plugin for containerd) is used Registry nerdctl image encrypt nerdctl image decrypt image image https://github.com/containerd/imgcrypt Public key Private key encrypts an image decrypts an image
  • 19. Copyright(c)2022 NTT Corp. All Rights Reserved. Image encryption (OCICrypt) on IPFS 19 l Encrypted image can be pushed to IPFS l Configuration of the image for IPFS (urls field) is done by “nerdctl push ipfs://” nerdctl image encrypt nerdctl image decrypt image image IPFS Public key Private key
  • 20. Copyright(c)2022 NTT Corp. All Rights Reserved. Future works 20 l Performance improvements • Especially on high bandwidth environment with small number of images • Pulling hangs when the searching image isn’t found on IPFS l Enabling “ipfs://CID” reference on a various tools (e.g. BuildKit, Kubernetes, …) l CID reproducibility • “nerdctl push ipfs://” will produce different CIDs for different configurations of IPFS • e.g. different chunk size l Higher availability of data • “pinning services” can be used maybe l …
  • 21. Copyright(c)2022 NTT Corp. All Rights Reserved. Related projects about image distribution on IPFS 21 l ipcs: https://github.com/hinshun/ipcs • Proposed by Edgar Lee (Netflix) • containerd content store plugin backed by IPFS • Focuses on content deduplication but incompatible to OCI image l ipdr: https://github.com/ipdr/ipdr • Proposed by Miguel Mota • Docker registry backed by IPFS • No native integration with runtime (requires a dedicated CLI) • Lazy pulling unsupported l EdgePier[1] • Proposed by Soeren Becker, et al. • Integrated ipdr (mentioned in the above) with Kubernetes • Fast image distribution under bandwidth-restricted environment • No OSS implementation [1] Soeren Becker, et al."EdgePier: P2P-based Container Image Distribution in Edge Computing Environments". IEEE International Performance Computing and Communications Conference 2021
  • 22. Copyright(c)2022 NTT Corp. All Rights Reserved. Summary 22 l nerdctl experimentally supports P2P image distribution on IPFS • simple UI/UX for P2P • allows IPFS-agnostic tools to get images from IPFS (e.g. BuildKit, Kubernetes) • fast image distribution from bandwidth-limited seeder l Combination with existing OCI image distribution techniques • lazy pulling of eStargz, image encryption by OCIcrypt Registry nerdctl push nerdctl pull pusher node receiver node peer peer nerdctl push nerdctl pull Registry-based image distribution IPFS-based image distribution IPFS Thanks to Akihiro Suda (NTT) for the discussion!