Skip to content

Latest commit

 

History

History
96 lines (62 loc) · 2.49 KB

buildkit-kubes.md

File metadata and controls

96 lines (62 loc) · 2.49 KB

buildkit in kubernetes

Install buildctl: brew install buildkit

Define a rootless kubernetes builder instance in the default kube namespace with two replicas:

docker buildx create --driver kubernetes --name kubebkd \
    --driver-opt rootless=true --driver-opt replicas=2 \
    --driver-opt requests.cpu=1000m --driver-opt requests.memory=1G \
    --driver-opt limits.cpu=1000m --driver-opt limits.memory=1G

A Kubernetes Deployment is created on first use:

docker buildx --builder mybuilder build .

To talk to the instance, the docker client execs buildctl dial-stdio inside the pod and streams stdin/out.

Watch the build process:

kubectl exec -it mybuilder0-57966d47cb-z99fs -- ps -o pid,ppid,time,args

Within the buildkitd container:

  • Images are stored in /home/user/.local/share/buildkit/runc-native
  • buildctl du will show layers and their size, use --verbose to see command used for the layers
  • buildctl build can be used to manually build

The pods, and their cache, remain until killed.

Delete builder instance which removes the Kubernetes Deployment:

docker buildx rm mybuilder

List builders

docker buildx ls

Inspect current builder

docker build inspectx

Change current builder instance to the default

docker build use default

Pod exec

Create a pod:

kubectl apply -f pod.rootless.yaml

Connect via the exec buildctl stdio method:

buildctl --addr kube-pod://buildkitd build --frontend dockerfile.v0 --local context=/path/to/dir --local dockerfile=/path/to/dir

Service

BuildKit CLI for kubectl

Create builder instance in current namespace

kubectl buildkit create

References

See also