Why setting up the revision of a deployment in Kubernetes?

11/6/2018

In the book Kubernetes: Up & Running, on the section "Creating Deployments", it has a yaml file that is being used for deployments that starts like this:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations: 
    deployment.kubernetes.io/revision: "1"

What's the point of setting up deployment.kubernetes.io/revision: "1"?

This is a file that is going to be applied, not the result of querying the server.

-- pupeno
kubernetes

1 Answer

11/6/2018

This annotation is set by Kubernetes. It is required for deployment to identify it's respective Replicaset.

Ok, let me explain. A Deployment creates Replicaset. This Replicaset is responsible for creating Pod's.

Whenever, you made some changes in deployment's podTemplate, it creates a new replicaset. But it don't delete old replicaset as it is necessary if you want to rollback to a previous version.

Now, how deployment will know which replicaset is currently being used? Here comes the deployment.kubernetes.io/revision: annotation. Replicaset also contains this annotation. So, deployment know which replicaset is being used by matching revision number of it's annotation with the revision number of replicaset's annotation.

You can read this nice article to understand more: How Kubernetes Deployments Work.

To know how to rollback deploymment to a previous version, see here.

-- Emruz Hossain
Source: StackOverflow