.env to Kubernetes ConfigMap & Secret Generator

Convert .env and KEY=VALUE environment variable files into production-ready Kubernetes ConfigMap or Base64-encoded Secret YAML manifests.

How to Convert .env Files to Kubernetes Manifests

1

Paste or Upload .env

Paste your .env file content containing key-value definitions (e.g. DB_HOST=127.0.0.1), drop a file, or click Sample.

2

Select Resource & Options

Choose between ConfigMap (for public config) or Secret (with automatic Base64 encoding), and specify your resource name.

3

Save & Deploy YAML

Manifest updates in real time. Click Copy or Download to save your Kubernetes YAML manifest, or copy the Pod injection snippet.

Tool Options

Dual Resource Support

Seamlessly generate either non-sensitive ConfigMap or encrypted Secret manifests from identical environment definitions.

Automatic Base64 Encoding

Automatically encodes sensitive values into standard Base64 for data: maps, or preserves readability with stringData:.

Deployment Injection Snippets

Generates ready-to-paste envFrom container spec references so you can mount your new manifests into deployments immediately.

Your Data Privacy

Web Tool
Privacy-First Architecture
Most of our web tools process your data entirely in-browser. Where server processing is technically required, payloads are evaluated statelessly in-memory and are never stored, saved, or logged.
REST API
Stateless In-Memory Processing
When you use our API endpoints, your requests are processed strictly in-memory without persistent database storage, disk logging, or data retention.
Want to learn more about how we safeguard your information and infrastructure?
Read our full Privacy Policy for detailed security standards, data retention principles, and compliance guarantees.

What does the .env to Kubernetes ConfigMap & Secret Generator do?

The .env to Kubernetes ConfigMap & Secret Generator parses .env, .env.local, and standard KEY=VALUE environment variable definitions and converts them into production-ready Kubernetes ConfigMap (apiVersion: v1) or Secret (type: Opaque) YAML manifests. It handles automated Base64 data encoding, multiline string formatting, comment filtering, and generates ready-to-use envFrom container reference snippets.

Core Concepts

Understanding Kubernetes configuration management from .env definitions:

  • ConfigMap vs. Secret Separation: ConfigMaps store non-sensitive configuration parameters (such as hostnames, ports, and feature flags) as plain text strings. Secrets store sensitive credentials (passwords, API tokens, encryption keys) encoded in Base64 under data: or plain text under stringData:.
  • Automatic Base64 Data Transformation: When generating Kubernetes Secrets, values are automatically encoded to Base64 without requiring manual command-line pipelines.
  • Key & Name Sanitization: Validates keys and metadata resource names against Kubernetes DNS-1123 label standards and generates accompanying Pod envFrom snippets for zero-friction integration.

How to use the tool?

  1. Input Environment Variables: Paste your .env content or click Sample to inspect a pre-populated configuration.
  2. Select Resource Type: Choose between ConfigMap and Secret, provide a custom resource name and namespace, and pick your secret encoding method (data: or stringData:).
  3. Live Preview & Export: Converts automatically in real time. Click Copy or Download to save the .yaml file directly.

Related Developer Utilities

If you work with Kubernetes, Docker containers, and environment variables, explore these complementary tools:

REST API Integration

blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/yaml/env-to-kubernetes) to programmatically convert .env files into Kubernetes ConfigMap and Secret YAML manifests.

API Request Parameters

Name Type Description Example
rawText String / Object Raw .env content or key-value object (aliases: rawEnv, env, data, payload, input, text). "DB_HOST=10.0.0.1\nDB_PORT=5432"
resourceType String Target manifest type: 'configmap' (default) or 'secret'. "configmap"
name String Metadata name for the resource (default: 'app-config'). "my-app-config"
namespace String Optional Kubernetes namespace string. "production"
secretFormat String Secret data format: 'base64' (data:, default) or 'stringData'. "base64"

API Request Payload Examples

cURL

curl -X POST https://blueutils.com/api/yaml/env-to-kubernetes \
  -H "Content-Type: application/json" \
  -d '{
    "rawText": "DB_HOST=postgres.internal\nDB_PORT=5432\nAPI_KEY=secret_key_123",
    "options": {
      "resourceType": "secret",
      "name": "app-credentials",
      "namespace": "backend",
      "secretFormat": "base64"
    }
  }'

Python

import requests

url = "https://blueutils.com/api/yaml/env-to-kubernetes"
payload = {
    "rawText": "DB_HOST=postgres.internal\nDB_PORT=5432\nAPI_KEY=secret_key_123",
    "options": {
        "resourceType": "secret",
        "name": "app-credentials",
        "namespace": "backend",
        "secretFormat": "base64"
    }
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String jsonPayload = """
            {
                "rawText": "DB_HOST=postgres.internal\\nDB_PORT=5432",
                "options": {
                    "resourceType": "configmap",
                    "name": "app-config"
                }
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://blueutils.com/api/yaml/env-to-kubernetes"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

API Response Parameters

Name Type Description Example
isValid Boolean Indicates whether parsing and generation succeeded. true
resourceType String Generated resource type (configmap or secret). "secret"
name String Final sanitized Kubernetes resource name. "app-credentials"
totalKeys Number Count of environment keys processed. 3
yaml String Formatted Kubernetes YAML manifest string. "apiVersion: v1\nkind: Secret\n..."
podSnippet String Container spec snippet for injecting the resource. "envFrom:\n - secretRef:\n ..."

API Response Payload Examples

Success Response (HTTP 200 OK)

{
  "isValid": true,
  "resourceType": "secret",
  "name": "app-credentials",
  "namespace": "backend",
  "totalKeys": 3,
  "yaml": "apiVersion: v1\nkind: Secret\nmetadata:\n  name: app-credentials\n  namespace: backend\ntype: Opaque\ndata:\n  DB_HOST: cG9zdGdyZXMuaW50ZXJuYWw=\n  DB_PORT: NTQzMg==\n  API_KEY: c2VjcmV0X2tleV8xMjM=",
  "podSnippet": "# To inject all keys into a Container / Deployment spec:\nenvFrom:\n  - secretRef:\n      name: app-credentials"
}

Validation Failure Response (HTTP 400 Bad Request)

{
  "isValid": false,
  "error": "No valid KEY=VALUE pairs found in provided input."
}

Rate Limit Exceeded Response (HTTP 429 Too Many Requests)

{
  "error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}

Why use an API to convert .env to Kubernetes manifests?

Integrating the .env to Kubernetes Manifest API into CI/CD pipelines, GitOps sync scripts, or AI agent tool calling provides key benefits:

  • Rapid GitOps Provisioning: Automatically generates validated Kubernetes manifests from developer .env files without manual YAML editing or shell scripts.
  • Optimized Token Efficiency for AI Agents: LLMs frequently introduce Base64 padding errors or incorrect YAML indentation for multiline variables. Calling the API generates syntactically valid manifests deterministically.
  • Deterministic Accuracy Without Hallucinations: Ensures 100% compliant Kubernetes API specifications with strict key formatting.

Native Usage

How to generate Kubernetes ConfigMaps and Secrets natively via CLI and scripts:

Linux / Unix (Bash with kubectl)

# Generate ConfigMap YAML locally without applying to cluster
kubectl create configmap app-config --from-env-file=.env --dry-run=client -o yaml > configmap.yaml

# Generate Secret YAML with base64 encoding locally
kubectl create secret generic app-secret --from-env-file=.env --dry-run=client -o yaml > secret.yaml

Windows (PowerShell with kubectl)

# Generate ConfigMap in PowerShell
kubectl create configmap app-config --from-env-file=.env --dry-run=client -o yaml | Out-File -Encoding utf8 configmap.yaml

# Generate Secret in PowerShell
kubectl create secret generic app-secret --from-env-file=.env --dry-run=client -o yaml | Out-File -Encoding utf8 secret.yaml

Windows (Command Prompt)

:: Generate ConfigMap in Command Prompt
kubectl create configmap app-config --from-env-file=.env --dry-run=client -o yaml > configmap.yaml

:: Generate Secret in Command Prompt
kubectl create secret generic app-secret --from-env-file=.env --dry-run=client -o yaml > secret.yaml

Python

Using Python:

import base64

def generate_k8s_secret(env_dict, name="app-secret"):
    data_lines = [f"  {k}: {base64.b64encode(v.encode()).decode()}" for k, v in env_dict.items()]
    return f"""apiVersion: v1
kind: Secret
metadata:
  name: {name}
type: Opaque
data:
""" + "\n".join(data_lines)

print(generate_k8s_secret({"DB_PORT": "5432", "DB_NAME": "mydb"}))

Java

Using Java:

import java.util.Base64;
import java.util.Map;

public class K8sSecretGenerator {
    public static void main(String[] args) {
        Map<String, String> env = Map.of("DB_HOST", "localhost", "PORT", "8080");
        StringBuilder sb = new StringBuilder("apiVersion: v1\nkind: Secret\nmetadata:\n  name: app-secret\ntype: Opaque\ndata:\n");
        env.forEach((k, v) -> {
            String b64 = Base64.getEncoder().encodeToString(v.getBytes());
            sb.append("  ").append(k).append(": ").append(b64).append("\n");
        });
        System.out.println(sb);
    }
}

Frequently Asked Questions (FAQ)

How do I convert a .env file into a Kubernetes ConfigMap or Secret?

Paste your .env or KEY=VALUE content into the input editor, select whether you want a ConfigMap or Secret manifest, specify your resource name, and click Generate Kubernetes Manifest. The tool generates a standard Kubernetes v1 YAML manifest instantly.

What is the difference between data: and stringData: in Secret manifests?

The data: field requires all secret values to be Base64-encoded strings, which this tool generates automatically. The stringData: field allows unencoded plain-text values, which Kubernetes automatically Base64 encodes upon cluster creation.

How are multiline environment variables and quotes handled in YAML?

Multiline environment values enclosed in quotes are parsed into clean YAML literal block scalar syntax (|), preserving internal line breaks while stripping outer quotes.

How do I inject the generated ConfigMap or Secret into a Kubernetes Pod or Deployment?

Use the envFrom field under spec.containers[*] in your Pod or Deployment manifest with configMapRef: name: <resource-name> or secretRef: name: <resource-name> to inject all key-value pairs as environment variables.

Are my environment variables or API keys uploaded to any remote server?

No. All parsing, validation, and Base64 encoding execute in-memory with zero server logging, ensuring that database passwords, API tokens, and deployment secrets remain completely private.

Rate Limits

UI Limits
100 uses per 15 minutes
Max payload size: 5 MB
API Limits
5 requests per 60 minutes
Max payload size: 256 KB
Need higher API rate limits, increased payload sizes, or custom developer solutions?
Contact our engineering team at support@blueutils.com for custom rate limit increases, higher quota allocations, or tailored enterprise integrations.