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 layersbuildctl 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
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
Create builder instance in current namespace
kubectl buildkit create
References
- vmware-tanzu/buildkit-cli-for-kubectl
- YouTube: BuildKit CLI for kubectl: A New Way to Build Container Images
- kim
- buildkitd.toml for configuration options