Oct 1 2024

Run Dev Containers on Kubernetes and OpenShift with Envbuilder

Théo Devantoy
Théo Devantoy

> To learn more about Envbuilder’s use cases and benefits, check out our introductory blog post here!

Envbuilder allows you to build development environments from a Dev Container on Docker and Kubernetes or OpenShift.

In this post, we’ll explore some examples. These examples assume you already have an existing dev container spec in the .devcontainer folder at the root of your project’s repository. If you don’t, check out VS Code’s Dev Containers Tutorial.

Vanilla Kubernetes

Quick example

Here is an example Kubernetes manifest that shows how to spawn a Pod from the Dev Container spec available in our envbuilder-starter-devcontainer repository and obtain an interactive Bash shell from it.

yaml

After applying the manifest (e.g., via kubectl apply), you should be able to run kubectl exec --stdin --tty devcontainer -- bash to get a bash session.

Running Staging Environments in Dev Containers

Running your staging environment using Dev Containers can have multiple benefits.

The main advantage is having all the debugging tools you know and love ready to start debugging any issues that may arise in the staging environment.

Additionally, this approach helps identify and eliminate any bugs or issues that might be present in the Dev Container spec.

In this example, we’ll run an ephemeral web server using Deno, but you can easily modify this manifest to run the staging environment for your project.

yaml

Caching

In both of these cases, the Dev Container will be built from scratch every time you start the pod, which is fine for prototyping but can become quite slow.

To speed up your builds, you can cache the layers of the image.

Using a Container Registry

Envbuilder supports caching layers in a container registry. To enable this, configure authentication to your registry and set the ENVBUILDER_CACHE_REPO environment variable.

See the “Layer Caching” section in Envbuilder’s README for more information.

Using a Volume

Envbuilder also supports caching layers in a folder, but this method is only intended for testing. For production, it’s best to use a container registry.

You can mount a PersistentVolume to the Pod and pass its path in the ENVBUILDER_LAYER_CACHE_DIR environment variable.

Conclusion

Envbuilder streamlines the setup and management of development environments, making workflows more efficient and flexible. Whether for prototyping or production, it offers a powerful solution for modern development needs.

You can check out EnvBuilder on Github. Want a demo? Contact us.