What's a Kubernetes Deployment object?

2 min read | by Jordi Prats

Maybe the most common object used for deploying applications on Kubernetes is the Deployment object. It is intended to provide declarative updates for Pods at a controlled rate.

With a Deployment we are setting the desired state of a ReplicaSet. The Deployment controller will take the appropriate actions to adjust the ReplicaSet so it has the correct amount of Pods

The most relevant parts of a Deployment definition are:

  • replicas: Specifies the number of Pod replicas we want to have
  • template: Just as many other kubernetes objects (Job), contains the Pod definition template that is going to be used to create the actual Pods
  • selector: With the selector we are telling the Deployment which Pods are under it's control. Thus, if we are using matchLabels we must make sure the same label is defined on the Pod template.

A full example of a Deployment object is:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-deploy
spec:
  replicas: 6
  selector:
    matchLabels:
      app: demo-deploy
  template:
    metadata:
      labels:
        app: demo-deploy
    spec:
      containers:
      - name: demo-deploy
        image: alpine:latest
        command: ["sleep"]
        args: ["1h"]
        ports:
        - name: http
          containerPort: 8000

Posted on 09/08/2021

Categories