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 understringData:. - 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
envFromsnippets for zero-friction integration.
How to use the tool?
- Input Environment Variables: Paste your
.envcontent or click Sample to inspect a pre-populated configuration. - Select Resource Type: Choose between ConfigMap and Secret, provide a custom resource name and namespace, and pick your secret encoding method (
data:orstringData:). - Live Preview & Export: Converts automatically in real time. Click Copy or Download to save the
.yamlfile directly.
Related Developer Utilities
If you work with Kubernetes, Docker containers, and environment variables, explore these complementary tools:
- Kubernetes Manifest Validator & Kubeval Linter: Validate syntax and API schemas of Kubernetes manifests.
- YAML to Env / Dotenv Converter: Convert hierarchical YAML configurations into flat
.envkey-value pairs. - Docker Compose to .env Extractor: Extract environment variables and placeholders from Compose files.
- .gitignore to .dockerignore Converter: Generate optimized
.dockerignorefilters for container builds.
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
.envfiles 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.yamlWindows (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.yamlWindows (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.yamlPython
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);
}
}