Prerequisites
Before you start, make sure you have:- Flox installed
- A FloxHub login — run
flox auth login
just up copies your token into a Kubernetes secret for you
and stops with an error if you are not logged in. See
Configuration for how that secret is created
and mounted.
Running the example
The entirety of this example can be run locally with the following commands:kind and deploys a web server
backed by Redis.
To fetch something from the web server, run:
Quotes app environment
The example runs a deployment offlox/quotes-app, which is just like any other
Kubernetes deployment, but with a few key differences.
Here’s a snippet from the deployment manifest:
- Specifying
runtimeClassName: floxruns the container using the Flox containerd shim. - The annotation
flox.dev/environment: "flox/quotes-app"specifies the Flox environment to use to bootstrap the container filesystem instead of a container image
["quotes-app-go", "-r", "redis:6379"] in this case.
When the container starts, the flox/quotes-app Flox environment is pulled from FloxHub and bind mounted into the container.
This environment contains the flox/quotes-app-go package, which is a simple web server published to FloxHub.
When the container starts, the environment is activated, and then quotes-app-go is run inside the activated environment.
Redis environment
Thequotes-app-go server uses a Redis instance running in a second deployment.
Just like the first pod, rather than specifying a container image, the Redis
deployment runs the environment flox/redis which is pulled from
hub.flox.dev/flox/redis.
Here’s the relevant snippet from the Redis deployment manifest:
Updating the deployment
Because the environment is hosted on FloxHub, there’s no need to rebuild a container image to update the deployment. After a change toquotes-app-go, updating the deployment would require running
a flox publish for quotes-app-go and a flox upgrade -r flox/quotes-app.
After that, restarting a pod will pull the latest generation of the environment.
This allows deploying software with the reproducibility of a container, but
without the overhead of having to rebuild an entire container image when iterating.