Web

Kubernetes YAML: Writing Production-Grade Manifests

A complete guide to writing Kubernetes YAML manifests — Pods, Deployments, Services, ConfigMaps, and validation best practices.

WebUtil Team

What Is Kubernetes YAML?

Kubernetes uses YAML files to define the desired state of your cluster resources. Every object in Kubernetes — Pods, Deployments, Services, ConfigMaps, Secrets, Ingresses — is created from a YAML manifest that describes what you want and how it should run. Understanding Kubernetes YAML is essential for anyone working with container orchestration.

A Kubernetes YAML manifest follows a consistent structure across all resource types. Every manifest has four required top-level fields: apiVersion (which API version to use), kind (the resource type), metadata (name, namespace, labels, annotations), and spec (the desired state configuration). This consistency means once you understand one resource type, learning others is a matter of learning their specific spec fields.

The challenge most developers face is getting the YAML syntax correct. Kubernetes is strict about indentation — an extra space can cause your entire manifest to be rejected. Common mistakes include using tabs instead of spaces, incorrect nesting of fields, and missing required spec properties. Our Kubernetes YAML Validator helps catch these errors before you apply manifests to your cluster, saving time and preventing accidental misconfiguration.

Writing Pod and Deployment Manifests

Pods are the smallest deployable units in Kubernetes, representing one or more containers that share storage and network resources. A simple Pod manifest includes containers with their image, ports, environment variables, and resource requests. Pods are typically not created directly in production — you use higher-level resources like Deployments to manage them.

Deployments are the standard way to run stateless applications in Kubernetes. A Deployment manages a ReplicaSet, which in turn manages the Pods. Key spec fields include replicas (how many Pod instances to run), selector (which Pods to manage via labels), and template (the Pod template defining containers, volumes, and other settings). Deployments support rolling updates with configurable strategies like maxSurge and maxUnavailable for zero-downtime deployments.

Production-grade Deployments should include resource requests and limits for CPU and memory, liveness and readiness probes for health checking, pod disruption budgets for maintenance windows, and horizontal pod autoscaling for dynamic scaling. These configuration details transform a basic deployment into a resilient production service. Our Kubernetes YAML Validator checks for these best practices and flags missing configurations.

Services, ConfigMaps, and Secrets

Services provide stable networking for Pods, which are ephemeral and get new IP addresses when they restart. The most common Service types are ClusterIP (internal cluster access, default), NodePort (external access via node port), and LoadBalancer (cloud provider load balancer). Services use label selectors to determine which Pods receive traffic, decoupling the network endpoint from the actual Pod instances.

ConfigMaps and Secrets store configuration data separately from container images. ConfigMaps hold non-sensitive configuration in key-value pairs or structured data like YAML files. They can be exposed to Pods as environment variables, command-line arguments, or mounted as volumes. The advantage is that you can change configuration without rebuilding container images.

Secrets work like ConfigMaps but are intended for sensitive data like passwords, API keys, and certificates. Values in Secrets are base64-encoded (not encrypted — encryption at rest requires additional configuration like KMS). For production environments, consider external secret management tools like HashiCorp Vault, AWS Secrets Manager, or Sealed Secrets for GitOps workflows.

Sponsored
Advertisement

Common Kubernetes YAML Errors

The most frequent errors in Kubernetes YAML manifests are indentation mistakes. YAML uses spaces for indentation, and Kubernetes is strict about the exact nesting structure required by the API spec. A common example is placing spec fields at the wrong level, like putting containers directly under spec instead of under spec.template.spec. These errors produce cryptic messages from kubectl apply that can be hard to debug.

API version mismatches are another common issue. Kubernetes deprecates API versions across releases — for example, apps/v1beta1 was removed in Kubernetes 1.16. Using a deprecated API version causes apply failures. Always check the Kubernetes API versioning documentation for your cluster version. The kubectl explain command shows the correct API version and field structure for any resource.

Missing required fields is the third category of common errors. Every resource has required fields that must be present. A Deployment requires spec.selector.matchLabels and spec.template.metadata.labels to overlap. An Ingress requires spec.rules. Our Kubernetes YAML Validator checks for these structural requirements and provides clear error messages to help you fix issues before deployment.

YAML Validation Best Practices

Validating Kubernetes YAML before applying it to a cluster is a critical part of any deployment pipeline. Manual validation steps include using kubectl apply --dry-run=client to check syntax locally, kubectl explain to verify field structures, and schema validation tools to check against the OpenAPI spec that Kubernetes publishes for each version.

For CI/CD pipelines, integrate validation at multiple stages. Run syntax checks in pre-commit hooks, schema validation in pull request checks, and dry-run applies against a staging cluster before production. Tools like kubeconform, kubeval, and our Kubernetes YAML Validator can be integrated into GitHub Actions, GitLab CI, or any pipeline that runs containerized jobs.

Our free Kubernetes YAML Validator provides instant client-side validation of your manifests. It checks YAML syntax, Kubernetes schema compliance, and common configuration issues. Paste your manifest and get immediate feedback without needing a cluster connection. All validation runs in your browser — your manifests never leave your machine, making it safe for confidential configurations.

Use our free online tool to get started instantly.