Updated on 2024-12-18 GMT+08:00

Managing Namespaces

Using Namespaces

  • When creating a workload, you can select a namespace to isolate resources or users.
  • When querying workloads, you can select a namespace to view all workloads in the namespace.

Isolating Namespaces

  • Isolating namespaces by environment

    An application generally goes through the development, joint debugging, and testing stages before it is launched. In this process, the workloads deployed in each environment (stage) are the same, but are logically defined. There are two ways to define them:

    • Group them in different clusters for different environments.

      Resources cannot be shared among different clusters. In addition, services in different environments can access each other only through load balancing.

    • Group them in different namespaces for different environments.

      Workloads in the same namespace can be mutually accessed by using the Service name. Cross-namespace access can be implemented by using the Service name or namespace name.

      The following figure shows namespaces created for the development, joint debugging, and testing environments, respectively.

      Figure 1 One namespace for one environment
  • Isolating namespaces by application

    You are advised to use this method if a large number of workloads are deployed in the same environment. For example, in the following figure, different namespaces (APP1 and APP2) are created to logically manage workloads as different groups. Workloads in the same namespace access each other using the Service name, and workloads in different namespaces access each other using the Service name or namespace name.

    Figure 2 Grouping workloads into different namespaces

Managing Namespace Labels

  1. Log in to the CCE console and click the cluster name to access the cluster console. In the navigation pane on the left, choose Namespaces.
  2. Locate the row containing the target namespace and choose More > Manage Label in the Operation column.
  3. In the dialog box that is displayed, the existing labels of the namespace are displayed. Modify the labels as needed.

    • Adding a label: Click the add icon, enter the key and value of the label to be added, and click OK.

      For example, the key is project and the value is cicd, indicating that the namespace is used to deploy CICD.

    • Deleting a label: Click next the label to be deleted and then OK.
    Figure 3 Adding or deleting a namespace label

  4. Switch to the Manage Label dialog box again and check the modified labels.

Deleting a Namespace

If a namespace is deleted, all resources (such as workloads, jobs, and ConfigMaps) in this namespace will also be deleted. Exercise caution when deleting a namespace.

  1. Log in to the CCE console and click the cluster name to access the cluster console.
  2. In the navigation pane on the left, choose Namespaces. Locate the target namespace and choose More > Delete in the Operation column.

    Follow the prompts to delete the namespace. The default namespaces cannot be deleted.