Updated on 2024-05-28 GMT+08:00

Managing Namespaces

A namespace is a collection of resources and objects. Multiple namespaces can be created in a single CCE cluster with the data isolated from each other. This enables namespaces to share the services of the same cluster without affecting each other.

For example, you can deploy workloads in a development environment into one namespace, and deploy workloads in a testing environment into another namespace.

Table 1 describes the namespace types.

Table 1 Namespace types

Creation Type

Description

Created by a cluster by default

When a cluster is started, the default, kube-public, kube-system, and kube-node-lease namespaces are created by default.

  • default: All objects for which no namespace is specified are allocated to this namespace.
  • kube-public: Resources in this namespace can be accessed by all users (including unauthenticated users), such as public add-ons and container charts.
  • kube-system: All resources created by Kubernetes are in this namespace.
  • kube-node-lease: Each node has an associated Lease object in this namespace. The object is periodically updated by the node.

Created manually

You can create namespaces to serve separate purposes. For example, you can create three namespaces, one for a development environment, one for joint debugging environment, and one for testing environment. You can also create one namespace for login services and one for game services.

This section describes how to create and delete a namespace, and manage namespace resource quotas.

Prerequisites

A CCE cluster has been bound to the environment. For details, see Binding a CCE Cluster.

Creating a Namespace

  1. Log in to ServiceStage.
  2. On the Environment Management page, click the target environment.
  3. In the Resource Settings area, choose Cloud Container Engine from Compute.
  4. Click Namespace > Create Namespace.
  5. Set the parameters by referring to the following table. Parameters marked with an asterisk (*) are mandatory.

    Parameter

    Description

    *Namespace

    Namespace name.

    Namespace description

    Description about the namespace.

    Figure 1 Setting namespace parameters

  6. Click OK.

    The created namespace is displayed in the namespace list.

Deleting a Namespace

  • If a namespace is deleted, all resources (such as workloads and configuration items) in this namespace will be also deleted. Exercise caution when deleting a namespace.
  • The cluster-created namespace default cannot be deleted.
  1. Log in to ServiceStage.
  2. On the Environment Management page, click the target environment.
  3. In the Resource Settings area, choose Cloud Container Engine from Compute.
  4. Click the Namespace tab.

    • To delete a single namespace, locate the target namespace and click Delete in the Operation column.
      Figure 2 Deleting a single namespace
    • To delete namespaces in batches, select the target namespaces and click Delete above the namespaces.
      Figure 3 Deleting namespaces in batches

  5. In the displayed dialog box, enter DELETE and click OK.

Managing Namespace Resource Quotas

By default, pods running in a CCE cluster can use the CPUs and memory of a node without restrictions. This means that pods in a namespace may exhaust all resources of the cluster.

Kubernetes provides namespaces for you to group workloads in a cluster. By setting resource quotas for each namespace, you can prevent resource exhaustion and ensure cluster reliability. You can configure quotas for resources such as CPU, memory, and the number of pods in a namespace. For more information, see Resource Quotas.

User-created namespaces and the cluster-created namespace default support resource quota management.

  1. Log in to ServiceStage.
  2. On the Environment Management page, click the target environment.
  3. In the Resource Settings area, choose Cloud Container Engine from Compute.
  4. Click the Namespace tab.
  5. Locate the target namespace and click Resource Quota Manager in the Operation column.

    In the displayed Resource Quota Manager dialog box, view the resource types, total resource quotas, and accumulated quota usage in the namespace.
    Figure 4 Accessing the Resource Quota Manager page

  6. Click Edit Quota and set the total quota of each resource type.

    • If the usage of a resource type is not limited, enter 0.
    • If the usage of a resource type is limited, enter the expected integer.
      • Accumulated quota usage includes the resources used by CCE to create default components, such as the Kubernetes Services (which can be viewed using kubectl) created under the default namespace. Therefore, you are advised to set a resource quota greater than expected to reserve resource for creating default components.
      • If the total CPU or memory quota in a namespace is limited, you must set the maximum and minimum number of CPU cores and memory (GiB) that can be used by the component when setting resources for the Kubernetes component of this namespace in Creating and Deploying a Component and Upgrading a Single Component. Otherwise, the operation will fail.
      • If the total quota of other resource types in a namespace is limited and the remaining usage of this resource type does not meet requirements, the Kubernetes component of this namespace will fail to be deployed.

  7. Click OK.