elefcode

Kubernetes YAML Generator

Fill in your app and get a Deployment, Service, Ingress and autoscaler that work together.

Deployment
Environment variables

Passwords and API keys belong in a Secret, not here — reference it with envFrom.secretRef.

web.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  namespace: default
  labels:
    app.kubernetes.io/name: web
spec:
  replicas: 2
  selector:
    matchLabels:
      app.kubernetes.io/name: web
  template:
    metadata:
      labels:
        app.kubernetes.io/name: web
    spec:
      containers:
        - name: web
          image: nginx:1.27
          ports:
            - name: http
              containerPort: 80
          env:
            - name: NODE_ENV
              value: production
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 500m
              memory: 256Mi
          readinessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: 5
            periodSeconds: 10
          livenessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: 15
            periodSeconds: 20
---
apiVersion: v1
kind: Service
metadata:
  name: web
  namespace: default
  labels:
    app.kubernetes.io/name: web
spec:
  type: ClusterIP
  selector:
    app.kubernetes.io/name: web
  ports:
    - name: http
      port: 80
      targetPort: http
      protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web
  namespace: default
  labels:
    app.kubernetes.io/name: web
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - app.example.com
      secretName: web-tls
  rules:
    - host: app.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  name: http

Apply it with kubectl apply -f web.yaml.

Advertisement

Guide

About the Kubernetes YAML Generator

Running one web app on Kubernetes usually takes several objects that must agree with each other: a Deployment that runs the containers, a Service that gives them a stable address, and an Ingress that routes outside traffic to that Service. Their labels, selectors, names and ports all have to match. This generator writes them together from one form, so they always line up.

Requests, limits and probes

Requests are what the scheduler reserves for a pod; limits are the ceiling it may use. A container over its memory limit is killed, and one over its CPU limit is slowed. The readiness probe keeps traffic away from a pod until it answers, and the liveness probe restarts it if it stops answering. Point both at a lightweight health endpoint.

Moving from Docker Compose

Each Compose service roughly becomes a Deployment plus a Service; published ports become an Ingress or a LoadBalancer Service; environment becomes env or a ConfigMap; and named volumes become PersistentVolumeClaims.

How to use it

  1. 1Enter the app name, image and container port.
  2. 2Set resources, a health check path and environment variables.
  3. 3Turn the Service, Ingress and autoscaler on or off and fill in their settings.
  4. 4Copy or download the YAML and run kubectl apply -f.

Frequently asked questions

Do I need an Ingress controller?

Yes. An Ingress object does nothing on its own; the cluster needs a controller such as ingress-nginx or Traefik. The ingress class field tells Kubernetes which one should handle it.

Where does the TLS certificate come from?

With HTTPS on, the Ingress asks cert-manager (via the cluster-issuer annotation) to obtain a certificate and store it in the <name>-tls Secret. Without cert-manager, create that Secret yourself.

Why is replicas missing when autoscaling is on?

The HorizontalPodAutoscaler sets the replica count. Leaving replicas in the Deployment would reset the count every time you apply the file.

Should I put secrets in environment variables here?

No. Put passwords and keys in a Kubernetes Secret and reference it from the Deployment; ConfigMaps and plain env values are not encrypted.

Which Kubernetes versions does the YAML work with?

It uses apps/v1, networking.k8s.io/v1 and autoscaling/v2, which every supported Kubernetes release (1.23 and later) understands.

Related tools