创建Deployment的回滚操作
功能介绍
This API is used to create rollback of a Deployment Rollback.
URI
PATCH /apis/apps/v1/namespaces/{namespace}/deployments/{name} (Supports 1.17 and 1.17+)
POST /apis/apps/v1beta1/namespaces/{namespace}/deployments/{name}/rollback (Supports only 1.7~1.15)
POST /apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}/rollback (Supports 1.15 and 1.15-)
表1描述该API的参数。
请求消息
请求参数:
参数 |
是否必选 |
描述 |
---|---|---|
Content-Type |
Yes |
消息体的类型(格式),取值:
仅1.17版本的patch请求需要该header。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
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 replicaset.spec.template, template correspond to path “/spec/template”. Revision describes the revision of replicaset 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 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
revision |
No |
Integer |
The revision to rollback to. If set to 0, rollbck to the last revision. |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
deployment.kubernetes.io/revision |
Yes |
String |
The revision of replicaset 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 }
