SlideShare a Scribd company logo
1 of 45
Download to read offline
BuildKit: A Modern Builder Toolkit on Top of
containerd (BuildKit: 建立在containerd之上的现代构建工具包)
Tõnis Tiigi, Docker
Akihiro Suda, NTT (须田 瑛大, 日本电信电话)
About us
2
Tonis Tiigi
@tonistiigi
Software engineer
Docker Inc.
Maintainer of BuildKit
and Moby/Docker
Akihiro Suda
@_AkihiroSuda_
Software engineer
NTT Corporation
Maintainer of BuildKit,
containerd, Moby...
3
What is BuildKit?
4
How are container images built?
Dockerfile
> docker build .
Bundled into Docker daemon
5
What’s the issue with old builder?
● Old design/codebase
● Tightly modeled after Dockerfile instructions
● Hard to add new (Dockerfile) features
● Suboptimal performance
● Leaks state to other Docker APIs
● Not usable for other projects
6
BuildKit solves these problems
● Dozens on new features and bugfixes
● Much faster
● Language agnostic
● Componentized
● Toolkit for building opinionated builders
7
Built on containerd
● Snapshotters
● Distribution
● Blobs storage
● GC
containerd - An open and reliable container runtime
8
Embraces OCI standards
● Process execution with OCI Runtime
specification
● Build results can be exported with OCI Image
specification (including manifest lists)
OCI - Open Container Initiative
Part 2
BuildKit Innovations
9
Problems of legacy docker build
10
● The legacy docker build does not compute
dependencies across Dockerfile instructions correctly
● Modifying line N always invalidates the cache for line
(N+1)
FROM debian
EXPOSE 80
RUN apt update && apt install -y HEAVY-PACKAGES
Problems of legacy docker build
11
FROM golang AS stage0
...
RUN go build –o /foo ...
FROM clang AS stage1
...
RUN clang –o /bar ...
FROM debian AS stage2
EXPOSE 80
RUN apt ...
COPY --from=stage0 /foo /
COPY --from=stage1 /bar /
0

2

1
 0

2

1

Expected schedule Actual
BuildKit LLB
12
● LLB is to Dockerfile what LLVM IR is to C
● Accurate dependency expression with graph structure
○ Efficient caching
○ Concurrent execution
● Encoded in protobuf; typically compiled from Dockerfile
○ Other “frontends” are also available:
Buildpacks, Mockerfile, Gockerfile, Docker Assemble
BuildKit LLB
13
SourceOp
...
ExecOp
SourceOp
...
ExecOp
SourceOp
ExecOp
FileOp
FROM golang AS stage0
...
RUN go build –o /foo ...
FROM clang AS stage1
...
RUN clang –o /bar ...
FROM debian AS stage2
EXPOSE 80
RUN apt ...
COPY --from=stage0 /foo /
COPY --from=stage1 /bar / FileOp
Note: No “ExposeOp”
•DAGはマルチステージDockerfileを用いて記述できる
BuildKit: 次世代 `docker build`
FROM golang AS stage0
...
RUN go build –o /foo ...
FROM clang AS stage1
...
RUN clang –o /bar ...
FROM debian AS stage2
COPY --from=stage0 /foo /usr/local/bin/foo
COPY --from=stage1 /bar /usr/local/bin/bar
0

2

1

https://t.co/aUKqQCVmXa
Extensible syntax
15
● “LLB frontend” container can be specified in the first
line of Dockerfile (# syntax = ...)
● You can also create your own LLB frontend container
i.e. you can define your own syntax
# syntax = docker/dockerfile:1.1-experimental
FROM ...
RUN ...
RUN --mount=type=cache
16
● Allows preserving caches of compilers and package
managers
# syntax = docker/dockerfile:1.1-experimental
...
RUN --mount=type=cache,target=/root/.cache go build
...
https://t.co/aUKqQCVmXa
RUN --mount=type=secret
18
● Allows accessing private assets without leaking
credential in the image
# syntax = docker/dockerfile:1.1-experimental
...
RUN --mount=type=secret,id=aws,target=/root/.aws/credentials 
aws s3 cp s3://... ...
$ buildctl build –-secret id=aws,src=~/.aws/credentials ...
RUN --mount=type=secret
19
● Note: DON’T do this!
...
COPY my_aws_credentials /root/.aws/credentials
RUN aws s3 cp s3://... …
RUN rm -f /root/.aws/credentials
...
RUN --mount=type=secret
20
● Note: DON’T do this either!
$ docker build 
--build-arg 
MY_AWS_CREDENTIALS=$(cat ~/.aws/credentials)
Part 3
Using BuildKit
21
22
Many ways to use BuildKit
● Docker, docker buildx
● img
● Tekton
● Rio, Pouch, vab
With or without daemon, in container, in k8s,
with containerd daemon, without root privileges, etc.
23
Docker
● Integrated into “docker build” v18.09+
● Opt-in:
export DOCKER_BUILDKIT=1
24
Docker
● Next generation Build command from Docker
● Familiar Docker UI + full BuildKit
● Manages instances of Builders and Build nodes
● With container driver, works with any version of
Docker engine
25
Docker Buildx
26
Buildx: Full BuildKit
● Remote caching (eg. for CI)
● Multi-platform images support
○ --platform=linux/amd64,linux/arm64
○ QEMU, distributed among nodes, or
cross-compilation in multi-stage Dockerfile
27
Buildx: Multi-platform images
● Webassembly: wasi/wasm
https://github.com/tonistiigi/wasm-cli-plugin
● Initial RISC-V support: linux/riscv64
https://tinyurl.com/docker-riscv
Part 4
Deploying BuildKit on Kubernetes
28
Why build images on Kube?
29
1. CI/CD
30
2. Developer Experience
Why build images on Kube?
1. CI/CD
Legacy docker build on Kubernetes
31
● docker
/var/run/docker.sock
● docker:dind
securityContext.privileged
●
Rootless mode
32
●
● securityContext
Rootless BuildKit vs Kaniko
33
● Kaniko runs as the root user but “unprivileged”
○ No need to disable seccomp and AppArmor
● Kaniko might be able to mitigate some vuln that
Rootless BuildKit cannot mitigate - and vice versa
○ Rootless BuildKit might be weak against kernel vulns
○ Kaniko might be weak against runc vulns
Deployment strategy
34
DaemonSet?
Deployment?
StatefulSet?
Job?
Deployment strategy
35
● Deployment
○ Most typical deployment
● DaemonSet
○ Optimal load-balancing but non-optimal caching
● StatefulSet
○ Good for Consistent Hashing (discussed later)
● Job
○ No need to manage the life cycles of the daemons
Caching
36
Load-balancing component
(Can be just headless svc with DNSRR)
gRPC
request
Image
Cache
Caching
37
●Remote cache might be slow compared to the
daemon-local cache
●Example:
○ No cache: 2m50s
○ Remote cache: 36s
○ Daemon-local cache: 0.5s
Caching
38
●Consistent hashing allows sticking a build request to a
specific Pod in StatefulSet
●Always hits the cache,
but non-optimal load
balancing
buildkitd-1
buildkitd-0
buildkitd-2
foo/Dockerfile
bar/Dockerfile
baz/Dockerfile
https://tinyurl.com/consistent-hash
39
Recap
● BuildKit is a modern container Build toolkit
● Significant advantages over previous tools
● Usable with Docker, K8s and many other tools
● Open platform for collaboration around build
Join us: https://github.com/moby/buildkit
Extra slides
41
Tekton
● CRD for building images
● Successor of Knative Build
42
Tekton
43
The interface is same as other image builders
(Buildah, Kaniko, and Makisu)
Credentials are loaded from the Secret
associated with the ServiceAccount
Tekton
44
Rancher Rio
45
● k8s/k3s-based micro PaaS
● “rio run https://github.com/…” builds and
deploy app in one-line
● Internally using BuildKit, but users don’t need to care
about BuildKit

More Related Content

More from Akihiro Suda

[CNCF TAG-Runtime] Usernetes Gen2
[CNCF TAG-Runtime] Usernetes Gen2[CNCF TAG-Runtime] Usernetes Gen2
[CNCF TAG-Runtime] Usernetes Gen2Akihiro Suda
 
[DockerCon 2023] Reproducible builds with BuildKit for software supply chain ...
[DockerCon 2023] Reproducible builds with BuildKit for software supply chain ...[DockerCon 2023] Reproducible builds with BuildKit for software supply chain ...
[DockerCon 2023] Reproducible builds with BuildKit for software supply chain ...Akihiro Suda
 
The internals and the latest trends of container runtimes
The internals and the latest trends of container runtimesThe internals and the latest trends of container runtimes
The internals and the latest trends of container runtimesAkihiro Suda
 
[KubeConEU2023] Lima pavilion
[KubeConEU2023] Lima pavilion[KubeConEU2023] Lima pavilion
[KubeConEU2023] Lima pavilionAkihiro Suda
 
[KubeConEU2023] containerd pavilion
[KubeConEU2023] containerd pavilion[KubeConEU2023] containerd pavilion
[KubeConEU2023] containerd pavilionAkihiro Suda
 
[Container Plumbing Days 2023] Why was nerdctl made?
[Container Plumbing Days 2023] Why was nerdctl made?[Container Plumbing Days 2023] Why was nerdctl made?
[Container Plumbing Days 2023] Why was nerdctl made?Akihiro Suda
 
[FOSDEM2023] Bit-for-bit reproducible builds with Dockerfile
[FOSDEM2023] Bit-for-bit reproducible builds with Dockerfile[FOSDEM2023] Bit-for-bit reproducible builds with Dockerfile
[FOSDEM2023] Bit-for-bit reproducible builds with DockerfileAkihiro Suda
 
[CNCF TAG-Runtime 2022-10-06] Lima
[CNCF TAG-Runtime 2022-10-06] Lima[CNCF TAG-Runtime 2022-10-06] Lima
[CNCF TAG-Runtime 2022-10-06] LimaAkihiro Suda
 
[KubeCon EU 2022] Running containerd and k3s on macOS
[KubeCon EU 2022] Running containerd and k3s on macOS[KubeCon EU 2022] Running containerd and k3s on macOS
[KubeCon EU 2022] Running containerd and k3s on macOSAkihiro Suda
 
Dockerからcontainerdへの移行
Dockerからcontainerdへの移行Dockerからcontainerdへの移行
Dockerからcontainerdへの移行Akihiro Suda
 
[Paris Container Day 2021] nerdctl: yet another Docker & Docker Compose imple...
[Paris Container Day 2021] nerdctl: yet another Docker & Docker Compose imple...[Paris Container Day 2021] nerdctl: yet another Docker & Docker Compose imple...
[Paris Container Day 2021] nerdctl: yet another Docker & Docker Compose imple...Akihiro Suda
 
[Docker Tokyo #35] Docker 20.10
[Docker Tokyo #35] Docker 20.10[Docker Tokyo #35] Docker 20.10
[Docker Tokyo #35] Docker 20.10Akihiro Suda
 
[KubeCon EU 2021] Introduction and Deep Dive Into Containerd
[KubeCon EU 2021] Introduction and Deep Dive Into Containerd[KubeCon EU 2021] Introduction and Deep Dive Into Containerd
[KubeCon EU 2021] Introduction and Deep Dive Into ContainerdAkihiro Suda
 
DockerとPodmanの比較
DockerとPodmanの比較DockerとPodmanの比較
DockerとPodmanの比較Akihiro Suda
 
[KubeCon NA 2020] containerd: Rootless Containers 2020
[KubeCon NA 2020] containerd: Rootless Containers 2020[KubeCon NA 2020] containerd: Rootless Containers 2020
[KubeCon NA 2020] containerd: Rootless Containers 2020Akihiro Suda
 
[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep Dive[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep DiveAkihiro Suda
 
[DockerCon 2020] Hardening Docker daemon with Rootless Mode
[DockerCon 2020] Hardening Docker daemon with Rootless Mode[DockerCon 2020] Hardening Docker daemon with Rootless Mode
[DockerCon 2020] Hardening Docker daemon with Rootless ModeAkihiro Suda
 
[FOSDEM 2020] Lazy distribution of container images
[FOSDEM 2020] Lazy distribution of container images[FOSDEM 2020] Lazy distribution of container images
[FOSDEM 2020] Lazy distribution of container imagesAkihiro Suda
 
[KubeConUS2019 Docker, Inc. Booth] Distributed Builds on Kubernetes with Bui...
 [KubeConUS2019 Docker, Inc. Booth] Distributed Builds on Kubernetes with Bui... [KubeConUS2019 Docker, Inc. Booth] Distributed Builds on Kubernetes with Bui...
[KubeConUS2019 Docker, Inc. Booth] Distributed Builds on Kubernetes with Bui...Akihiro Suda
 
[Container Runtime Meetup] runc & User Namespaces
[Container Runtime Meetup] runc & User Namespaces[Container Runtime Meetup] runc & User Namespaces
[Container Runtime Meetup] runc & User NamespacesAkihiro Suda
 

More from Akihiro Suda (20)

[CNCF TAG-Runtime] Usernetes Gen2
[CNCF TAG-Runtime] Usernetes Gen2[CNCF TAG-Runtime] Usernetes Gen2
[CNCF TAG-Runtime] Usernetes Gen2
 
[DockerCon 2023] Reproducible builds with BuildKit for software supply chain ...
[DockerCon 2023] Reproducible builds with BuildKit for software supply chain ...[DockerCon 2023] Reproducible builds with BuildKit for software supply chain ...
[DockerCon 2023] Reproducible builds with BuildKit for software supply chain ...
 
The internals and the latest trends of container runtimes
The internals and the latest trends of container runtimesThe internals and the latest trends of container runtimes
The internals and the latest trends of container runtimes
 
[KubeConEU2023] Lima pavilion
[KubeConEU2023] Lima pavilion[KubeConEU2023] Lima pavilion
[KubeConEU2023] Lima pavilion
 
[KubeConEU2023] containerd pavilion
[KubeConEU2023] containerd pavilion[KubeConEU2023] containerd pavilion
[KubeConEU2023] containerd pavilion
 
[Container Plumbing Days 2023] Why was nerdctl made?
[Container Plumbing Days 2023] Why was nerdctl made?[Container Plumbing Days 2023] Why was nerdctl made?
[Container Plumbing Days 2023] Why was nerdctl made?
 
[FOSDEM2023] Bit-for-bit reproducible builds with Dockerfile
[FOSDEM2023] Bit-for-bit reproducible builds with Dockerfile[FOSDEM2023] Bit-for-bit reproducible builds with Dockerfile
[FOSDEM2023] Bit-for-bit reproducible builds with Dockerfile
 
[CNCF TAG-Runtime 2022-10-06] Lima
[CNCF TAG-Runtime 2022-10-06] Lima[CNCF TAG-Runtime 2022-10-06] Lima
[CNCF TAG-Runtime 2022-10-06] Lima
 
[KubeCon EU 2022] Running containerd and k3s on macOS
[KubeCon EU 2022] Running containerd and k3s on macOS[KubeCon EU 2022] Running containerd and k3s on macOS
[KubeCon EU 2022] Running containerd and k3s on macOS
 
Dockerからcontainerdへの移行
Dockerからcontainerdへの移行Dockerからcontainerdへの移行
Dockerからcontainerdへの移行
 
[Paris Container Day 2021] nerdctl: yet another Docker & Docker Compose imple...
[Paris Container Day 2021] nerdctl: yet another Docker & Docker Compose imple...[Paris Container Day 2021] nerdctl: yet another Docker & Docker Compose imple...
[Paris Container Day 2021] nerdctl: yet another Docker & Docker Compose imple...
 
[Docker Tokyo #35] Docker 20.10
[Docker Tokyo #35] Docker 20.10[Docker Tokyo #35] Docker 20.10
[Docker Tokyo #35] Docker 20.10
 
[KubeCon EU 2021] Introduction and Deep Dive Into Containerd
[KubeCon EU 2021] Introduction and Deep Dive Into Containerd[KubeCon EU 2021] Introduction and Deep Dive Into Containerd
[KubeCon EU 2021] Introduction and Deep Dive Into Containerd
 
DockerとPodmanの比較
DockerとPodmanの比較DockerとPodmanの比較
DockerとPodmanの比較
 
[KubeCon NA 2020] containerd: Rootless Containers 2020
[KubeCon NA 2020] containerd: Rootless Containers 2020[KubeCon NA 2020] containerd: Rootless Containers 2020
[KubeCon NA 2020] containerd: Rootless Containers 2020
 
[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep Dive[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep Dive
 
[DockerCon 2020] Hardening Docker daemon with Rootless Mode
[DockerCon 2020] Hardening Docker daemon with Rootless Mode[DockerCon 2020] Hardening Docker daemon with Rootless Mode
[DockerCon 2020] Hardening Docker daemon with Rootless Mode
 
[FOSDEM 2020] Lazy distribution of container images
[FOSDEM 2020] Lazy distribution of container images[FOSDEM 2020] Lazy distribution of container images
[FOSDEM 2020] Lazy distribution of container images
 
[KubeConUS2019 Docker, Inc. Booth] Distributed Builds on Kubernetes with Bui...
 [KubeConUS2019 Docker, Inc. Booth] Distributed Builds on Kubernetes with Bui... [KubeConUS2019 Docker, Inc. Booth] Distributed Builds on Kubernetes with Bui...
[KubeConUS2019 Docker, Inc. Booth] Distributed Builds on Kubernetes with Bui...
 
[Container Runtime Meetup] runc & User Namespaces
[Container Runtime Meetup] runc & User Namespaces[Container Runtime Meetup] runc & User Namespaces
[Container Runtime Meetup] runc & User Namespaces
 

Recently uploaded

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 

Recently uploaded (20)

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 

[KubeCon China 2019] BuildKit: A Modern Builder Toolkit on Top of containerd

  • 1. BuildKit: A Modern Builder Toolkit on Top of containerd (BuildKit: 建立在containerd之上的现代构建工具包) Tõnis Tiigi, Docker Akihiro Suda, NTT (须田 瑛大, 日本电信电话)
  • 2. About us 2 Tonis Tiigi @tonistiigi Software engineer Docker Inc. Maintainer of BuildKit and Moby/Docker Akihiro Suda @_AkihiroSuda_ Software engineer NTT Corporation Maintainer of BuildKit, containerd, Moby...
  • 4. 4 How are container images built? Dockerfile > docker build . Bundled into Docker daemon
  • 5. 5 What’s the issue with old builder? ● Old design/codebase ● Tightly modeled after Dockerfile instructions ● Hard to add new (Dockerfile) features ● Suboptimal performance ● Leaks state to other Docker APIs ● Not usable for other projects
  • 6. 6 BuildKit solves these problems ● Dozens on new features and bugfixes ● Much faster ● Language agnostic ● Componentized ● Toolkit for building opinionated builders
  • 7. 7 Built on containerd ● Snapshotters ● Distribution ● Blobs storage ● GC containerd - An open and reliable container runtime
  • 8. 8 Embraces OCI standards ● Process execution with OCI Runtime specification ● Build results can be exported with OCI Image specification (including manifest lists) OCI - Open Container Initiative
  • 10. Problems of legacy docker build 10 ● The legacy docker build does not compute dependencies across Dockerfile instructions correctly ● Modifying line N always invalidates the cache for line (N+1) FROM debian EXPOSE 80 RUN apt update && apt install -y HEAVY-PACKAGES
  • 11. Problems of legacy docker build 11 FROM golang AS stage0 ... RUN go build –o /foo ... FROM clang AS stage1 ... RUN clang –o /bar ... FROM debian AS stage2 EXPOSE 80 RUN apt ... COPY --from=stage0 /foo / COPY --from=stage1 /bar / 0
 2
 1
 0
 2
 1
 Expected schedule Actual
  • 12. BuildKit LLB 12 ● LLB is to Dockerfile what LLVM IR is to C ● Accurate dependency expression with graph structure ○ Efficient caching ○ Concurrent execution ● Encoded in protobuf; typically compiled from Dockerfile ○ Other “frontends” are also available: Buildpacks, Mockerfile, Gockerfile, Docker Assemble
  • 13. BuildKit LLB 13 SourceOp ... ExecOp SourceOp ... ExecOp SourceOp ExecOp FileOp FROM golang AS stage0 ... RUN go build –o /foo ... FROM clang AS stage1 ... RUN clang –o /bar ... FROM debian AS stage2 EXPOSE 80 RUN apt ... COPY --from=stage0 /foo / COPY --from=stage1 /bar / FileOp Note: No “ExposeOp”
  • 14. •DAGはマルチステージDockerfileを用いて記述できる BuildKit: 次世代 `docker build` FROM golang AS stage0 ... RUN go build –o /foo ... FROM clang AS stage1 ... RUN clang –o /bar ... FROM debian AS stage2 COPY --from=stage0 /foo /usr/local/bin/foo COPY --from=stage1 /bar /usr/local/bin/bar 0
 2
 1
 https://t.co/aUKqQCVmXa
  • 15. Extensible syntax 15 ● “LLB frontend” container can be specified in the first line of Dockerfile (# syntax = ...) ● You can also create your own LLB frontend container i.e. you can define your own syntax # syntax = docker/dockerfile:1.1-experimental FROM ... RUN ...
  • 16. RUN --mount=type=cache 16 ● Allows preserving caches of compilers and package managers # syntax = docker/dockerfile:1.1-experimental ... RUN --mount=type=cache,target=/root/.cache go build ...
  • 18. RUN --mount=type=secret 18 ● Allows accessing private assets without leaking credential in the image # syntax = docker/dockerfile:1.1-experimental ... RUN --mount=type=secret,id=aws,target=/root/.aws/credentials aws s3 cp s3://... ... $ buildctl build –-secret id=aws,src=~/.aws/credentials ...
  • 19. RUN --mount=type=secret 19 ● Note: DON’T do this! ... COPY my_aws_credentials /root/.aws/credentials RUN aws s3 cp s3://... … RUN rm -f /root/.aws/credentials ...
  • 20. RUN --mount=type=secret 20 ● Note: DON’T do this either! $ docker build --build-arg MY_AWS_CREDENTIALS=$(cat ~/.aws/credentials)
  • 22. 22 Many ways to use BuildKit ● Docker, docker buildx ● img ● Tekton ● Rio, Pouch, vab With or without daemon, in container, in k8s, with containerd daemon, without root privileges, etc.
  • 23. 23 Docker ● Integrated into “docker build” v18.09+ ● Opt-in: export DOCKER_BUILDKIT=1
  • 25. ● Next generation Build command from Docker ● Familiar Docker UI + full BuildKit ● Manages instances of Builders and Build nodes ● With container driver, works with any version of Docker engine 25 Docker Buildx
  • 26. 26 Buildx: Full BuildKit ● Remote caching (eg. for CI) ● Multi-platform images support ○ --platform=linux/amd64,linux/arm64 ○ QEMU, distributed among nodes, or cross-compilation in multi-stage Dockerfile
  • 27. 27 Buildx: Multi-platform images ● Webassembly: wasi/wasm https://github.com/tonistiigi/wasm-cli-plugin ● Initial RISC-V support: linux/riscv64 https://tinyurl.com/docker-riscv
  • 28. Part 4 Deploying BuildKit on Kubernetes 28
  • 29. Why build images on Kube? 29 1. CI/CD
  • 30. 30 2. Developer Experience Why build images on Kube? 1. CI/CD
  • 31. Legacy docker build on Kubernetes 31 ● docker /var/run/docker.sock ● docker:dind securityContext.privileged ●
  • 33. Rootless BuildKit vs Kaniko 33 ● Kaniko runs as the root user but “unprivileged” ○ No need to disable seccomp and AppArmor ● Kaniko might be able to mitigate some vuln that Rootless BuildKit cannot mitigate - and vice versa ○ Rootless BuildKit might be weak against kernel vulns ○ Kaniko might be weak against runc vulns
  • 35. Deployment strategy 35 ● Deployment ○ Most typical deployment ● DaemonSet ○ Optimal load-balancing but non-optimal caching ● StatefulSet ○ Good for Consistent Hashing (discussed later) ● Job ○ No need to manage the life cycles of the daemons
  • 36. Caching 36 Load-balancing component (Can be just headless svc with DNSRR) gRPC request Image Cache
  • 37. Caching 37 ●Remote cache might be slow compared to the daemon-local cache ●Example: ○ No cache: 2m50s ○ Remote cache: 36s ○ Daemon-local cache: 0.5s
  • 38. Caching 38 ●Consistent hashing allows sticking a build request to a specific Pod in StatefulSet ●Always hits the cache, but non-optimal load balancing buildkitd-1 buildkitd-0 buildkitd-2 foo/Dockerfile bar/Dockerfile baz/Dockerfile https://tinyurl.com/consistent-hash
  • 39. 39 Recap ● BuildKit is a modern container Build toolkit ● Significant advantages over previous tools ● Usable with Docker, K8s and many other tools ● Open platform for collaboration around build
  • 42. Tekton ● CRD for building images ● Successor of Knative Build 42
  • 43. Tekton 43 The interface is same as other image builders (Buildah, Kaniko, and Makisu) Credentials are loaded from the Secret associated with the ServiceAccount
  • 45. Rancher Rio 45 ● k8s/k3s-based micro PaaS ● “rio run https://github.com/…” builds and deploy app in one-line ● Internally using BuildKit, but users don’t need to care about BuildKit