Chafik Belhaoues
Deployment YAML looks simple until you start deploying in production. Incorrect probes, forgotten resource limits, a poor update strategy - and instead of a stable service, you get CrashLoopBackOff. In this guide, we'll break down how to write Kubernetes deployment YAML so that applications run reliably and update without downtime.
A Kubernetes deployment YAML file is a declarative configuration file that describes the desired state of an application in a Kubernetes cluster. It is the central building block for container management and answers three key questions:
Kubernetes constantly compares the current state of the cluster with the description in the deployment file. If a pod goes down, the controller automatically creates a new one. If three replicas are specified and two are running, the third will be launched without an engineer's involvement. This declarative approach is the basis for deployment strategies: instead of step-by-step instructions, you describe the desired result, and Kubernetes determines how to achieve it.
Each Kubernetes deployment file consists of several mandatory blocks. Understanding their structure is the basis for a competent Kubernetes deployment strategy, helping you avoid common deployment errors.
The metadata section contains the deployment name, namespace, and a set of labels with annotations. Labels are key-value pairs that are used to organize, filter, and select resources across the cluster. For example, the labels app: web-api and env: production allow you to find all production pods for a specific service quickly.
The spec block defines the desired state of the deployment:
Kubernetes continuously monitors to ensure that the number of running pods matches the specified value replicas.
The template section describes the pod template - the actual workload that Kubernetes will schedule and run:
According to the Kubernetes deployment documentation, health checks are critical for production reliability:
Without probes, Kubernetes cannot automatically detect and fix failures, which makes the application fragile.
Choosing the right update strategy depends on application requirements and acceptable risk levels. Let's look at the main deployment strategies.
The default strategy: Kubernetes gradually replaces old pods with new ones. Key parameters:
Rolling update is ideal for most production workloads that require zero downtime. The update is smooth: new pods pass the readiness probe before the old ones are terminated.
The Recreate type of Kubernetes update strategy works differently: all existing pods are stopped before new ones are created. This results in a brief downtime, but is suitable for applications that:
Blue-green and canary are advanced Kubernetes deployment types that are not built into the standard Deployment resource directly, but are implemented through additional tools:
These strategies are implemented through Argo Rollouts, Flagger, or service mesh (Istio, Linkerd). They are justified for critical services where the cost of failure is high. To visualize such architectures, it is convenient to use Brainboard, which displays infrastructure dependencies and helps plan complex deployments.
A reliable deployment file for production must comply with several recommendations:
For teams managing multiple deployment files, Brainboard provides a centralized view of the entire infrastructure and helps enforce configuration standards.
When working with Kubernetes deployment YAML, teams regularly encounter typical problems:
The Brainboard tool reduces the risk of such errors by allowing you to design infrastructure visually and automatically generate correct configurations.
1. What is the difference between a Deployment and a Pod in Kubernetes?
A Pod is the smallest unit of execution, consisting of one or more containers. Deployment is a higher-level controller that manages pods: it maintains a specified number of replicas, performs updates, and rolls back.
2. How do I roll back a failed Kubernetes deployment?
With the command kubectl rollout undo deployment/<name>. Kubernetes will revert to the previous ReplicaSet version. To roll back to a specific revision, use the flag --to-revision=N.
3. Can I use JSON instead of YAML for deployment files?
Yes, Kubernetes accepts both JSON and YAML. However, YAML is preferred: it is more compact, supports comments, and is easier to read.
4. How do I update a running deployment without downtime?
Use the Rolling Update strategy (default). Update the image with the command kubectl set image deployment/<name> <container>=<image>:<tag> - Kubernetes will smoothly replace pods without downtime.
5. What is the default deployment strategy in Kubernetes?
The default is RollingUpdate with the parameters maxSurge: 25% and maxUnavailable: 25%. This ensures a gradual update without complete application downtime.