BuildKit and Kubernetes


BuildKit and Kubernetes

BuildKit can be used as a build service in Kubernetes

Multiple examples available

Pod

Proof-of-concept

BuildKit understands the schema kube-pod://

Deployment

Multiple pods can run simultaneously

Build is passed to any one of them by the service

Demo: BuildKit and Kubernetes

Pass build to remote pod

Create cluster:

kind create cluster

Run BuildKit daemon:

kubectl apply -f pod.rootless.yaml

Run build:

export BUILDKIT_HOST=kube-pod://buildkitd
buildctl build \
    --frontend=dockerfile.v0 \
    --local context=. \
    --local dockerfile=.

Using BuildKit with GitLab CI

Described in my blog post

Published demo on gitlab.com

Option 1: BuildKit daemon as service

Service is running next to build job

Connection is configured through variable BUILDKIT_HOST

Option 2: BuildKit daemonless

Using the buildctl-daemonless.sh script

BuildKit daemon is started on-the-fly

Using BuildKit in GitHub Actions

Official actions provided by Docker

Based on buildx

Comprehensive example

Actions

Obtain metadata for tagging and labels

Install qemu static binaries for buildx

Setup buildx for multi-platform builds

Login to Docker Hub for pushing images

Build and push container image