Creating a Namespace
Function
This API is used to create a namespace.
Currently, Cloud Container Instance (CCI) provides general-computing and GPU-accelerated resources. When creating a namespace, you must choose a resource type so that workloads you create can run in the corresponding cluster. When calling the API, set the namespace.kubernetes.io/flavor field in metadata.annotations as follows:
- general-computing: This type of namespaces provides basic computing, storage, and network resources, well suited to common workload scenarios.
- gpu-accelerated: This type of namespaces provides an outstanding graphics processing capability, applicable to high-performance computing scenarios, such as AI.
You must create a network under a namespace to define the mapping relationship between a network of a namespace in Kubernetes, and a Virtual Private Cloud (VPC) and subnet. For more information, see Creating a Network.
URI
POST /api/v1/namespaces
|
Parameter |
Mandatory |
Description |
|---|---|---|
|
pretty |
No |
If 'true', then the output is pretty printed. |
Request
Request parameters
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
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. The value of this parameter is Namespace. |
|
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. The value of this parameter is v1. |
|
metadata |
Yes |
Object |
Standard object metadata. For details, see Table 10. For details about the annotations and labels fields, see Table 3 and Table 4. |
|
spec |
No |
Object |
Spec defines the behavior of the Namespace. For details, see Table 5. |
|
status |
No |
Object |
Status describes the current status of a Namespace. For details, see Table 7. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
namespace.kubernetes.io/flavor |
Yes |
String |
Flavor of the cluster to which the namespace belongs. Currently, GPU-accelerated and general-computing clusters are supported. |
|
namespace.kubernetes.io/allowed-on-shared-node |
No |
String |
Whether to enable elastic scheduling. The value can be true or false. The default value is false. You do not need to set this parameter if elastic scheduling is not required. If elastic scheduling is enabled, on-demand pods can be automatically created when dedicated resources are used up. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
sys_enterprise_project_id |
No |
String |
ID of an enterprise project. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
finalizers |
No |
Array of objects |
Finalizers is an opaque list of values that must be empty to permanently remove object from storage. For details, see Table 6. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
phase |
No |
String |
Phase is the current lifecycle phase of the namespace. A namespace can be in the following states: - Active: The namespace is available for use in the system. - Terminating: The namespace is undergoing graceful termination. |
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "namespace-test",
"annotations": {
"namespace.kubernetes.io/flavor": "gpu-accelerated"
},
"labels": {
"sys_enterprise_project_id": "0503dda897000fed2f78c00909158a4d"
},
"spec": {
"finalizers": [
"kubernetes"
]
}
}
}
Response
Response parameters
For the description about response parameters, see Table 2.
|
Parameter |
Type |
Description |
|---|---|---|
|
pv.kubernetes.io/enable-dynamic-provisioning |
String |
Whether dynamic storage creation is supported. |
|
tenant.kubernetes.io/domain-id |
String |
Account ID. |
|
tenant.kubernetes.io/domain-name |
String |
Account name. |
|
tenant.kubernetes.io/project-id |
String |
Project ID. |
|
tenant.kubernetes.io/project-name |
String |
Project name. |
Example response
{
"metadata": {
"name": "namespace-test",
"selfLink": "/api/v1/namespaces/namespace-test",
"uid": "68a68c5a-af6b-11e8-8f17-c81fbe371a17",
"resourceVersion": "5016746",
"creationTimestamp": "2018-09-03T11:20:48Z",
"annotations": {
"namespace.kubernetes.io/flavor": "gpu-accelerated",
"pv.kubernetes.io/enable-dynamic-provisioning": "true",
"tenant.kubernetes.io/domain-id": "aadb43c0b14c4cafbccfff483d075987",
"tenant.kubernetes.io/domain-name": "cci",
"tenant.kubernetes.io/project-id": "51bf52609f2a49c68bfda3398817b376",
"tenant.kubernetes.io/project-name": "southchina"
},
"enable": true,
"labels": {
"sys_enterprise_project_id": "0503dda897000fed2f78c00909158a4d"
}
},
"spec": {
"finalizers": [
"kubernetes"
]
},
"status": {
"phase": "Active"
}
}
Status Code
Table 9 describes the status code of this API.
|
Status Code |
Description |
|---|---|
|
201 |
This operation succeeds, and a Namespace resource object is returned. |
For more status codes, see Status Codes.
Last Article: Namespace
Next Article: Reading a Namespace
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.