A manifest file in Kubernetes is a YAML file that contains the configuration needed to deploy and manage an application or other components in a Kubernetes cluster. It defines resources like Deployments, Services, ConfigMaps, PersistentVolumes, and more. Each manifest file tells Kubernetes what to create, how to run it, and how to manage it.
Here's a breakdown of the types of manifest files and their purposes, followed by examples:
- Deployment Manifest
This file tells Kubernetes to run your application containers. It specifies the image, the number of replicas (copies of the app), and environment variables.
Example: django-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: django-deployment
labels:
app: django
spec:
replicas: 3 # Run 3 copies of the app
selector:
matchLabels:
app: django
template:
metadata:
labels:
app: django
spec:
containers:
- name: django
image: your-dockerhub-username/django-app:latest # Replace this with your own Docker image
ports:
- containerPort: 8000
env:
- name: DJANGO_SETTINGS_MODULE
value: "myproject.settings"
Explanation:
kind: Deployment specifies that this manifest will create a deployment.
replicas: 3 tells Kubernetes to keep 3 running copies of the app for reliability.
containers specifies which Docker image to use and the port the container listens on.
- Service Manifest
This file creates a way for users to connect to your application. It exposes the Deployment to the outside world or within the Kubernetes cluster.
Example: django-service.yaml
apiVersion: v1
kind: Service
metadata:
name: django-service
spec:
selector:
app: django
ports:
- protocol: TCP port: 80 # External users will use this port targetPort: 8000 # Connects to port 8000 inside the containers type: LoadBalancer
Explanation:
kind: Service defines a network service that exposes your app to users.
type: LoadBalancer allows external access by creating a public IP that users can connect to.
targetPort matches the port your Django app listens to inside the container (8000 in this case).
- ConfigMap Manifest (Optional)
A ConfigMap stores configuration data (like environment variables) that your app can use.
Example: django-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: django-config
data:
DJANGO_SETTINGS_MODULE: "myproject.settings"
SECRET_KEY: "your-secret-key"
Explanation:
kind: ConfigMap helps you manage environment settings without hardcoding them into your app.
You can reference these settings from your Deployment by using environment variables.
- PersistentVolume Manifest (Optional)
A PersistentVolume (PV) is storage that stays even if your app restarts. Use it to store files or databases.
Example: django-persistent-volume.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: django-pv
spec:
capacity:
storage: 5Gi # Allocate 5GB of storage
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data/django"
Explanation:
kind: PersistentVolume provides long-term storage for data that persists even when your containers stop or restart.
capacity: 5Gi means this volume can store up to 5 Gigabytes of data.
How to Use These Manifest Files
Create each YAML file (django-deployment.yaml, django-service.yaml, etc.) based on your app's needs.
Run the following command to deploy your app:
kubectl apply -f django-deployment.yaml
kubectl apply -f django-service.yaml
kubectl apply -f django-configmap.yaml # Optional
kubectl apply -f django-persistent-volume.yaml # Optional
Summary
Manifest files are like blueprints for deploying your app in Kubernetes.
Deployment files define how your app should run.
Service files make your app accessible to users.
ConfigMap files store environment settings.
PersistentVolume files provide long-term storage.
This setup ensures your app can handle more users, automatically restart if it crashes, and keep running even if parts of it fail.
Top comments (0)