Creating a Deployment

Function

This API is used to create a Deployment.

URI

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

Table 1 describes the parameters of this API.

Table 1 Parameter description

Parameter

Mandatory

Description

namespace

Yes

Namespace to which the Deployment you want to create belongs.

pretty

No

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

Request

Request parameters

For the description about request parameters, see Table 2.

Table 2 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.

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 10

Standard object metadata.

spec

Yes

Table 3

Specification of the desired behavior of the Deployment.

status

No

Table 4

Most recently observed status of the Deployment. Read-only.

Table 3 Data structure of the spec field

Parameter

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

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 20

Template describes the pods that will be created.

Table 4 Data structure of the status field

Parameter

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

Parameter

Mandatory

Type

Description

revision

No

Integer

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

Table 6 Data structure of the selector field

Parameter

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

Parameter

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

Parameter

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

Parameter

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

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.

Table 10 Data structure of the RollingUpateDeployment field

Parameter

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": {
        "annotations": {
            "description": ""
        }, 
        "labels": {
            "appgroup": ""
        }, 
        "name": "deployment-test"
    }, 
    "spec": {
        "replicas": 1, 
        "selector": {
            "matchLabels": {
                "app": "deployment-test"
            }
        }, 
        "template": {
            "metadata": {
                "annotations": {
                    "metrics.alpha.kubernetes.io/custom-endpoints": "[{api:'',path:'',port:'',names:''}]", 
                    "com.huawei.scheduler/container-type": "secure-container"
                }, 
                "labels": {
                    "app": "deployment-test"
                }
            }, 
            "spec": {
                "containers": [
                    {
                        "image": "nginx:latest", 
                        "name": "container-0", 
                        "resources": {
                            "limits": {
                                "cpu": "500m", 
                                "memory": "1024Mi"
                            }, 
                            "requests": {
                                "cpu": "500m", 
                                "memory": "1024Mi"
                            }
                        }, 
                        "lifecycle": {}
                    }
                ], 
                "imagePullSecrets": [
                    {
                        "name": "imagepull-secret"
                    }
                ], 
                "affinity": {}
            }
        }, 
        "minReadySeconds": 0, 
        "strategy": {
            "type": "RollingUpdate", 
            "rollingUpdate": {
                "maxSurge": 0, 
                "maxUnavailable": 1
            }
        }
    }
}

Response

Response parameters

Table 2 describes the response parameters.

Example response

{
    "kind": "Deployment", 
    "apiVersion": "apps/v1beta1", 
    "metadata": {
        "name": "deployment-test", 
        "namespace": "8f6c39e7c269440c881bba2fc49586d6", 
        "selfLink": "/apis/apps/v1beta1/namespaces/8f6c39e7c269440c881bba2fc49586d6/deployments/deployment-test", 
        "uid": "ed89a51c-2728-11e8-b891-84a9c46e8c8b", 
        "resourceVersion": "4510929", 
        "generation": 1, 
        "creationTimestamp": "2018-03-14T01:42:17Z", 
        "labels": {
            "appgroup": ""
        }, 
        "annotations": {
            "description": ""
        }, 
        "enable": true
    }, 
    "spec": {
        "replicas": 1, 
        "selector": {
            "matchLabels": {
                "app": "deployment-test"
            }
        }, 
        "template": {
            "metadata": {
                "creationTimestamp": null, 
                "labels": {
                    "app": "deployment-test"
                }, 
                "annotations": {
                    "com.huawei.scheduler/container-type": "secure-container", 
                    "metrics.alpha.kubernetes.io/custom-endpoints": "[{api:'',path:'',port:'',names:''}]"
                }, 
                "enable": true
            }, 
            "spec": {
                "containers": [
                    {
                        "name": "container-0", 
                        "image": "nginx:latest", 
                        "resources": {
                            "limits": {
                                "cpu": "1", 
                                "memory": "1024Mi"
                            }, 
                            "requests": {
                                "cpu": "1", 
                                "memory": "1024Mi"
                            }
                        }, 
                        "lifecycle": {}, 
                        "terminationMessagePath": "/dev/termination-log", 
                        "terminationMessagePolicy": "File", 
                        "imagePullPolicy": "Always"
                    }
                ], 
                "restartPolicy": "Always", 
                "terminationGracePeriodSeconds": 30, 
                "dnsPolicy": "ClusterFirst", 
                "securityContext": {}, 
                "imagePullSecrets": [
                    {
                        "name": "imagepull-secret"
                    }
                ], 
                "affinity": {}, 
                "schedulerName": "default-scheduler"
            }
        }, 
        "strategy": {
            "type": "RollingUpdate", 
            "rollingUpdate": {
                "maxUnavailable": 1, 
                "maxSurge": 0
            }
        }, 
        "revisionHistoryLimit": 2, 
        "progressDeadlineSeconds": 600
    }, 
    "status": {}
}

Status Code

Table 11 describes the status code of this API.

Table 11 Status code

Status Code

Description

201

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

For more status codes, see Status Codes.