Creating a Deployment
Function
This API is used to create a Deployment.
After Deployment creation, only the Deployments with labels can be displayed on the Workloads page of the CCE console.
Set the metadata.labels parameter in the request body as follows:
labels:
app: deploymentname
- Deployment names must be unique in a namespace.
- deploymentname indicates the workload name displayed on the Workloads page of the CCE console. The value of deploymentname must be the same as the value of metadata.name. The values of metadata.labels.app, spec.selector.matchLabels.app, and spec.template.metadata.labels.app must be the same as the value of deploymentname. For details, see the Example Request.
URI
POST /apis/apps/v1/namespaces/{namespace}/deployments (for clusters later than v1.15)
POST /apis/extensions/v1beta1/namespaces/{namespace}/deployments (for clusters of v1.15 and earlier)
Table 1 describes the parameters of this API.
Request
Request parameters:
Table 2 describes the 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 |
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. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
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 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. |
|
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. |
|
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 |
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. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
revision |
No |
Integer |
The revision to roll back to. If set to 0, roll back to the last revision. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
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. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
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. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
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. |
|
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. |
|
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 atmost 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": {
"app": "deployment-test"
},
"name": "deployment-test"
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"app": "deployment-test"
}
},
"template": {
"metadata": {
"labels": {
"app": "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 11 describes the status code of this API.
|
Status Code |
Description |
|---|---|
|
200 |
This operation succeeds, and an Endpoint resource object is returned. |
For the description about error status codes, see Status Code.
Last Article: Deployment
Next Article: Rolling Back a Deployment
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.