How to Write Kubernetes YAML for a Web App (Deployment to Ingress)
A practical guide to Deployment, Service, Ingress, ConfigMap and autoscaler manifests: labels, probes, resources and a hardened security context.
&c=%230f766e&k=developer)
How to Write Kubernetes YAML for a Web App
Deploying a web app to Kubernetes usually takes four or five objects that must agree with each other: a Deployment that runs the pods, a Service that gives them a stable address, an Ingress that routes outside traffic, a ConfigMap for settings and sometimes an autoscaler. A mismatched label or port name silently breaks the chain. The free Kubernetes Manifest Generator produces a consistent set from a short form; this guide explains each piece.
Names and labels
Object names must be lower-case letters, digits and dashes, starting and ending with a letter or digit. The generator checks this before writing anything. Every object carries the recommended label app.kubernetes.io/name, and the Deployment's selector, the pod template's labels and the Service's selector all use the same value. If they differ, the Service finds no pods and traffic goes nowhere.
The Deployment
The Deployment keeps the requested number of replicas running and replaces them gradually when you change the image. The important parts:
- A named port. Naming the container port http lets the Service, probes and Ingress refer to it by name rather than number.
- Readiness probe. Kubernetes sends traffic to a pod only after this check passes, so users never hit a pod that is still starting.
- Liveness probe. If this fails repeatedly, the container is restarted. It starts later than readiness so slow starts are not mistaken for hangs.
- Requests and limits. Requests reserve CPU and memory for scheduling; limits cap use. A memory limit stops one leaking pod from starving a node. Many teams set a CPU request but no CPU limit to avoid throttling.
The security context
The hardened option sets runAsNonRoot, a RuntimeDefault seccomp profile, no privilege escalation, a read-only root filesystem and drops all Linux capabilities, matching the restricted Pod Security Standard that many clusters enforce. Apps that write files need an emptyDir volume mounted where they write, such as /tmp.
Service and Ingress
The Service gives the pods one stable name inside the cluster. ClusterIP is internal only; NodePort and LoadBalancer expose it directly. Most web apps use ClusterIP behind an Ingress, which routes a host name and path to the Service. Set the ingress class to match your controller, and the cert-manager annotation and TLS block make cert-manager obtain and renew a certificate automatically.
ConfigMap
Environment settings go into a ConfigMap loaded with envFrom, so you can change configuration without rebuilding the image. Restart the deployment after changing it. Passwords and keys belong in Secrets instead.
Autoscaling
A HorizontalPodAutoscaler adds replicas when average CPU use passes your target, such as 70 percent of the request, and removes them when load drops. It needs the CPU request to be set and the metrics-server installed.
Applying and rolling out
Save the generated file and run kubectl apply -f with it, then kubectl rollout status to watch the rollout. To release a new version, change the image tag and apply again. If the new pods fail readiness, the old ones keep serving; kubectl rollout undo returns to the previous version.
A worked example
An online shop called shop runs the image registry.example.com/shop:1.4.2 on port 8080 with three replicas. With the host shop.example.com, TLS on and autoscaling up to ten replicas at 70 percent CPU, the generator writes five documents in one file: a ConfigMap with LOG_LEVEL, the Deployment with probes on /health, a ClusterIP Service on port 80, an Ingress with a cert-manager certificate, and the HorizontalPodAutoscaler.
What this does not cover
Databases and other stateful services need StatefulSets, persistent volumes, backups and careful upgrades. Use managed databases or dedicated operators for them. The generator targets stateless web services, the most common case, and runs entirely in your browser.



