Init containers (Kubernetes)
Use an init container to bootstrap secrets into your pod before the main container starts — without installing the Kubernetes operator.
Prefer the operator
For production Kubernetes setups the operator is easier to manage — it handles re-sync automatically and doesn't require changing every Deployment. Use init containers when you can't install cluster-wide CRDs.
How it works
- The init container runs
snapenv pulland writes the output to a sharedemptyDirvolume - The main container reads the file at startup
- Secrets are in memory only — never in the image or persistent storage
Pod manifest
yaml
initContainers:
- name: snapenv-init
image: ghcr.io/snapenv-io/cli:latest
command: ["snapenv", "pull", "--env", "prod", "--output", "/secrets/.env"]
env:
- name: SNAPENV_TOKEN
valueFrom:
secretKeyRef:
name: snapenv-token
key: token
- name: SNAPENV_PROJECT
value: "<your-project-uuid>"
volumeMounts:
- name: secrets
mountPath: /secrets
containers:
- name: app
image: your-app:latest
volumeMounts:
- name: secrets
mountPath: /secrets
readOnly: true
volumes:
- name: secrets
emptyDir:
medium: Memory # tmpfs — never written to diskCreate the token Secret
bash
kubectl create secret generic snapenv-token \
--from-literal=token=snp_live_xxxxxxxxxxxxSource the file in your app
bash
# In your entrypoint or CMD
source /secrets/.env && exec node server.jsOr load it programmatically (Node.js example):
js
import { config } from 'dotenv';
config({ path: '/secrets/.env' });