Validate a Kubernetes Pod Manifest
Kubernetes manifests are complex YAML documents where a formatting error causes kubectl apply to reject the file or silently misinterpret the configuration. This example shows a Pod spec with resource limits, environment variables, liveness and readiness probes. Validating the YAML structure before applying to a cluster saves time and prevents misconfigured workloads from reaching production.
Example
apiVersion: v1
kind: Pod
metadata:
name: web-api
labels:
app: web-api
version: v2
spec:
containers:
- name: api
image: myapp:2.1.0
ports:
- containerPort: 8080
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "512Mi"
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 10FAQ
- What is the difference between requests and limits in Kubernetes?
- requests is the amount of CPU/memory the scheduler reserves for the pod. limits is the maximum it can use. A pod that exceeds its memory limit is killed; exceeding CPU limit throttles it.
- What is a liveness probe?
- A liveness probe tells Kubernetes whether the container is running correctly. If it fails, Kubernetes restarts the container. A readiness probe controls whether the pod receives traffic.
- Should I use Pod directly or a Deployment?
- Use a Deployment in production. Deployments manage replica sets, handle rolling updates, and restart pods that fail. Bare Pods are not rescheduled if the node fails.
Related Examples
Validate a docker-compose.yml File
Docker Compose files are notoriously sensitive to indentation because YAML uses ...
Format a Helm Values FileHelm values files configure Kubernetes charts and are injected into templates as...
Validate a CloudFormation TemplateAWS CloudFormation templates define cloud infrastructure as code and must be val...