Kubernetes is the standard for container orchestration; however, to fully leverage the platform, you need to approach Kubernetes with a set plan. This would include a proper structured approach and a consistent way to define and manage the Kubernetes workloads. This is where a Kubernetes manifest file comes in handy.
These YAML configuration files work as blueprints that tell Kubernetes what they need to create and how to do it. Manifest files help with all stages of development, from initial deployment to version control.
In this guide, we will explore the importance of a Kubernetes manifest file, their structure, and how to use it effectively.
What Is a Kubernetes Manifest File?
A Kubernetes manifest file is a configuration file that is written in YAML or JSON script, defining the desired state of resources within a Kubernetes cluster. These resources can include pods, deployments, services, config maps, Kubernetes secrets and more.
The manifest file defines what needs to be done, pretty much like a blueprint. The platform uses it to ensure that the system state matches the declared configuration.
Why Use Manifest Files in Kubernetes?
Get exclusive access to all things tech-savvy, and be the first to receive
the latest updates directly in your inbox.
Manifest files are a Kubernetes must-have because:
- They define the end state of your application or infrastructure, and let Kubernetes handle the how.
- Store YAML files in Git to track changes later on and enable GitOps workflows.
- Easily integrate into deployment pipelines.
- They clarify tasks, which results in a consistent performance across teams.
YAML Syntax & Structure for Kubernetes Manifests
Since most Kubernetes files are in YAML script, a basic Kubernetes manifest file is somewhat like this:
apiVersion: v1
kind: Pod
metadata:
name: my-pod
labels:
app: demo
spec:

containers:
– name: nginx-container
image: nginx:latest
ports:
– containerPort: 80
Key Sections Explained:
- apiVersion: Specifies the API version used for the object type.
- kind: Defines the type of Kubernetes object (e.g., Pod, Deployment, Service).
- metadata: Provides metadata like the name, labels, and namespace.
- spec: Contains the actual configuration for the resource (e.g., container image, ports, replicas).
YAML is indentation-sensitive, so proper formatting is crucial to avoid errors.
Common Kubernetes Manifest File Types
Some of the most commonly used manifest file types in Kubernetes are:
- Pod Manifest
A Pod Manifest file type is the smallest deployable unit in Kubernetes. It defines one or more containers that share the same network and storage context.
Example:
apiVersion: v1
kind: Pod
metadata:
name: simple-pod
spec:
containers:
– name: nginx
image: nginx:latest
ports:
– containerPort: 80
Use a Pod manifest for testing or very simple workloads. For production, prefer Deployments.
- Deployment Manifest
A Deployment manifest file manages multiple replicas of the Pods and handles them by rolling updates and rollbacks automatically. It is one of the most useful manifest types for running applications in Kubernetes.
Example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deployment
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
– name: web
image: nginx:latest
ports:
– containerPort: 80
Deployments ensure high availability and are ideal for scaling applications.
- Service Manifest
A Service manifest file type exposes Pods over a stable network interface. It abstracts access to one or more Pods using selectors.
Example:
apiVersion: v1
kind: Service
metadata:
name: web-service
spec:
selector:
app: web
ports:
– protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
Other types include NodePort, LoadBalancer, and ExternalName depending on exposure needs.
- ConfigMap and Secret
ConfigMap Example:
They store configuration data in key-value pairs for non-sensitive information.
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
LOG_LEVEL: debug
MAX_RETRIES: “5”
Secret Example:
Secret manifest files store sensitive data like tokens and passcodes.
apiVersion: v1
kind: Secret
metadata:
name: app-secret
type: Opaque
data:
DB_PASSWORD: cGFzc3dvcmQxMjM= # Base64 encoded value
Use ConfigMaps and Secrets to externalize configuration from your application containers.
- Ingress Manifest
An ingress manifest file manages the external access to services within the cluster, typically via the HTTP/HTTPS routes. It supports routing, TLS, and path-based rules.
Example:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
– host: myapp.example.com
http:
paths:
– path: /
pathType: Prefix
backend:
service:
name: web-service
port:
number: 80
Ingress requires an Ingress Controller (e.g., NGINX Ingress Controller) to work.
Creating a Basic Manifest File: Step-by-Step
Writing a Kubernetes manifest file is a pretty easy process once you are familiar with the syntax and resource types. Here is how you can create a Pod manifest easily.
- Step 1: Open Your Text Editor
Start with a text editor that you are familiar with.
- Step 2: Define the Manifest Structure
Initiate a new file with the name nginx-pod.yaml and add the following content:
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
– name: nginx
image: nginx:latest
ports:
– containerPort: 80
This manifest file will define a single running Pod on an NGINX container on port 80.
- Step 3: Save the File
Save the file with a .yaml or .yml extension.
Using kubectl to Apply and Manage Manifests
To manage a Kubernetes manifest file, use a kubectl command.
- Applying a Manifest
Use this command to create defined resources in your YAML file:
kubectl apply -f nginx-pod.yaml
This tells Kubernetes to read the file and create the Pod.
- Verifying Resource Status
To check the status, run:
kubectl get pods
To get detailed information:
kubectl describe pod nginx-pod
- Updating a Manifest
To reapply the YAML file, use:
kubectl apply -f nginx-pod.yaml
- Deleting a Resource
To delete a defined resource, run:
kubectl delete -f nginx-pod.yaml
Example: Full Deployment Manifest for a Web App
Here is a complete deployment example for a simple web application using NGINX, covering stages from deployment to ingress.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
– name: nginx
image: nginx:latest
ports:
– containerPort: 80
—
apiVersion: v1
kind: Service
metadata:
name: web-service
spec:
selector:
app: web
ports:
– protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
—
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
– host: web.local
http:
paths:
– path: /
pathType: Prefix
backend:
service:
name: web-service
port:
number: 80
This Kubernetes manifest file will deploy an NGINX-based app with three duplicates. Using a Service internally and an Ingress resource externally.
Guide To Troubleshooting A Kubernetes Manifest File
Issue | Cause | Fix / Tip |
YAML parse error | Incorrect indentation or syntax | Validate YAML with linters or online tools like YAML Lint |
CrashLoopBackOff status | Container keeps crashing due to app errors | Use kubectl logs <pod> to inspect logs |
Pods not scheduled (Pending) | Insufficient cluster resources or node selectors | Check node capacity and kubectl describe pod for more info |
Service not reachable | Wrong selector or port mismatch | Ensure the Service selector matches Pod labels |
Ingress not routing correctly | Ingress controller not installed or misconfigured | Deploy an Ingress controller like NGINX or Traefik |
Secret/ConfigMap not mounted | Incorrect volume or reference paths | Double-check volumeMounts and envFrom references |
Wrapping Up – Kubernetes Manifest File
Kubernetes manifest files are a core component of the declarative configuration in a cloud-based infrastructure. From simple pods to complex multi-dimensional applications, you can define and version control absolutely everything.
With proper syntax and the right templates, Manifest files can empower developers and operators to maintain control.
Frequently Asked Questions
How do I apply a manifest file in Kubernetes?
You can use the kubectl apply -f <filename>.yaml
command to deploy or update Kubernetes resources based on the manifest file.
What tools can I use to validate my manifest file?
You can use kubectl apply --dry-run=client -f <file>
or online tools like YAML Lint to validate YAML syntax before applying the manifest.
What are some common errors in Kubernetes manifests?
Common issues include incorrect indentation, mismatched selectors, missing fields, unsupported apiVersion
, and misconfigured volumes or ports.