Skip to content
These docs are still under construction and may contain outdated references to Earthly and/or broken links.
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Kubernetes

Note

This guide describes deploying BuildKit to Kubernetes by hand. EarthBuild/helm-buildkitd is a Helm chart for the same job, with scale-to-zero support, and is intended to supersede this guide. It is currently alpha -- no tagged release yet -- so the manual setup below remains the supported path for now.

Overview

Kubernetes isn't a CI per-se, but it can serve as the underpinning for many modern CI systems. As such, this example serves as a bare-bones example to base your implementations on.

Compatibility

earth has been tested with the all-in-one earthbuild/earthbuild mode, and works as long as the pod runs in a privileged mode.

It has also been tested with a single remote earthbuild/buildkitd running in privileged mode, and an earthbuild/earthbuild pod running without any additional security concerns. This configuration is considered experimental. See these additional instructions.

Multi-node earthbuild/buildkitd configurations are currently unsupported.

Resources

Setup (earthbuild/earthbuild Only)

This is the recommended approach when using EarthBuild within Kubernetes. Assuming you are following the steps outlined in the overview, here are the additional things you need to configure:

Dependencies

Your Kubernetes cluster needs to allow privileged mode pods. It's possible to use a separate instance group, along with Taints and Tolerations to effectively segregate these pods.

Installation

The default image from earthbuild/earthbuild should be sufficient. If you need additional tools or configuration, you can create your own runner image.

Configuration

In some instances, notably when using Calico within your cluster, the MTU of the clusters network may end up mismatched with the internal CNI network, preventing external communication. You can set this through the CNI_MTU environment variable to force a match.

earthbuild/earthbuild currently requires the use of privileged mode. Use this in your container spec to enable it:

The earthbuild/earthbuild container will operate best when provided with decent storage for intermediate operations. Mount a volume like this:

The location within the container for this temporary folder is configurable with the EARTH_TMP_DIR environment variable.

The earthbuild/earthbuild image will expect to find the source code (with Earthfile) rooted in the default working directory, which is set to /workspace.

Setup (Remote earthbuild/buildkitd)

It is possible to run multiple earthbuild/buildkitd instances in Kubernetes, for larger deployments. Follow the configuration instructions for using the earthbuild/earthbuild image above.

There are some caveats that come with this kind of a setup, though:

  1. Some local cache is not available across instances, so it may take a while for the cache to become "warm".

  2. Builds that occur across multiple instances simultaneously may fail in odd ways. This is not supported.

  3. The TLS configuration needs to be shared across the entire fleet.

Configuration

To mitigate some of the issues, it is recommended to run in a "sticky" mode to keep builds pinned to a single instance for the duration. You can see how to do this in our example:

Example

This example requires kind and kubectl:

Create a cluster:

All-in-one

The simplest setup runs the all-in-one image as a Job, with its embedded buildkitd. It needs privileged, since buildkitd does not currently support rootless mode:

Apply it, then follow the build:

Remote buildkitd

To keep a warm cache across builds, run buildkitd as its own Deployment and point the client at it. Only the daemon needs to be privileged:

The client Job then points at the service and needs no privileges of its own:

To tear the cluster down:

Last updated