manifest file in kubernetes example

Manifest File in Kubernetes: A Step-by-Step Example

By Steven White
AD

A Manifest File in Kubernetes is like a blueprint for deploying applications. It's a crucial component of Kubernetes (K8s) that defines the desired state of your cluster. Written in YAML or JSON, manifest files tell K8s exactly what you want to run and how you want it to run. Let's dive into the world of Kubernetes manifests, using real-life examples to illustrate their power.

Before diving into specifics, let'scidos some basics. Kubernetes uses declarative management, meaning you specify what you want, not how to achieve it. This is done through manifests. Now, let's discuss two key types of Kubernetes objects that manifest files describe: Pods and Deployments.

Pod Manifests

A Pod is the smallest and simplest unit of the Kubernetes Platform that you create or deploy. It represents a single instance of a running process on your K8s cluster. Here's a basic Pod manifest example:

AD
a diagram with the words how to learn kubernets on it and an image of
a diagram with the words how to learn kubernets on it and an image of
Modify your Kubernetes manifests with Kustomize
Modify your Kubernetes manifests with Kustomize
the kuberite's yaml explanation poster
the kuberite's yaml explanation poster

apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx:latest

In this example, we're creating a Pod named 'nginx-pod' that runs the NGINX image. Now, let's discuss how to create a multi-container Pod:

Multi-Container Pods

Kubernetes allows creating Pods with multiple containers that need to run in the same context. Here's an example of a manifest that runs both an NGINX web server and a Redis cache:

the kubernets basics diagram with several different types of text and symbols on it
the kubernets basics diagram with several different types of text and symbols on it
an overview of kubernets architecture
an overview of kubernets architecture
How Kubernetes Works?
How Kubernetes Works?

apiVersion: v1
kind: Pod
metadata:
name: nginx-redis
spec:
containers:
- name: nginx
image: nginx:latest
- name: redis
image: redis:alpine

Now, let's discuss another critical Kubernetes object – Deployments. Deployments ensure that a specified number of Pod Template objects are running. Here's an example:

Deployment Manifests

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
template:
metadata:
spec:
image: nginx:latest

In this example, we're creating a Deployment named 'nginx-deployment' that guarantees there are always 3 Pods running the NGINX image. If a Pod crashes or is deleted, the Deployment will create a new one.

AD

Deployment Updates

Deployments also allow you to update your application without downtime. Here's how you could update the NGINX image to a specific version:

Kubernetes Kind Deployment Example ☸️ | Run Apps Locally in Minutes
Kubernetes Kind Deployment Example ☸️ | Run Apps Locally in Minutes
Kubernetes
Kubernetes
Mastering Kubernetes: A Collection of Essential Programming Practices
Mastering Kubernetes: A Collection of Essential Programming Practices
Kubernetes Architecture: Inside the Worker Node
Kubernetes Architecture: Inside the Worker Node
the kubernets concept is depicted in this graphic above it's description
the kubernets concept is depicted in this graphic above it's description
a flow diagram with several different types of data
a flow diagram with several different types of data

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
template:
metadata:
spec:
image: nginx:1.16.1

By applying this manifest, K8s will gradually update all three NGINX Pods without any downtime. Isn't that amazing?

Kubernetes manifests are powerful tools that allow you to describe your desired state in a clear, organized way. Whether you're managing simple Pods or complex Deployments, they're an essential part of the K8s ecosystem. Now, go forth and create manifests to your heart's content!

AD
The Complete Request Journey in Kubernetes: What Really Happens Behind the Scenes?
The Complete Request Journey in Kubernetes: What Really Happens Behind the Scenes?
AD