文档首页 > > API参考> Kubernetes API> Deployment> 创建Deployment的回滚操作

创建Deployment的回滚操作

分享
更新时间: 2020/06/23 GMT+08:00

功能介绍

This API is used to create rollback of a Deployment Rollback.

URI

PATCH /apis/apps/v1/namespaces/{namespace}/deployments/{name} (Supports only 1.17 and 1.17+)

POST /apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}/rollback (Compatible)

POST /apis/apps/v1beta1/namespaces/{namespace}/deployments/{name}/rollback (Supports only 1.7)

表1描述该API的参数。

表1 参数解释

参数

是否必选

描述

name

Yes

name of the DeploymentRollback

namespace

Yes

object name and auth scope, such as for teams and projects

请求消息

请求参数:

请求参数如表2表3所示。

表2 请求Header参数说明

参数

是否必选

描述

Content-Type

Yes

消息体的类型(格式),取值:

  • application/json-patch+json

仅1.17版本的patch请求需要该header

表3 请求参数

参数

是否必选

参数类型

描述

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 rollback which can be got from certain replicset.spec.template, template correspond to path “/spec/template”.

Revision describes the revision of replicset to rollback, revision correspond 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

表4 rollbackTo字段数据结构说明

参数

是否必选

参数类型

描述

revision

No

Integer

The revision to rollback to. If set to 0, rollbck to the last revision.

表5 revision字段说明

参数

是否必选

参数类型

描述

deployment.kubernetes.io/revision

Yes

String

The revision of replicset to rollback.

1.17及以上版本请求示例:

[
	{
		"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"
		}
	}
]

1.17以下版本请求示例:

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

响应消息

响应参数:

响应参数的详细描述请参见表3

1.17及以上版本请求示例:

{
	"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."
			}
		]
	}
}

1.17以下版本响应示例:

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

状态码

表6描述API的状态码。

表6 状态码

状态码

描述

201

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

异常状态码请参见状态码

分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!

非常感谢您的反馈,我们会继续努力做到更好!

反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

智能客服提问云社区提问