Updated on 2024-07-04 GMT+08:00

Namespace

Namespaces are used to logically divide your resources into different groups, especially in scenarios where a large number of users work across multiple projects.

Currently, CCI provides general-computing resources. When creating a namespace, you must choose a resource type so that workloads you create can run in the corresponding cluster.

  • General-computing: Pods with CPU resources can be created, which are ideal for general computing scenarios.
  • One account can create a maximum of five namespaces in one region.
  • General-computing resources support x86-based images.

Relationship Between Namespaces and Networks

Each namespace requires a separate subnet, as shown in Figure 1. When you create a namespace, you need to associate it with an existing VPC or a new VPC. If you create a VPC, create a subnet for the namespace. Containers and other resources created in this namespace will run in the VPC and subnet you select.

If you want to run resources of multiple services in the same VPC, you need to consider network planning, including subnet CIDR block division and IP address planning.

Figure 1 Relationship between namespaces and VPC subnets

Application Scenarios

Namespaces can implement partial environment isolation. If you have a large number of projects and personnel, you can create different namespaces based on project attributes, such as production, test, and development.

Creating a Namespace

  1. Log in to the CCI console. In the navigation pane on the left, choose Namespaces.
  2. On the page displayed on the right, click Create for the target namespace type.
  3. Enter a name for the namespace.

    The namespace name must be globally unique in CCI.

  4. Set RBAC policies.

    After RBAC is enabled, the access to resources in the namespace is controlled by the RBAC policies. For details, see Namespace Permissions.

  5. Select an enterprise project. In CCI, each namespace can belong to one enterprise project, but an enterprise project can have multiple namespaces.

    • Skip this step if Enterprise Project Management Service is not enabled. To enable the service, see Enabling Enterprise Center. If you are an IAM user, pay attention to the notice provided in (Optional) Uploading Images.
    • After you specify an enterprise project, both the namespace and the network and storage resources that are automatically created for the namespace belong to the enterprise project. You must migrate these resources together with the namespace. For example, when you migrate a namespace from project 1 to project 2, you must also migrate the associated network and storage resources to project 2, or the workloads in this namespace may not run normally.

  6. Configure a VPC.

    You can use an existing VPC or create a VPC. If you create a VPC, it is recommended that you set the VPC CIDR block to 10.0.0.0/8–22, 172.16.0.0/12–22, or 192.168.0.0/16–22.

    You must not set the VPC CIDR block and subnet CIDR block to 10.247.0.0/16, because this CIDR block is reserved for workload access. If you select this CIDR block, IP address conflicts may occur, which may result in failure to create a workload or service unavailability. If you do not need to access pods through workloads, you can select this CIDR block.

    After the namespace is created, you can view VPC and subnet information by choosing Network Management > Networks.

  7. Configure a subnet CIDR block.

    Ensure sufficient available IP addresses to create workloads.

    Figure 2 Configuring a subnet
    • Some IP addresses (10 by default) in the configured subnet will be warmed up for the created namespace.
    • You can set the number of IP addresses to be warmed up in 8.
    • Warming up IP addresses for the created namespace affects the deletion of the configured subnet and VPC. They can be deleted only after the namespace is deleted.

  8. Configure advanced settings.

    Each namespace provides an IP resource pool. You can customize the pool size to reduce the duration for applying for IP addresses and improve the workload creation efficiency.

    For example, 200 pods are running every day. During peak traffic hours, the IP resource pool instantly scales out to provide 500 IP addresses. After a specified interval (for example, 23 hours), the number of IP addresses that exceed the pool size (500 – 200 = 300) will be reclaimed.

    Figure 3 Configuring advanced settings
    • IP Pool Warm-up for Namespace: CCI creates an IP pool with the number of IP addresses you specify here for the namespace, and will warm up these IP addresses to accelerate workload creation. The IP pool can contain a maximum of 500 IP addresses.
    • IP Address Recycling Interval (h): Warmed-up IP addresses that become idle can be recycled within the duration that you specify here.
    • Container Network: Enable this option if you want CCI to start the container network in advance so that containers can connect to the network as soon as they are started.

  9. Click Create.

    After the creation is complete, you can view the VPC and subnet information on the namespace details page.

Deleting a Namespace

Deleting a namespace will remove all data resources related to the namespace, including workloads, ConfigMaps, secrets, and SSL certificates.

  1. Log in to the CCI console. In the navigation pane on the left, choose Namespaces. On the page displayed, click the namespace you want to delete.
  2. In the upper right corner, click Delete. In the dialog box that is displayed, enter DELETE and click Yes.

    To delete a VPC or subnet, go to the VPC console.

Creating a Namespace Using kubectl

For details, see Namespace and Network.