|
| 1 | +--- |
| 2 | +title: "Configuration" |
| 3 | +description: "Configuring Imageless Kubernetes" |
| 4 | +--- |
| 5 | + |
| 6 | +# Configuration |
| 7 | + |
| 8 | +## Authentication |
| 9 | + |
| 10 | +Imageless Kubernetes allows you to run Flox environments in place of or on top of container images. |
| 11 | +Flox environments are accessed centrally via [FloxHub][floxhub] and managed using the Flox CLI. |
| 12 | + |
| 13 | +In the [introduction][intro] we discussed how annotations are used to tell Imageless Kubernetes which Flox environment to run. |
| 14 | +However, we assumed that the referenced environment was publicly available without authentication. |
| 15 | +If you plan to use private environments, you will have to authenticate Imageless Kubernetes using your FloxHub user credentials. |
| 16 | + |
| 17 | +To do so, you need to first login to FloxHub using the Flox CLI using [`flox auth login`][flox_auth], if you haven't done so already. |
| 18 | +You then create a new Kubernetes secret: |
| 19 | + |
| 20 | +```bash |
| 21 | +flox auth token \ |
| 22 | + | kubectl create secret generic floxhub-token \ |
| 23 | + --from-file=floxhub-token=/dev/stdin |
| 24 | +``` |
| 25 | + |
| 26 | +!!! note "Token expiry" |
| 27 | + Tokens generated with `flox auth token` are associated with your user account and will expire 1 month from when they were issued. For a more robust alternative see [Machine Access Tokens for Organizations](../concepts/organizations.md#machine-access-tokens). |
| 28 | + |
| 29 | +!!! note "Flox CLI version" |
| 30 | + The user creating the token via `flox auth token` will need at least version 1.7.6 of the Flox CLI. |
| 31 | + |
| 32 | +Finally, you add a secret volume to your pod specification and mount it to `/var/run/secrets/flox.dev` inside your container. |
| 33 | + |
| 34 | +A sample specification is shown below: |
| 35 | + |
| 36 | +```yaml |
| 37 | +apiVersion: v1 |
| 38 | +kind: Pod |
| 39 | +metadata: |
| 40 | + name: flox-containerd-demo |
| 41 | + annotations: |
| 42 | + flox.dev/environment: "flox/echoip" |
| 43 | +spec: |
| 44 | + runtimeClassName: flox |
| 45 | + |
| 46 | + # Required for auth: a secret volume referencing the secret created with |
| 47 | + # `$ kubectl create secret` |
| 48 | + volumes: |
| 49 | + - name: secret-volume |
| 50 | + secret: |
| 51 | + secretName: floxhub-token |
| 52 | + |
| 53 | + containers: |
| 54 | + - name: empty |
| 55 | + image: flox/empty:1.0.0 |
| 56 | + command: ["echoip"] |
| 57 | + |
| 58 | + # Required for auth: mount the secret into a known place where Imageless Kubernetes can read it. |
| 59 | + volumeMounts: |
| 60 | + - name: secret-volume |
| 61 | + mountPath: "/var/run/secrets/flox.dev" |
| 62 | + readOnly: true |
| 63 | +``` |
| 64 | +
|
| 65 | +## Telemetry |
| 66 | +
|
| 67 | +Since Imageless Kubernetes uses the Flox CLI to perform certain operations such as activating your environment, Imageless Kubernetes will report the same telemetry by default that the Flox CLI reports. |
| 68 | +This includes information such as: |
| 69 | +
|
| 70 | +- Which subcommands were run |
| 71 | +- Which shell was used for the activation (Bash, Zsh, etc) |
| 72 | +- Whether the environment was remote (e.g. stored on FloxHub) or not |
| 73 | +- etc |
| 74 | +
|
| 75 | +We also use Sentry for error reporting. |
| 76 | +This information helps us focus feature development and maintenance on the areas that deliver the most value for our users. |
| 77 | +
|
| 78 | +However, we understand that some users either don't want any information collected or work in an environment that does not allow this kind of information to be collected. |
| 79 | +For this reason we offer the ability to disable telemetry. |
| 80 | +
|
| 81 | +### Disabling telemetry |
| 82 | +
|
| 83 | +When using the Flox CLI directly you can set `FLOX_DISABLE_METRICS=1` in your environment. |
| 84 | +With Imageless Kubernetes, you can set an annotation on the pod specification to accomplish the same goal. |
| 85 | + |
| 86 | +```yaml |
| 87 | +apiVersion: v1 |
| 88 | +kind: Pod |
| 89 | +metadata: |
| 90 | + name: flox-containerd-demo |
| 91 | + annotations: |
| 92 | + flox.dev/environment: "flox/echoip" |
| 93 | + # Disable telemetry |
| 94 | + flox.dev/disable-metrics: "true" |
| 95 | +spec: |
| 96 | + runtimeClassName: flox |
| 97 | + containers: |
| 98 | + - name: empty |
| 99 | + image: flox/empty:1.0.0 |
| 100 | + command: ["echoip"] |
| 101 | +``` |
| 102 | + |
| 103 | +## Activation mode |
| 104 | + |
| 105 | +By default, Imageless Kubernetes pods start in `run` mode. `run` mode is intended only to run packages installed in the Flox environment, but not provide any of the installed development dependencies. |
| 106 | + |
| 107 | +The `flox.dev/activate-mode` annotation can be used to configure the mode, which may be useful for applications such as running CI jobs in Flox-enabled pods. |
| 108 | + |
| 109 | +See the [`options.activate.mode`](../man/manifest.toml.md#options) option in the manifest for more details on modes. |
| 110 | + |
| 111 | +```yaml |
| 112 | +apiVersion: v1 |
| 113 | +kind: Pod |
| 114 | +metadata: |
| 115 | + name: quotes-app |
| 116 | + annotations: |
| 117 | + flox.dev/environment: "flox/quotes-app" |
| 118 | + # Activate in dev mode |
| 119 | + flox.dev/activate-mode: "dev" |
| 120 | +``` |
| 121 | + |
| 122 | +## Generations |
| 123 | + |
| 124 | +A specific [generation][generations] of an environment on FloxHub can be specified as part of the `flox.dev/environment` annotation. |
| 125 | +This can be useful to pin a specific version of an environment to allow for intentional or staged upgrades. |
| 126 | + |
| 127 | +```yaml |
| 128 | +apiVersion: v1 |
| 129 | +kind: Pod |
| 130 | +metadata: |
| 131 | + name: quotes-app |
| 132 | + annotations: |
| 133 | + # Pin to generation 2 of the environment |
| 134 | + flox.dev/environment: "flox/quotes-app:2" |
| 135 | +``` |
| 136 | + |
| 137 | +## Mutability |
| 138 | + |
| 139 | +By default, Imageless Kubernetes pods are immutable, such that `flox install` commands are not possible and `/nix` is mounted read-only. |
| 140 | + |
| 141 | +To enable mutability (e.g. for debugging), the `flox.dev/nix-mutable` annotation can be used. |
| 142 | + |
| 143 | +```yaml |
| 144 | +apiVersion: v1 |
| 145 | +kind: Pod |
| 146 | +metadata: |
| 147 | + name: quotes-app |
| 148 | + annotations: |
| 149 | + flox.dev/environment: "flox/quotes-app" |
| 150 | + # Enable /nix mutability |
| 151 | + flox.dev/nix-mutable: "true" |
| 152 | +``` |
| 153 | + |
| 154 | +## Mixed Flox/non-Flox pods |
| 155 | + |
| 156 | +Imageless Kubernetes allows mixing Flox and non-Flox-based containers in the same pod, supporting the use of conventional init or sidecar containers combined with Flox-based workloads. |
| 157 | +This is accomplished through the use of two annotations: `flox.dev/skip-containers` and `flox.dev/skip-containers-exec`. |
| 158 | + |
| 159 | +`flox.dev/skip-containers` accepts a comma-separated list of containers that will _not_ be modified by the Flox runtime, and will be run as if they were started with the default runtime (e.g. `runc`). This option is best used for sidecars like `vault-agent` or `istio` that should run completely unmodified. |
| 160 | + |
| 161 | +```yaml |
| 162 | +apiVersion: v1 |
| 163 | +kind: Pod |
| 164 | +metadata: |
| 165 | + name: quotes-app |
| 166 | + annotations: |
| 167 | + vault.hashicorp.com/agent-inject: "true" |
| 168 | + vault.hashicorp.com/role: "myapp-role" |
| 169 | + flox.dev/environment: "flox/quotes-app" |
| 170 | + # Keep these containers unmodified |
| 171 | + flox.dev/skip-containers: "vault-agent,vault-agent-init" |
| 172 | + spec: |
| 173 | + containers: |
| 174 | +... |
| 175 | + - name: vault-agent |
| 176 | + image: hashicorp/vault:latest |
| 177 | + command: ["/bin/sh", "-ec"] |
| 178 | + args: |
| 179 | + - | |
| 180 | + vault agent -config=/vault/configs/agent.hcl |
| 181 | + env: |
| 182 | + - name: VAULT_ADDR |
| 183 | + value: "http://vault.vault.svc.cluster.local:8200" |
| 184 | + volumeMounts: |
| 185 | + - name: vault-secrets |
| 186 | + mountPath: /vault/secrets |
| 187 | +
|
| 188 | + - name: quotes-app |
| 189 | + image: flox/empty:1.0.0 |
| 190 | + command: ["quotes-app-go"] |
| 191 | + volumeMounts: |
| 192 | + - name: vault-secrets |
| 193 | + mountPath: /vault/secrets |
| 194 | + readOnly: true |
| 195 | +... |
| 196 | +``` |
| 197 | + |
| 198 | +`flox.dev/skip-containers-exec` also accepts a comma separated list of containers, but containers specified in this annotation _will_ contain the Flox environment specified in `flox.dev/environment`. |
| 199 | + |
| 200 | +The difference from `skip-containers` is that while `skip-containers-exec` containers will have their main process run from the Flox environment, commands run via `kubectl exec` or equivalent will be run outside of it. This option is best used when you want the container's main workload to run in the Flox environment, but need exec commands (for debugging, health checks, or auxiliary tasks) to run in the base container environment without Flox. |
| 201 | + |
| 202 | +[intro]: ./intro.md |
| 203 | +[floxhub]: ../concepts/floxhub.md |
| 204 | +[flox_auth]: ../man/flox-auth.md |
| 205 | +[generations]: ../concepts/generations.md |
0 commit comments