Creating a Network

Function

This API is used to create a network.

Network is a new object in CCI that defines the mapping relationship between a network of a namespace in Kubernetes, and a VPC and subnet. A network corresponds to a subnet in a VPC.

The container network of CCI depends on the bottom-layer VPC network. Before creating a network, you need to call the VPC API to create a subnet or query existing subnets.

The CIDR blocks of the VPC and subnet cannot be 10.247.0.0/16, which is the CIDR block reserved by CCI for services. If you use this CIDR block, IP address conflicts may occur, which may result in workload creation failures or service unavailability. If you do not need to access pods through services, you can allocate this CIDR block to a VPC.

The security group ID can be obtained from Security Groups on the network console, as shown in the following figure.
Figure 1 Obtaining the security group ID
The VPC ID, subnet ID, and network ID can be obtained from Virtual Private Cloud on the network console.
Figure 2 Obtaining the VPC ID
Figure 3 Obtaining the subnet ID and network ID

URI

POST /apis/networking.cci.io/v1beta1/namespaces/{namespace}/networks

Table 1 Path parameter

Parameter

Description

namespace

Object name and auth scope, such as for teams and projects.

Table 2 Query parameters

Parameter

Mandatory

Description

pretty

No

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

Request

Request parameters

Table 3 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. The value of this parameter is Network.

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 networking.cci.io.

metadata

Yes

Table 10

Standard object metadata.

For details about the annotations field, see Table 4.

The value of metadata.Namespace must be set to the namespace being operated.

spec

Yes

Table 5

Specification of the desired behavior of the Network.

status

No

Table 6

Most recently observed status of the Network.

Table 4 Data structure of the metadata.annotations field

Parameter

Mandatory

Type

Description

network.alpha.kubernetes.io/default-security-group

Yes

String

ID of the security group to which the subnet of the network belongs.

network.alpha.kubernetes.io/project-id

Yes

String

Project ID of the tenant that creates the network. To obtain the project ID, see Obtaining a Project ID.

network.alpha.kubernetes.io/domain-id

Yes

String

Domain ID of the tenant that creates the network. To obtain the project ID, see Obtaining an Account ID.

Table 5 Data structure of the spec field

Parameter

Mandatory

Type

Description

cidr

No

String

Network segment of the VPC subnet to which the network belongs.

NOTE:

The CIDR blocks of the VPC and subnet cannot be 10.247.0.0/16, which is the CIDR block reserved by CCI for services. If you use this CIDR block, IP address conflicts may occur, which may result in workload creation failures or service unavailability. If you do not need to access pods through services, you can allocate this CIDR block to a VPC.

attachedVPC

Yes

String

ID of the VPC to which the network belongs.

networkType

Yes

String

Network type. Currently, only the underlay_neutron network type is supported.

networkID

Yes

String

Network ID of the VPC subnet in which the network belongs.

subnetID

Yes

String

ID of the VPC subnet to which the network belongs.

availableZone

Yes

String

AZ to which the VPC subnet of the network belongs. Currently, the following regions are supported: CN North-Beijing 1, CN North-Beijing 4, and CN East-Shanghai 1. You can set this parameter to cn-north-1a, cn-north-4a, or cn-east-3a.

Table 6 Data structure of the status field

Parameter

Mandatory

Type

Description

state

No

String

Network status, which can be Initializing, Active, Pending, Failed, or Terminating.

Message

No

String

Reason why the network is in the current state.

Example request
{
    "apiVersion": "networking.cci.io/v1beta1",
    "kind": "Network",
    "metadata": {
        "annotations": {
            "network.alpha.kubernetes.io/default-security-group": "security-group-id",
            "network.alpha.kubernetes.io/domain-id": "domain-id",
            "network.alpha.kubernetes.io/project-id": "project-id"
        },
        "name": "test-network",
        "namespace": "test-ns"
    },
    "spec": {
        "availableZone": "cn-north-1a",
        "cidr": "192.168.0.0/24",
        "attachedVPC": "vpc-id",
        "networkID": "network-id",
        "networkType": "underlay_neutron",
        "subnetID": "subnet-id"
    }
}

Response

Response parameters

For the description about response parameters, see Table 3.

Example response

{
    "kind": "Network",
    "apiVersion": "networking.cci.io/v1beta1",
    "metadata": {
        "name": "test-network",
        "namespace": "test-ns",
        "selfLink": "/apis/networking.cci.io/v1beta1/namespaces/test-ns/networks/test-network",
        "uid": "f03452ac-a4ea-11e8-8500-c81fbe371a17",
        "resourceVersion": "2025736",
        "creationTimestamp": "2018-08-21T02:35:59Z",
        "annotations": {
            "network.alpha.kubernetes.io/default-security-group": "security-group-id",
            "network.alpha.kubernetes.io/domain-id": "domain-id",
            "network.alpha.kubernetes.io/project-id": "project-id",
            "network.alpha.kubernetes.io/type": "underlay_neutron"
        },
        "enable": true
    },
    "spec": {
        "availableZone": "cn-north-1a",
        "cidr": "192.168.0.0/24",
        "attachedVPC": "vpc-id",
        "networkID": "network-id",
        "networkType": "underlay_neutron",
        "subnetID": "subnet-id"
    },
    "status": {
        "state": "Initializing"
    }
}

Status Code

Table 7 Status code

Status Code

Description

201

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

For more status codes, see Status Codes.