.env ↔ K8s / Compose
Convert .env variables into a Kubernetes Secret or ConfigMap, a Docker Compose environment block, JSON or GitHub Actions env, and decode a Secret, ConfigMap or Compose service back into a .env file.
Runs entirely in your browser — nothing you paste is uploaded.
Nothing you paste leaves this browser tab; the conversion runs in your memory.
apiVersion: v1 kind: Secret metadata: name: app-secrets type: Opaque data: NEXT_PUBLIC_SUPABASE_URL: aHR0cHM6Ly94eXpjb21wYW55LnN1cGFiYXNlLmNv NEXT_PUBLIC_SUPABASE_ANON_KEY: ZXlKaGJHY2lPaUpJVXpJMU5pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SnliMnhsSWpvaVlXNXZiaUo5LmRlbW8= SUPABASE_SERVICE_ROLE_KEY: c2VydmljZS1yb2xlLWtleS1mcm9tLXRoZS1kYXNoYm9hcmQ= DATABASE_URL: cG9zdGdyZXM6Ly9wb3N0Z3Jlczpwd0BkYi5pbnRlcm5hbDo1NDMyL2FwcA== NODE_ENV: cHJvZHVjdGlvbg==
Secret values are Base64-encoded as UTF-8, which is what Kubernetes expects in data.
- NEXT_PUBLIC_SUPABASE_URLhttps://xyzcompany.supabase.co
- NEXT_PUBLIC_SUPABASE_ANON_KEYeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiJ9.demo
- SUPABASE_SERVICE_ROLE_KEYservice-role-key-from-the-dashboard
- DATABASE_URLpostgres://postgres:pw@db.internal:5432/app
Kubernetes Secret and Compose cheat sheet
quick reference- KEY=VALUE
- The dotenv format: one pair per line, an optional export prefix, # starts a comment, and quotes keep spaces or an inline # inside the value.
- kubectl create secret generic app --from-env-file=.env
- Creates a Secret whose keys are the variables of the file — the command-line version of what this tool writes.
- data vs stringData
- data holds Base64 of the UTF-8 bytes and is what the API returns; stringData takes plain text and Kubernetes encodes it when the object is written.
- printf %s "$VALUE" | base64
- Encodes one value by hand. Use printf or echo -n, because a trailing newline silently becomes part of the decoded secret.
- environment:
- In Compose a mapping passes YAML strings straight through, while a - KEY=VALUE list goes through Compose interpolation and handles ${VAR} references.
- envFrom.secretRef
- Mounts every key of a Secret as an environment variable in a container; envFrom.configMapRef does the same for a ConfigMap.
Frequently asked questions
answered below the toolShould a Secret use data or stringData?
stringData takes plain text and is easier to read; data holds Base64 and is what the API returns. Both describe the same Secret.
Why is the decoded value one character longer?
echo adds a newline before Base64 encoding. Use printf %s or echo -n so the newline never becomes part of the secret.
Can I turn a Secret back into .env?
Yes. Paste the Secret, ConfigMap or Compose service and choose the reverse direction; the values come back as KEY=VALUE lines.
Related Docker syntax guides
All Docker guidesDocker: exec user process caused: exec format error
An arm64 image on an amd64 host is a runtime failure, not a pull failure. Diagnose the platform, build for the target, publish multi-arch, and spot the script variant.
DockerDocker Compose: bind: address already in use and Port Conflicts
A published port is a host socket, and two projects cannot own it. How to find the real owner, why an override file merged instead of replacing, and how to publish dynamically.
DockerAlpine musl vs Debian slim: DNS Timeouts and Native Builds
musl rejects manylinux wheels and linux-x64-gnu prebuilds, so the installer starts compiling without a toolchain. And ndots:5 in Kubernetes adds five seconds per lookup.
DockerDocker Compose Connection Refused: localhost vs Service DNS
localhost inside a container is that container. Compose resolves service names on a shared network, depends_on does not wait for readiness, and binding loopback breaks the rest.