Help Center> ServiceStage> API Reference> Application Management V2 APIs> Instance> Creating an Application Component Instance
Updated on 2024-06-14 GMT+08:00

Creating an Application Component Instance

Function

This API is used to create a component instance.

URI

POST /v2/{project_id}/cas/applications/{application_id}/components/{component_id}/instances

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Tenant's project ID. See Obtaining a Project ID.

application_id

Yes

String

Application ID. See Obtaining All Applications.

component_id

Yes

String

Component ID. See Obtaining All Components of an Application.

Request

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

Content-Type

Yes

String

Message body type or format.

X-Auth-Token

Yes

String

API calling can be authenticated using a token or AK/SK. If you use a token, this parameter is mandatory and must be set to the token. For details about how to obtain a token, see Obtaining a User Token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Component instance name.

The value can contain 2 to 63 characters, including lowercase letters, digits, and hyphens (-). It must start with a lowercase letter and end with a lowercase letter or digit.

environment_id

Yes

String

Environment ID.

replica

Yes

Integer

Number of instance replicas.

flavor_id

Yes

String

Resource specifications, which can be obtained by using the API in Obtaining All Supported Flavors of Application Resources.

If you need to customize resource specifications, the format is CUSTOM-xxG:xxm-xxm:xxGi-xxGi. Where:

  • xxG: storage capacity allocated to a component instance. It is a reserved field. You can set it to a fixed number.
  • xxm-xxm: the maximum and minimum number of CPU cores allocated to a component instance.
  • xxGi-xxGi: the maximum and minimum memory allocated to a component instance.

For example, CUSTOM-10G:0.5m-0.25m:1.6Gi-0.8Gi indicates that the maximum number of CPU cores allocated to a component instance is 0.5, the minimum number of CPU cores is 0.25, the maximum memory is 1.6 Gi, and the minimum memory is 0.8 Gi.

artifacts

Yes

Map<String, Object>

Artifact. key indicates the component name. In the Docker container scenario, key indicates the container name. See Table 21.

If the source parameters of a component specify the software package source, this parameter is optional, and the software package source of the component is inherited by default. Otherwise, this parameter is mandatory.

version

Yes

String

Application component version that meets version semantics. Example: 1.0.0.

configuration

No

Object

Configuration parameters, such as environment variables, deployment configurations, and O&M monitoring. By default, this parameter is left blank. See Table 4.

description

No

String

Description.

The value can contain up to 128 characters.

external_accesses

No

Array of objects

External network access. See Table 22.

refer_resources

Yes

Array of objects

Deployed resources. See Table 23.

Table 4 configuration parameters

Parameter

Mandatory

Type

Description

env

No

Array of objects

Environment variable. See Table 5.

storage

No

Array of objects

Data storage configuration. See Table 6.

strategy

No

Object

Upgrade strategy. See Table 7.

lifecycle

No

Object

Lifecycle. See Table 8.

scheduler

No

Object

Scheduling strategy. See Table 9.

probes

No

Object

Health check. See Table 10.

container_spec

No

Object

Container information. See Table 24.

Table 5 environment parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Environment variable name.

The value contains 1 to 64 characters, including letters, digits, underscores (_), hyphens (-), and dots (.), and cannot start with a digit.

value

Yes

String

Environment variable value.

Table 6 storage parameters

Parameter

Mandatory

Type

Description

type

Yes

String

Storage type. Value:

  • HostPath: host path mounting.
  • EmptyDir: temporary directory mounting.
  • ConfigMap: configuration item mounting.
  • Secret: secret volume mounting.
  • PersistentVolumeClaim: cloud storage mounting.

parameters

Yes

Object

Storage parameter. See Table 19.

mounts

Yes

Array of objects

Directory mounted to the container. See Table 20.

Table 7 strategy parameter

Parameter

Mandatory

Type

Description

upgrade

No

String

Upgrade policy. Value: Recreate or RollingUpdate (default). The former indicates in-place upgrade while the latter indicates rolling upgrade.

Table 8 lifecycle parameters

Parameter

Mandatory

Type

Description

entrypoint

No

Object

Startup command. See Table 16.

post-start

No

Object

Post-start processing. See Table 17.

pre-stop

No

Object

Pre-stop processing. See Table 17.

Table 9 scheduler parameters

Parameter

Mandatory

Type

Description

affinity

No

Object

Affinity. See Table 15.

anti-affinity

No

Object

Anti-affinity. See Table 15.

Table 10 probes parameters

Parameter

Mandatory

Type

Description

livenessProbe

No

Object

Component liveness probe. See Table 11.

readinessProbe

No

Object

Component service probe. See Table 11.

Table 11 probes_object parameters

Parameter

Mandatory

Type

Description

type

Yes

String

Value: http, tcp, or command. The check methods are HTTP request check, TCP port check, and command execution check, respectively.

parameters

Yes

Object

Parameters.

delay

No

Integer

Interval between the startup and detection.

timeout

No

Integer

Detection timeout interval.

Table 12 probes_param_http parameters

Parameter

Mandatory

Type

Description

scheme

No

String

Value: HTTP or HTTPS.

host

No

String

Pod IP address (default). You can specify an IP address.

port

No

Integer

Port.

path

No

String

Request path.

Table 13 probes_param_command parameters

Parameter

Mandatory

Type

Description

command

No

Array of String

Command list.

Table 14 probes_param_tcp parameters

Parameter

Mandatory

Type

Description

port

No

Integer

Port

Table 15 scheduler_affinity parameters

Parameter

Mandatory

Type

Description

az

No

Array of String

AZ list.

node

No

Array of String

Node private IP address list.

application

No

Array of String

Component instance list.

Table 16 lifecycle_entrypoint parameters

Parameter

Mandatory

Type

Description

command

No

Array of String

Command that can be executed.

args

No

Array of String

Running parameters.

Table 17 lifecycle_process parameters

Parameter

Mandatory

Type

Description

type

No

String

Value: command or http. The former indicates command execution and the latter indicates HTTP requests.

parameters

No

Object

Post-start or pre-stop processing parameters. See Table 18.

Table 18 lifecycle_process_parameters parameters

Parameter

Mandatory

Type

Description

command

No

Array of String

Command parameters, for example, ["sleep", "1"]. This parameter is applicable to the command type.

host

No

String

Pod IP address (default). You can also specify an IP address. This parameter is applicable to the http type.

port

No

Integer

Port number. This parameter is applicable to the http type.

path

No

String

Request URL. This parameter is applicable to the http type.

Table 19 storage_parameters parameters

Parameter

Mandatory

Type

Description

path

No

String

Host path. This parameter is applicable to the HostPath storage type.

name

No

String

Name of a configuration item or secret. This parameter is applicable to the ConfigMap and Secret storage type.

defaultMode

No

Integer

Permission to be mounted. The value is in decimal format, for example, 384.

medium

No

String

This parameter is applicable to EmptyDir storage. If it is not specified, the default disk medium is used. If it is set to memory, memory storage is enabled.

Table 20 storage_mounts parameters

Parameter

Mandatory

Type

Description

path

Yes

String

Path of the mounted disk.

subPath

No

String

Sub-path of the mounted disk.

readOnly

Yes

boolean

Permission of the mounted disk, which can be read-only or read/write.

Table 21 artifact parameters

Parameter

Mandatory

Type

Description

storage

Yes

String

Storage mode. Value: swr (software repository), swr (image), obs. and codearts.

type

Yes

String

Type.

  • VM-based deployment supports package.
  • Container-based deployment supports package and image.

url

Yes

String

Software package or image address. For a component deployed on a VM, this parameter is the software package address. For a component deployed based on a container, this parameter is the image address or component name:v${index}. The latter indicates that the component source code or the image automatically built using the software package will be used.

auth

Yes

String

Authentication mode. Value: iam or none. Default value: iam.

version

No

String

Version number.

properties

No

Map<String, Object>

Property information.

Table 22 external_accesses parameters

Parameter

Mandatory

Type

Description

protocol

Yes

String

Protocol. Value: http or https.

address

Yes

String

Access address.

forward_port

Yes

Integer

Port number.

Table 23 refer_resources parameters

Parameter

Mandatory

Type

Description

id

Yes

String

Resource ID.

If type is set to ecs, the value of this parameter must be Default.

type

Yes

String

Basic resources: cce, as, and ecs.

Optional resources: rds, dcs, elb, cse, and other services.

refer_alias

No

String

Application alias, which is provided only in DCS scenario. Value: "distributed_session", "distributed_cache", "distributed_session, distributed_cache". Default value: "distributed_session, distributed_cache".

parameters

No

Map<String, Object>

Reference resource parameter.

NOTICE:
  • When type is set to cce, this parameter is mandatory. You need to specify the namespace of the cluster where the component is to be deployed. Example: {"namespace": "default"}.
  • When type is set to ecs, this parameter is mandatory. You need to specify the hosts where the component is to be deployed. Example: {"hosts":["04d9f887-9860-4029-91d1-7d3102903a69", "04d9f887-9860-4029-91d1-7d3102903a70"]}}.
Table 24 container_spec parameters

Parameter

Mandatory

Type

Description

containers

No

Array of objects

Container information. See Table 25.

type

No

String

Workload type.

  • deployment
  • statefulset
Table 25 container parameters

Parameter

Mandatory

Type

Description

name

No

String

Container name.

size

No

Object

Container size. See Table 26.

env

No

Array of objects

Environment variable. See Table 5.

storage

No

Array of objects

Data storage configuration. See Table 6.

lifecycle

No

Object

Lifecycle. See Table 8.

probes

No

Object

Health check. See Table 10.

Table 26 size parameter

Parameter

Mandatory

Type

Description

id

No

String

Resource specifications, which can be obtained by using the API in Obtaining All Supported Flavors of Application Resources.

If you need to customize resource specifications, the format is CUSTOM-xxG:xxm-xxm:xxGi-xxGi. Where:

  • xxG: storage capacity allocated to a component instance. It is a reserved field. You can set it to a fixed number.
  • xxm-xxm: the maximum and minimum number of CPU cores allocated to a component instance.
  • xxGi-xxGi: the maximum and minimum memory allocated to a component instance.

For example, CUSTOM-10G:0.5m-0.25m:1.6Gi-0.8Gi indicates that the maximum number of CPU cores allocated to a component instance is 0.5, the minimum number of CPU cores is 0.25, the maximum memory is 1.6 Gi, and the minimum memory is 0.8 Gi.

Response

Table 27 Response parameters

Parameter

Type

Description

job_id

String

Job ID, which is used to query information about the created job.

instance_id

String

Component instance ID.

Example Request

Create component instance component-instance-name. Select the environment whose ID is 6e763000-9128-4a9d-adea-34c42cc5344d as the running environment. Select the demo.jar package in the myapp bucket of OBS as the deployment component. Select the CCE resource whose ID is b6862a62-d916-11e9-bdf1-0255ac101fd9 and the ELB resource whose ID is 8c0a45cc-626f-4d65-8257-507ee059aa9a as the deployment resources.

{
    "name": "component-instance-name", 
    "environment_id": "6e763000-9128-4a9d-adea-34c42cc5344d", 
    "flavor_id": "MICRO-5G:0.5m:1G", 
    "replica": 1, 
    "artifacts": {
        "container-name": {
            "storage": "obs", 
            "type": "package",            
            "url": "obs://myapp/demo.jar",
	    "properties": {
				"bucket": "myapp",
				"key": "demo.jar",
				"endpoint": "https://obs.region_id.external_domain_name.com"
			},
            "auth": "iam"
        }
    }, 
    "version": 1, 
    "description": "instance desc", 
    "configuration": {
        "env": [
            {
                "name": "log-level", 
                "value": "warn"
            }
        ]
    }, 
    "refer_resources": [
        {
            "id": "b6862a62-d916-11e9-bdf1-0255ac101fd9", 
            "type": "cce", 
            "parameters": {
                "namespace": "default"
            }
        }, 
        {
            "id": "8c0a45cc-626f-4d65-8257-507ee059aa9a", 
            "type": "elb"
        }
    ]
}

Example Response

{
    "instance_id": "89f5baf5-efe4-4f12-9c0d-734d2af5a184", 
    "job_id": "JOB66761060-f209-407c-a093-4df6f531b9dc"
}

Status Code

Table 28 Status codes

HTTP Status Code

Description

200

OK

400

Bad Request

404

Not Found

500

Internal Server Error

Error Code

The error code format is SVCSTG.00100.[Error_ID], for example, SVCSTG.00100400. For details, see ServiceStage Error Codes.