• Cloud Container Engine

cce
  1. Help Center
  2. Cloud Container Engine
  3. API Reference 2.0
  4. Kubernetes API
  5. Deployment
  6. Creating a Deployment

Creating a Deployment

Function

This API is used to create a Deployment resource object.

  • A label should be attached to the Deployment object so the object can be displayed on the App Manager page of CCE console.

    Set the value of the metadata.labels key in the request message body as follows:

    labels:
        app: appname
        name: rcname
    • appname is the containerized application name displayed on the App Manager and can take any value.
    • name is the Deployment name and can take any value.

URI

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

POST /apis/extensions/v1beta1/namespaces/{namespace}/deployments

Table 1 describes the parameters of this API.

Table 1 Parameter description

Parameters

Mandatory

Description

namespace

Yes

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

pretty

No

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

Request

Request parameters:

Table 2 Request parameters

Parameters

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.

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

Table 11

Standard object's metadata.

spec

Yes

Table 3

Specification of the desired behavior of the Deployment.

status

No

Table 4

Most recently observed status of the Deployment.

Table 3 Data structure of the spec field

Parameters

Mandatory

Type

Description

minReadySeconds

No

integer

Minimum number of seconds for which a newly created pod should be ready without any of its containers 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 roll back 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.

rollbackTo

No

Table 5

The config this deployment is rolling back to. Will be cleared after rollback is done.

selector

No

Table 6

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

strategy

No

Table 7

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

template

Yes

Table 21

Template describes the pods that will be created.

Table 4 Data structure of the status field

Parameters

Mandatory

Type

Description

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

Table 8

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.

Table 5 Data structure of the rollbackTo field

Parameters

Mandatory

Type

Description

revision

No

integer

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

Table 6 Data structure of the selector field

Parameters

Mandatory

Type

Description

matchExpressions

No

Table 9

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.

Table 7 Data structure of the strategy field

Parameters

Mandatory

Type

Description

rollingUpdate

Yes

Table 10

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

type

No

string

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

Table 8 Data structure of the conditions field

Parameters

Mandatory

Type

Description

lastTransitionTime

No

Time

Last time the condition transitioned from one status to another.

lastUpdateTime

No

Time

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.

Table 9 Data structure of the matchExpressions field

Parameters

Mandatory

Type

Description

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 are In, NotIn, Exists and DoesNotExist.

values

No

string array

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.

Table 10 Data structure of the RollingUpateDeployment field

Parameters

Mandatory

Type

Description

maxSurge

No

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 cannot 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 at most 130% of desired pods.

maxUnavailable

No

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 cannot 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.

Example request:

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

Response

Response parameters:

For the description about response parameters, see Table 2

Example response:

{
    "kind": "Deployment",
    "apiVersion": "apps/v1beta1",
    "metadata": {
        "name": "deployment-test",
        "namespace": "default",
        "selfLink": "/apis/apps/v1beta1/namespaces/default/deployments/deployment-test",
        "uid": "d079d1a0-fc1f-11e7-9c3c-fa163eb8ad1a",
        "resourceVersion": "485774",
        "generation": 1,
        "creationTimestamp": "2018-01-18T07:18:42Z",
        "labels": {
            "name": "deployment-test"
        },
        "enable": true
    },
    "spec": {
        "replicas": 1,
        "selector": {
            "matchLabels": {
                "name": "deployment-test"
            }
        },
        "template": {
            "metadata": {
                "creationTimestamp": null,
                "labels": {
                    "name": "deployment-test"
                },
                "enable": true
            },
            "spec": {
                "containers": [
                    {
                        "name": "deployment-test",
                        "image": "172.16.5.235:20202/test/nginx",
                        "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": 2,
        "progressDeadlineSeconds": 600
    },
    "status": {}
}

Status Code

Table 11describes the status code of this API.

Table 11 Status code

Status Code

Description

201

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

For the description about status codes, see Status Codes.