Rolling Back a Deployment

Function

This API is used to roll back a Deployment.

URI

PATCH /apis/apps/v1/namespaces/{namespace}/deployments/{name} (for clusters of v1.17 or later)

POST /apis/apps/v1beta1/namespaces/{namespace}/deployments/{name}/rollback (for clusters of v1.15 and earlier)

POST /apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}/rollback (for clusters of v1.15 and earlier)

Table 1 describes the parameters of this API.

Table 1 Parameter description

Parameter

Mandatory

Description

name

Yes

Name of the DeploymentRollback.

namespace

Yes

Object name and auth scope, such as for teams and projects.

Request

Request parameters:

Table 2 and Table 3 describe the request parameters.

Table 2 Request header parameters

Parameter

Mandatory

Description

Content-Type

Yes

Type (or format) of the message body. The value must be:

  • application/json-patch+json

This header is required only for the patch request of version 1.17.

Table 3 Request parameters

Parameter

Mandatory

Type

Description

apiVersion

Yes

String

apiVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values.

op

Yes

String

Operation for this patch, value must be "replace".

path

Yes

String

Path to replace for this deployment, must be "/spec/template" or "/metadata/annotations"

value

Yes

template object

or

revision object

Template describes the pods' template that will be rolled back which can be got from certain replicaset.spec.template. Template corresponds to path "/spec/template".

Revision describes the revision of ReplicaSet to roll back. Revision corresponds to path "/metadata/annotations"

kind

Yes

String

kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase.

name

Yes

String

Required: This must match the Name of a deployment.

rollbackTo

No

rollbackTo object

The config of this deployment rollback.

updatedAnnotations

No

Object

The annotations to be updated to a deployment

Table 4 Data structure of the rollbackTo field

Parameter

Mandatory

Type

Description

revision

No

Integer

The revision to roll back to. If set to 0, roll back to the last revision.

Table 5 revision parameter description

Parameter

Mandatory

Type

Description

deployment.kubernetes.io/revision

Yes

String

The revision of replicaset to roll back.

Request example for version 1.17 or later:

[
	{
		"op": "replace",
		"path": "/spec/template",
		"value": {
			"metadata": {
				"creationTimestamp": null,
				"labels": {
					"app": "test-roll"
				},
				"annotations": {
					"metrics.alpha.kubernetes.io/custom-endpoints": "[{\"api\":\"\",\"path\":\"\",\"port\":\"\",\"names\":\"\"}]"
				}
			},
			"spec": {
				"containers": [
					{
						"name": "container-0",
						"image": "1*.*.*.*:20202/peedssw/nginx:latest",
						"env": [
							{
								"name": "PAAS_APP_NAME",
								"value": "test-roll"
							},
							{
								"name": "PAAS_NAMESPACE",
								"value": "default"
							},
							{
								"name": "PAAS_PROJECT_ID",
								"value": "47eb1d64cbeb45cfa01ae20af4f4b563"
							}
						],
						"resources": {
							"limits": {
								"cpu": "250m",
								"memory": "512Mi"
							},
							"requests": {
								"cpu": "100m",
								"memory": "100Mi"
							}
						},
						"terminationMessagePath": "/dev/termination-log",
						"terminationMessagePolicy": "File",
						"imagePullPolicy": "Always"
					}
				],
				"restartPolicy": "Always",
				"terminationGracePeriodSeconds": 30,
				"dnsPolicy": "ClusterFirst",
				"securityContext": {},
				"imagePullSecrets": [
					{
						"name": "default-secret"
					}
				],
				"affinity": {},
				"schedulerName": "default-scheduler",
				"tolerations": [
					{
						"key": "node.kubernetes.io/not-ready",
						"operator": "Exists",
						"effect": "NoExecute",
						"tolerationSeconds": 300
					},
					{
						"key": "node.kubernetes.io/unreachable",
						"operator": "Exists",
						"effect": "NoExecute",
						"tolerationSeconds": 300
					}
				],
				"dnsConfig": {
					"options": [
						{
							"name": "timeout",
							"value": ""
						},
						{
							"name": "ndots",
							"value": "5"
						},
						{
							"name": "single-request-reopen"
						}
					]
				}
			}
		}
	},
	{
		"op": "replace",
		"path": "/metadata/annotations",
		"value": {
			"deployment.kubernetes.io/revision": "6"
		}
	}
]

Request example for version earlier than 1.17:

{
    "kind": "DeploymentRollback",
    "apiVersion": "extensions/v1beta1",
    "name": "deploy-ex-12130306",
    "rollbackTo": {
        "revision": 0
    }
}

Response

Response parameters:

For the description about response parameters, see Table 3.

Response example for version 1.17 or later:

{
	"kind": "Deployment",
	"apiVersion": "apps/v1",
	"metadata": {
		"name": "test-roll",
		"namespace": "default",
		"selfLink": "/apis/apps/v1/namespaces/default/deployments/test-roll",
		"uid": "f5722cc7-1144-4834-9970-dcb505323d64",
		"resourceVersion": "2821114",
		"generation": 7,
		"creationTimestamp": "2020-06-22T07:14:40Z",
		"labels": {
			"appgroup": ""
		},
		"annotations": {
			"deployment.kubernetes.io/revision": "6"
		}
	},
	"spec": {
		"replicas": 1,
		"selector": {
			"matchLabels": {
				"app": "test-roll"
			}
		},
		"template": {
			"metadata": {
				"creationTimestamp": null,
				"labels": {
					"app": "test-roll"
				},
				"annotations": {
					"metrics.alpha.kubernetes.io/custom-endpoints": "[{\"api\":\"\",\"path\":\"\",\"port\":\"\",\"names\":\"\"}]"
				}
			},
			"spec": {
				"containers": [
					{
						"name": "container-0",
						"image": "1*.*.*.*:20202/peedssw/nginx:latest",
						"env": [
							{
								"name": "PAAS_APP_NAME",
								"value": "test-roll"
							},
							{
								"name": "PAAS_NAMESPACE",
								"value": "default"
							},
							{
								"name": "PAAS_PROJECT_ID",
								"value": "47eb1d64cbeb45cfa01ae20af4f4b563"
							}
						],
						"resources": {
							"limits": {
								"cpu": "250m",
								"memory": "512Mi"
							},
							"requests": {
								"cpu": "100m",
								"memory": "100Mi"
							}
						},
						"terminationMessagePath": "/dev/termination-log",
						"terminationMessagePolicy": "File",
						"imagePullPolicy": "Always"
					}
				],
				"restartPolicy": "Always",
				"terminationGracePeriodSeconds": 30,
				"dnsPolicy": "ClusterFirst",
				"securityContext": {},
				"imagePullSecrets": [
					{
						"name": "default-secret"
					}
				],
				"affinity": {},
				"schedulerName": "default-scheduler",
				"tolerations": [
					{
						"key": "node.kubernetes.io/not-ready",
						"operator": "Exists",
						"effect": "NoExecute",
						"tolerationSeconds": 300
					},
					{
						"key": "node.kubernetes.io/unreachable",
						"operator": "Exists",
						"effect": "NoExecute",
						"tolerationSeconds": 300
					}
				],
				"dnsConfig": {
					"options": [
						{
							"name": "timeout",
							"value": ""
						},
						{
							"name": "ndots",
							"value": "5"
						},
						{
							"name": "single-request-reopen"
						}
					]
				}
			}
		},
		"strategy": {
			"type": "Recreate"
		},
		"revisionHistoryLimit": 10,
		"progressDeadlineSeconds": 600
	},
	"status": {
		"observedGeneration": 6,
		"replicas": 1,
		"updatedReplicas": 1,
		"readyReplicas": 1,
		"availableReplicas": 1,
		"conditions": [
			{
				"type": "Available",
				"status": "True",
				"lastUpdateTime": "2020-06-22T08:08:42Z",
				"lastTransitionTime": "2020-06-22T08:08:42Z",
				"reason": "MinimumReplicasAvailable",
				"message": "Deployment has minimum availability."
			},
			{
				"type": "Progressing",
				"status": "True",
				"lastUpdateTime": "2020-06-22T08:08:42Z",
				"lastTransitionTime": "2020-06-22T07:14:40Z",
				"reason": "NewReplicaSetAvailable",
				"message": "ReplicaSet \"test-roll-74dd548fb8\" has successfully progressed."
			}
		]
	}
}

Response example for version earlier than 1.17:

{
    "kind": "Status",
    "apiVersion": "v1",
    "metadata": {},
    "status": "Success",
    "message": "rollback request for deployment \"deploy-ex-12130306\" succeeded",
    "code": 201
}

Status Code

Table 6 describes the status code of this API.

Table 6 Status code

Status Code

Description

201

The request has been fulfilled, resulting in the creation of a new resource.

For the description about error status codes, see Status Code.