Create a Deployment in Kubernetes With a Manifest File

Deployment objects in Kubernetes are very popular because they offer redundancy, flexibility and scalability for applications and services.


A deployment manifest file has a few sections we need to pay attention to because there is a difference between deploying a pod and a deployment object when looking into the manifest file.

A deployment manifest has the following sections.

  • Kind – The kind section is the same as pod deployment
  • Metadata – Same as pod deployment
  • Spec – In the spec section things get a bit tricky, the matchLabels holds the labels that link the deployment with the pod that will run the our app. The labels name needs to be the same in the matchLabels and in the template section and in the container name.

In the below deployment, I’m using an Ubuntu image, but I can use any image I would like to. In the last section of the file, I’m using command and args to keep the pod container running and not going ideal. If your image is already configured to run and not go ideal, you can remove the command and args options.

apiVersion: apps/v1
kind: Deployment
  name: server-deployment
      app: server-app
        app: server-app
        - name: server-app
          image: ubuntu
          command: ["/bin/sh"]
          args: ["-c", "sleep infinity"]
      restartPolicy: Always  

To run the deployment, save the file with a .yaml extension and run with the kubectl apply -f file.yaml