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
containerdの概要と最近の機能
PDF
今話題のいろいろなコンテナランタイムを比較してみた
PPTX
コンテナネットワーキング(CNI)最前線
PDF
Dockerからcontainerdへの移行
PDF
eStargzイメージとlazy pullingによる高速なコンテナ起動
PDF
コンテナ未経験新人が学ぶコンテナ技術入門
PDF
ML2/OVN アーキテクチャ概観
PDF
NetflixにおけるPresto/Spark活用事例
containerdの概要と最近の機能
今話題のいろいろなコンテナランタイムを比較してみた
コンテナネットワーキング(CNI)最前線
Dockerからcontainerdへの移行
eStargzイメージとlazy pullingによる高速なコンテナ起動
コンテナ未経験新人が学ぶコンテナ技術入門
ML2/OVN アーキテクチャ概観
NetflixにおけるPresto/Spark活用事例

What's hot (20)

PDF
BuildKitの概要と最近の機能
PDF
Kuberneteの運用を支えるGitOps
PPTX
BuildKitによる高速でセキュアなイメージビルド
PPTX
OVN 設定サンプル | OVN config example 2015/12/27
PPTX
急速に進化を続けるCNIプラグイン Antrea
PDF
自宅vSphereからニフクラに引っ越ししてみた
PDF
The overview of lazypull with containerd Remote Snapshotter & Stargz Snapshotter
PDF
Kubernetesのしくみ やさしく学ぶ 内部構造とアーキテクチャー
ODP
Kubernetes Architecture
PDF
BuildKitでLazy Pullを有効にしてビルドを早くする話
PDF
わかる!metadata.managedFields / Kubernetes Meetup Tokyo 48
PDF
Kubernetes Service Account As Multi-Cloud Identity / Cloud Native Security Co...
PDF
Stargz Snapshotter: イメージのpullを省略しcontainerdでコンテナを高速に起動する
PDF
PFN のオンプレML基盤の取り組み / オンプレML基盤 on Kubernetes 〜PFN、ヤフー〜
PDF
PostgreSQLをKubernetes上で活用するためのOperator紹介!(Cloud Native Database Meetup #3 発表資料)
PDF
OpenStack-Ansibleで作るOpenStack HA環境 手順書解説 - OpenStack最新情報セミナー 2016年3月
PDF
KubeCon + CloudNativeCon Europe 2022 Recap / Kubernetes Meetup Tokyo #51 / #k...
PPTX
OpenStack概要 ~仮想ネットワーク~
PPTX
Dockerからcontainerdへの移行
PPTX
Docker Networking with New Ipvlan and Macvlan Drivers
BuildKitの概要と最近の機能
Kuberneteの運用を支えるGitOps
BuildKitによる高速でセキュアなイメージビルド
OVN 設定サンプル | OVN config example 2015/12/27
急速に進化を続けるCNIプラグイン Antrea
自宅vSphereからニフクラに引っ越ししてみた
The overview of lazypull with containerd Remote Snapshotter & Stargz Snapshotter
Kubernetesのしくみ やさしく学ぶ 内部構造とアーキテクチャー
Kubernetes Architecture
BuildKitでLazy Pullを有効にしてビルドを早くする話
わかる!metadata.managedFields / Kubernetes Meetup Tokyo 48
Kubernetes Service Account As Multi-Cloud Identity / Cloud Native Security Co...
Stargz Snapshotter: イメージのpullを省略しcontainerdでコンテナを高速に起動する
PFN のオンプレML基盤の取り組み / オンプレML基盤 on Kubernetes 〜PFN、ヤフー〜
PostgreSQLをKubernetes上で活用するためのOperator紹介!(Cloud Native Database Meetup #3 発表資料)
OpenStack-Ansibleで作るOpenStack HA環境 手順書解説 - OpenStack最新情報セミナー 2016年3月
KubeCon + CloudNativeCon Europe 2022 Recap / Kubernetes Meetup Tokyo #51 / #k...
OpenStack概要 ~仮想ネットワーク~
Dockerからcontainerdへの移行
Docker Networking with New Ipvlan and Macvlan Drivers
Ad

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

PPTX
Usernetes: Kubernetes as a non-root user
PDF
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
PDF
[KubeCon EU 2020] containerd Deep Dive
PDF
ISC HPCW talks
PDF
Kubernetes
PDF
DockerとKubernetesをかけめぐる
PDF
Method of NUMA-Aware Resource Management for Kubernetes 5G NFV Cluster
PDF
Comparing Next-Generation Container Image Building Tools
PDF
Linux rumpkernel - ABC2018 (AsiaBSDCon 2018)
PDF
[FOSDEM 2020] Lazy distribution of container images
PDF
Kubernetes Basis: Pods, Deployments, and Services
PPTX
Introducing Container Technology to TSUBAME3.0 Supercomputer
PDF
[KubeCon NA 2020] containerd: Rootless Containers 2020
PDF
Introduction of eBPF - 時下最夯的Linux Technology
PDF
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PDF
4. CNCF kubernetes Comparison of-existing-cni-plugins-for-kubernetes
PDF
[Paris Container Day 2021] nerdctl: yet another Docker & Docker Compose imple...
PPTX
Comparison of existing cni plugins for kubernetes
PDF
Using VPP and SRIO-V with Clear Containers
PDF
LinuxKit Deep Dive
Usernetes: Kubernetes as a non-root user
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
[KubeCon EU 2020] containerd Deep Dive
ISC HPCW talks
Kubernetes
DockerとKubernetesをかけめぐる
Method of NUMA-Aware Resource Management for Kubernetes 5G NFV Cluster
Comparing Next-Generation Container Image Building Tools
Linux rumpkernel - ABC2018 (AsiaBSDCon 2018)
[FOSDEM 2020] Lazy distribution of container images
Kubernetes Basis: Pods, Deployments, and Services
Introducing Container Technology to TSUBAME3.0 Supercomputer
[KubeCon NA 2020] containerd: Rootless Containers 2020
Introduction of eBPF - 時下最夯的Linux Technology
PyCon SG 25 - Firecracker Made Easy with Python.pdf
4. CNCF kubernetes Comparison of-existing-cni-plugins-for-kubernetes
[Paris Container Day 2021] nerdctl: yet another Docker & Docker Compose imple...
Comparison of existing cni plugins for kubernetes
Using VPP and SRIO-V with Clear Containers
LinuxKit Deep Dive
Ad

More from Kohei Tokunaga (8)

PDF
Faster Container Image Distribution on a Variety of Tools with Lazy Pulling
PDF
Introduction and Deep Dive Into Containerd
PDF
Starting up Containers Super Fast With Lazy Pulling of Images
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:ランタイムとイメージの話題ダイジェスト
Faster Container Image Distribution on a Variety of Tools with Lazy Pulling
Introduction and Deep Dive Into Containerd
Starting up Containers Super Fast With Lazy Pulling of Images
Startup Containers in Lightning Speed with Lazy Image Distribution
Stargz Snapshotter: イメージのpullを省略してcontainerdでコンテナを高速に起動する
OCIランタイムの筆頭「runc」を俯瞰する
OCIv2?!軽量高速なイケてる次世代イメージ仕様の最新動向を抑えよう!
5分で振り返るKubeCon EU 2019:ランタイムとイメージの話題ダイジェスト

Recently uploaded (20)

PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
ai tools demonstartion for schools and inter college
PDF
top salesforce developer skills in 2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
medical staffing services at VALiNTRY
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Digital Strategies for Manufacturing Companies
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Computer Software and OS of computer science of grade 11.pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
ai tools demonstartion for schools and inter college
top salesforce developer skills in 2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
medical staffing services at VALiNTRY
Adobe Illustrator 28.6 Crack My Vision of Vector Design
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Digital Strategies for Manufacturing Companies
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Softaken Excel to vCard Converter Software.pdf
Operating system designcfffgfgggggggvggggggggg
Odoo Companies in India – Driving Business Transformation.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Wondershare Filmora 15 Crack With Activation Key [2025
PTS Company Brochure 2025 (1).pdf.......
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...

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!