更新时间:2022-04-18 GMT+08:00
分享

创建Deployment

功能介绍

该API用于创建一个Deployment资源对象。

如果要将创建的Deployment对象在CCE工作负载界面上正常显示,则必须给创建的Deployment资源对象添加labels标签。

设置请求消息体中的“metadata.labels”参数键值示例如下:

labels:
    app: deploymentname
其中:
  • 同命名空间下,deploymentname名称不要重复
  • deploymentname为显示在CCE工作负载界面上的工作负载名称,需要和metadata.name的值保持一致。且“metadata.labels.app”、“spec.selector.matchLabels.app”、“spec.template.metadata.labels.app”的值要和deploymentname的值同步。可参考请求示例。

URI

POST /apis/apps/v1/namespaces/{namespace}/deployments

表1 参数描述

参数

是否必选

描述

namespace

Yes

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

pretty

No

If 'true', then the output is pretty printed.

请求消息

请求参数

请求参数如表2所示。

表2 请求参数

参数

是否必选

参数类型

描述

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.

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.

metadata

Yes

metadata object

Standard object metadata.

spec

Yes

spec object

Specification of the desired behavior of the Deployment.

status

No

status object

Most recently observed status of the Deployment.

表3 spec字段数据结构说明

参数

是否必选

参数类型

描述

minReadySeconds

No

Integer

Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready)

paused

No

Boolean

Indicates that the deployment is paused.

progressDeadlineSeconds

No

Integer

The maximum time in seconds for a deployment to make progress before it is considered to be failed. The deployment controller will continue to process failed deployments and a condition with a ProgressDeadlineExceeded reason will be surfaced in the deployment status. Once autoRollback is implemented, the deployment controller will automatically rollback failed deployments. Note that progress will not be estimated during the time a deployment is paused. Defaults to 600s.

replicas

No

Integer

Number of desired pods. This is a pointer to distinguish between explicit zero and not specified. Defaults to 1.

revisionHistoryLimit

No

Integer

The number of old ReplicaSets to retain to allow rollback. This is a pointer to distinguish between explicit zero and not specified. Defaults to 2.

selector

No

selector object

Label selector for pods. Existing ReplicaSets whose pods are selected by this will be the ones affected by this deployment.

strategy

No

strategy object

The deployment strategy to use to replace existing pods with new ones.

template

Yes

template object

Template describes the pods that will be created.

表4 status字段数据结构说明

参数

是否必选

参数类型

描述

availableReplicas

No

Integer

Total number of available pods (ready for at least minReadySeconds) targeted by this deployment.

collisionCount

No

Integer

Count of hash collisions for the Deployment. The Deployment controller uses this field as a collision avoidance mechanism when it needs to create the name for the newest ReplicaSet.

conditions

No

conditions object

Represents the latest available observations of a deployment's current state.

observedGeneration

No

Integer

The generation observed by the deployment controller

readyReplicas

No

Integer

Total number of ready pods targeted by this deployment

replicas

No

Integer

Total number of non-terminated pods targeted by this deployment (their labels match the selector).

unavailableReplicas

No

Integer

Total number of unavailable pods targeted by this deployment.

updatedReplicas

No

Integer

Total number of non-terminated pods targeted by this deployment that have the desired template spec.

表5 rollbackTo字段数据结构说明

参数

是否必选

参数类型

描述

revision

No

Integer

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

表6 selector字段数据结构说明

参数

是否必选

参数类型

描述

matchExpressions

No

matchExpressions object

matchExpressions is a list of label selector requirements. The requirements are ANDed.

matchLabels

No

Object

matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed.

表7 strategy字段数据结构说明

参数

是否必选

参数类型

描述

rollingUpdate

Yes

RollingUpateDeployment object

Rolling update config params. Present only if DeploymentStrategyType = RollingUpdate.

type

No

String

Type of deployment. Can be "Recreate" or "RollingUpdate". Default is RollingUpdate.

表8 conditions字段数据结构说明

参数

是否必选

参数类型

描述

lastTransitionTime

No

String

Last time the condition transitioned from one status to another.

lastUpdateTime

No

String

The last time this condition was updated.

message

No

String

A human readable message indicating details about the transition.

reason

No

String

The reason for the condition's last transition.

status

No

String

Status of the condition, one of True, False, Unknown.

type

No

String

Type of deployment condition.

表9 matchExpressions字段数据结构说明

参数

是否必选

参数类型

描述

key

No

String

key is the label key that the selector applies to.

operator

No

String

operator represents a key's relationship to a set of values. Valid operators ard In, NotIn, Exists and DoesNotExist.

values

No

Array of strings

values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch.

表10 RollingUpateDeployment字段数据结构说明

参数

是否必选

参数类型

描述

maxSurge

No

String or Integer

The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to 25%. Example: when this is set to 30%, the new RC can be scaled up immediately when the rolling update starts, such that the total number of old and new pods do not exceed 130% of desired pods. Once old pods have been killed, new RC can be scaled up further, ensuring that total number of pods running at any time during the update is atmost 130% of desired pods.

maxUnavailable

No

String or Integer

The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to 25%. Example: when this is set to 30%, the old RC can be scaled down to 70% of desired pods immediately when the rolling update starts. Once new pods are ready, old RC can be scaled down further, followed by scaling up the new RC, ensuring that the total number of pods available at all times during the update is at least 70% of desired pods.

请求示例:

{
    "apiVersion": "apps/v1",
    "kind": "Deployment",
    "metadata": {
        "labels": {
            "app": "deployment-test"
        },
        "name": "deployment-test"
    },
    "spec": {
        "replicas": 1,
        "selector": {
            "matchLabels": {
                "app": "deployment-test"
            }
        },
        "template": {
            "metadata": {
                "labels": {
                    "app": "deployment-test"
                }
            },
            "spec": {
                "containers": [
                    {
                        "image": "nginx:alpine",
                        "imagePullPolicy": "IfNotPresent",
                        "name": "deployment-test"
                    }
                ],
                "imagePullSecrets": [{
                    "name": "default-secret"
                }]
            }
        }
    }
}

响应消息

响应参数

响应参数如表2所示。

响应示例:

{
    "kind": "Deployment",
    "apiVersion": "apps/v1",
    "metadata": {
        "name": "deployment-test",
        "namespace": "development",
        "selfLink": "/apis/apps/v1/namespaces/development/deployments/deployment-test",
        "uid": "31ddc359-d9f2-45aa-b6be-b26bf7194722",
        "resourceVersion": "12521",
        "generation": 1,
        "creationTimestamp": "2021-10-14T01:54:14Z",
        "labels": {
            "app": "deployment-test"
        }
    },
    "spec": {
        "replicas": 1,
        "selector": {
            "matchLabels": {
                "app": "deployment-test"
            }
        },
        "template": {
            "metadata": {
                "creationTimestamp": null,
                "labels": {
                    "app": "deployment-test"
                }
            },
            "spec": {
                "containers": [
                    {
                        "name": "deployment-test",
                        "image": "nginx:alpine",
                        "resources": {},
                        "terminationMessagePath": "/dev/termination-log",
                        "terminationMessagePolicy": "File",
                        "imagePullPolicy": "IfNotPresent"
                    }
                ],
                "restartPolicy": "Always",
                "terminationGracePeriodSeconds": 30,
                "dnsPolicy": "ClusterFirst",
                "securityContext": {},
                "imagePullSecrets": [
                    {
                        "name": "default-secret"
                    }
                ],
                "schedulerName": "default-scheduler"
            }
        },
        "strategy": {
            "type": "RollingUpdate",
            "rollingUpdate": {
                "maxUnavailable": "25%",
                "maxSurge": "25%"
            }
        },
        "revisionHistoryLimit": 10,
        "progressDeadlineSeconds": 600
    },
    "status": {}
}

状态码

表11 状态码描述API的状态码。

表11 状态码

状态码

描述

200

This operation succeeds, and a Endpoint resource object is returned.

异常状态码请参见状态码

分享:

    相关文档

    相关产品

close