kubernetes

How To Create Deployment File In Kubernetes?

Let’s understand what contents make a deployment file and what exactly it means.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: <pod_name>
  namespace: <namespace-name>
spec:
  selector:
    matchLabels:
      app: <app_name>
  template:
    metadata:
      labels:
        app: <app_name>
    spec:
      containers:
      - image: nginx:latest
        name: nginx
        volumeMounts:
        - name: persistent-storage
          mountPath: /data/
      volumes:
      - name: persistent-storage
        persistentVolumeClaim:
          claimName: pvc-name
  • apiVersion represents from which group Kind belongs.
  • kind represents the type of Kubernetes objects.
  • metadata before the template section defines the metadata of the pod, in which namespace you want to deploy the pod, what should be the name of the pod, etc.
  • spec before the template section defines the specification for the pod, such as the selector, which is in charge of selecting all containers whose names match the names in the matchLabels section.
  • template which is used to define property of containers.
  • metadata below the template section defines the metadata of container, such as labels.
  • spec after the template section defines the specification of the containers, such as the image name, container name, which volume to mount on which path, etc.
  • Volumes define which type of volume to use on the container to mount.

To create the deployment in the Kubernetes cluster run the below command

kubectl create -f <deployment.yaml>

    MtroView team is giving its best & working hard to provide the content to help you understand things better in simple terms. We are heartily open to receiving suggestions to improve our content to help more people in society. Please write to us in the form of a comment or can also send an email to mtroview@gmail.com

    Leave a Comment

    Your email address will not be published. Required fields are marked *