Skip to content
🛠️ToolsShed

Kubernetes YAML Generator

Generate Kubernetes manifests for Deployments, Services, ConfigMaps, and Namespaces.

Deployment Configuration

deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  namespace: default
  labels:
    app: my-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app
          image: nginx:latest
          ports:
            - containerPort: 80
        env:
          - name: ENV
            value: "production"
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 500m
              memory: 512Mi

Apply with: kubectl apply -f deployment.yaml

About this tool

Kubernetes YAML Generator is a developer tool that converts manual Kubernetes manifest definitions into properly formatted YAML configuration files. Whether you're deploying containerized applications, managing microservices, or configuring infrastructure-as-code, this tool eliminates the tedious task of hand-writing Kubernetes YAML by generating clean, syntactically valid manifests for Deployments, Services, ConfigMaps, and Namespaces. It ensures your configurations follow Kubernetes API specifications and best practices.

To use the tool, fill in the configuration form with your resource details—specify deployment metadata, container images, service ports, environment variables, and other parameters. The generator automatically produces properly indented, well-structured YAML that's ready to apply directly to your Kubernetes cluster using kubectl or your CI/CD pipeline. You can customize resource names, labels, selectors, and all other fields before generation.

This tool is particularly valuable for DevOps engineers, application developers, and infrastructure teams working with Kubernetes. It handles common edge cases like port mappings, volumeMounts, securityContext, and resource limits, saving time and reducing YAML syntax errors that could prevent successful deployments.

Frequently Asked Questions

Code Implementation

import subprocess
import yaml
import tempfile
import os

def generate_deployment(name, image, replicas=2, port=80, namespace="default"):
    """Generate a Kubernetes Deployment manifest dict."""
    return {
        "apiVersion": "apps/v1",
        "kind": "Deployment",
        "metadata": {"name": name, "namespace": namespace},
        "spec": {
            "replicas": replicas,
            "selector": {"matchLabels": {"app": name}},
            "template": {
                "metadata": {"labels": {"app": name}},
                "spec": {
                    "containers": [{
                        "name": name,
                        "image": image,
                        "ports": [{"containerPort": port}]
                    }]
                }
            }
        }
    }

manifest = generate_deployment("my-app", "nginx:latest", replicas=3)
yaml_str = yaml.dump(manifest, default_flow_style=False)
print(yaml_str)

# Apply using kubectl
with tempfile.NamedTemporaryFile(mode='w', suffix='.yaml', delete=False) as f:
    f.write(yaml_str)
    tmp = f.name

result = subprocess.run(["kubectl", "apply", "-f", tmp], capture_output=True, text=True)
print(result.stdout)
os.unlink(tmp)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.