What's a Kubernetes Deployment object?

2 min read

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: ampa-3.2
spec:
  replicas: 5
  selector:
    matchLabels:
      app: ampa-3.2
  template:
    metadata:
      labels:
        app: ampa-3.2
    spec:
      containers:
      - name: ampa
        image: ampa:3.2
        ports:
        - name: http
          containerPort: 8000

Posted on 09/08/2021

Categories