What is Manifest?

What is Manifest?

In Kubernetes (k8s), a manifest is a YAML (or sometimes JSON) file that describes the desired state of a Kubernetes object, such as a pod, service, deployment, config map, or persistent volume. These manifests are used to create, update, and manage the resources within a Kubernetes cluster. The manifest file defines the configuration, specifications, and metadata for the Kubernetes object.

Here are some of the key components of a Kubernetes manifest:

  1. apiVersion: Specifies the API version of the Kubernetes object.

  2. kind: Specifies the type of Kubernetes object being defined (e.g., Pod, Service, Deployment).

  3. metadata: Contains data that helps uniquely identify the object, including a name, namespace, labels, and annotations.

  4. spec: Describes the desired state of the object. The contents of this section vary depending on the type of Kubernetes object being defined.

For creating different manifest follow below steps:-

Step 1: Create minikube cluster with the help of this guide:

https://lalitakashyapblog.hashnode.dev/installation-of-minikube

Step 2: Firstly create nginx pod in simple way

kubectl run my-nginx --image=nginx:latest

Step 3: Check pod created or not

kubectl get pods

Step 4: Move into minikube cluster

 docker exec -it <container ID> bash

Step 5: Check docker container

docker ps

Step 6: Check nginx container is running

Step 7: Exit from container

exit

Step 8: Check container(No nginx container is running here)

docker ps

Step 9: Create directory and move into it

mkdir projects
cd projects/

Step 10: Check k8s namespace

kubectl get namespace

Step 11: Check created pods namespace

kubectl get pods

Step 12: Check container for "kube-system" namespace

kubectl get pods -n kube-system

Step 13: Create own namespace

kubectl create namespace node-app

Step 14: Check list of namespace

kubectl get ns

Step 15:Now create manifest file for creating pod

apiVersion: v1
kind: Pod
metadata:
  name: node-pod
  namespace: node-app
spec:
  containers:
  - name: node-container
    image: trainwithshubham/node-app-batch-6
    ports:
    - containerPort: 8000

Step 16: Apply created manifest file

kubectl apply -f pod.yml

Step 17: Check pod in namespace

kubectl get pods -n node-app

Step 18: Move into minikube cluster

minikube ssh

Step 19: Check docker container

docker ps

Step 20: Exit from minikube cluster

exit

Step 21: Create replica set file

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: node-app-replica-set
  namespace: node-app
  labels:
    app: guestbook
    tier: node-label
spec:
  # modify replicas according to your case
  replicas: 3
  selector:
    matchLabels:
      tier: node-label
  template:
    metadata:
      namespace: node-app
      labels:
        tier: node-label
    spec:
      containers:
      - name: node-container-rep
        image: trainwithshubham/node-app-batch-6

Step 22: Apply created manifest file

kubectl apply -f replica-set.yml

Step 23: Check pod using namespace

kubectl get pods -n node-app

Step 24: Delete replica set

kubectl delete -f replica-set.yml

Step 25: Create deployment file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: node-app-deployment
  namespace: node-app
  labels:
    app: node-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: node-app
  template:
    metadata:
      name: node-pod
      namespace: node-app 
      labels:
        app: node-app
    spec:
      containers:
        - name: node-container
          image: trainwithshubham/node-app-batch-6
          ports:
           - containerPort: 8000

Step 26: Apply created manifest file

kubectl apply -f deployment.yml

Step 27: Check deployment created or not

kubectl get deployment -n node-app

Step 28: Check pod created or not

kubectl get pods -n node-app

Step 29: Delete one of the pod

kubectl delete pod <pod name> -n node-app

Step 30: Again check pod(one pod created again: This is called Autohealing)

kubectl get pods  -n node-app

Step 31: You can also scale up or down

kubectl scale deployment node-app-deployment --replicas=6 -n node-app

Kubernetes manifests are essential for defining and managing the desired state of your applications and resources within a cluster. By using YAML files to describe the configuration, specifications, and metadata of Kubernetes objects, you can leverage the power of Kubernetes to automate deployment, scaling, and management tasks. Properly writing, versioning, and managing these manifests is crucial for maintaining a reliable and scalable Kubernetes environment.

Thank you🙏

Keep Learning..