Author: Gaëtan Lehmann
kubectl_build
integrates BuildKit CLI for kubectl, a tool for building OCI and Docker images with your kubernetes cluster, with tilt.
Having the images built directly in the cluster has several benefits:
- faster build cycles: no need to transfer the image from the current host to regitry, and from the registry to the cluster;
- smaller disk usage: when working with a local k8s instance like kind or docker desktop, we usually have 3 times the image on the local disk (one, for the builld output, one for the registry and a last one in the cluster). With kubectl_build, there is only one copy of the image, in the k8s cluster.
kubectl build
must be installed on your computer. See BuildKit CLI for kubectl's Getting started for instructions.
Load the extension in your Tiltfile
, and replace the docker_build
calls by kubectl_build
.
load('ext://kubectl_build', 'kubectl_build')
kubectl_build('gcr.io/foo/bar', '.')
kubectl_build
supports the same arguments than docker_build
(with a few exceptions, see the Limitations section).
By default, kubectl_build
uses the docker-registry
secret to pull the images, if it exists.
You can use another secret by passing the registry_secret
argument to the kubectl_build
call:
kubectl_build('gcr.io/foo/bar', '.', registry_secret='my-secret')
You may also set the KUBECTL_BUILD_REGISTRY_SECRET
environment variable with the secret name.
kubectl_build
can push the image to a registry by supplying the push=True
argument.
Similar to pulling an image from a private repository, you can specify the registry_secret
argument to authenticate.
kubectl_build('gcr.io/foo/bar', '.', push=True, registry_secret='my-secret')
kubectl_build
supports almost all the docker_build
arguments, except:
container_args
dockerfile_contents
network
only
some of these arguments may be added in the future (a pull request is welcome!).
BuildKit CLI for kubectl doesn't support env
secrets at this time, so you have to convert them to file to use this extension.
BuildKit CLI for kubectl doesn't support all the local k8s clusters equally — k3d, for example, is known to not be supported; with kind, the image tag must include the repository name.