Updated on 2026-09-15 GMT+08:00

Configuring Labels and Annotations

To support multi-dimensional metadata management, Kubernetes offers labels and annotations. They both attach metadata to resources in the format of key-value pairs, but their purposes and use cases differ significantly.

  • Labels are used for identifying and classifying Kubernetes objects. They follow a structured key-value format (for example, app=frontend) and can be used to efficiently select resources using selectors. They directly influence resource scheduling and management. The key and value of a label must comply with naming rules and typically represent persistent attributes of a resource, such as version.
  • Annotations serve to extend functionality and store additional metadata. They support flexible data formats (such as JSON or multi-line text). They are not used to select resources and do not influence scheduling.

Both labels and annotations apply to various Kubernetes resource types. This section will specifically examine their use in pods.

Pod Labels

Pod labels enable intelligent resource association. Once labels are added to pods, other Kubernetes resources can accurately identify and be associated with these pods using label selectors. Label keys and values must follow specific naming rules. For details, see Syntax and character set.

You can add labels to pods using either the console or YAML.

When creating or upgrading a workload on the CCE console, you can add labels to pods by clicking Labels and Annotations in the Advanced Settings area. These labels help identify the pods within the cluster. During the workload creation, CCE will add the labels shown in the figure below to the pods by default. The value of app is the workload name.

Figure 1 Pod labels

When creating or upgrading a workload, you can add labels to pods in the following area of the YAML file:

...
spec:
  selector:
    matchLabels:
      app: nginx
      version: v1
  template:
    metadata:
      labels:
        app: nginx
        version: v1
    spec:
      ...

Pod Annotations

CCE provides some advanced functions for pods. You can add annotations using the console or YAML to enable advanced functions.

When creating a workload on the console, you can add annotations to pods to enable advanced functions. In the Advanced Settings area, click Labels and Annotations and add annotations to pods.

For example, to add 14 GiB of ephemeral storage capacity for a pod, set Pod Annotation to resource.cce.io/extra-ephemeral-storage-in-GiB=14 and click Add.

Figure 2 Adding ephemeral storage capacity for a pod

When creating or upgrading a workload using YAML, you can use the annotations parameter to enable advanced pod functions.

For example, you can add 14 GiB ephemeral storage capacity for the pod through annotations.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx # Workload name
spec:
  replicas: 1 # Number of pods
  selector:
    matchLabels: # Selector for selecting resources with specific labels
      app: nginx  
  template:
    metadata:
      labels:     # Labels
        app: nginx
      annotations:
        resource.cce.io/extra-ephemeral-storage-in-GiB: '14'
    spec:
      containers:
      - image: nginx:latest   # {Image name}:{Image tag}
        name: nginx
      imagePullSecrets:
      - name: default-secret

Common Pod Annotations

Table 1 provides some common annotations. You can add annotations for pods as required.

Table 1 Pod annotations

Function and Reference

Annotation

Example Value

Description

Setting AZ Affinity

node.cce.io/node-az-list

cn-east-3a,cn-east-3b

Lists the AZs for pod affinity.

For a CCE Autopilot cluster, you can set workload annotations to implement AZ affinity and schedule pods to the specified AZs.

Increasing the Ephemeral Storage Space of a Pod

resource.cce.io/extra-ephemeral-storage-in-GiB

14

Indicates the extra ephemeral storage capacity for a pod, in GiB. The value ranges from 0 to 994.

Each pod can have 30-GiB free ephemeral storage and configurable extra storage.

NOTE:

This function is only supported in clusters v1.28.6-r0, v1.27.8-r0, and later.

Using an Image Cache

(Select either of the two parameters.)

imagecache.cce.io/specified-name

autopilot-test

Specifies the image cache. Enter the name of an available image cache. After the image cache is specified, the image information in the containers parameter must be the same as that in the image cache.

If the specified image cache does not exist or the required images are not found in the image cache, the image cache is no longer used. The cluster will download the images based on the image information in the containers parameter.

imagecache.cce.io/auto-match

true

Specifies whether to enable automatic image cache matching. The options are as follows:

  • true: This option is enabled.
  • false: This option is disabled by default.

After this option is enabled, the optimal images will be selected from all available image caches based on:

  • How much the images match the image caches: The images in the most matched image caches will be used.
  • Time when the image caches were created: The images in the latest image cache will be used.

If no images are matched in the image cache, the image cache is no longer used. In this case, the images in the SWR image repository and open-source images are matched in sequence based on the specified image name. If no images are matched, a message is returned indicating that images fail to be pulled.

Specifying the Pod Type

resource.cce.io/instance-type

general-computing-lite

Specifies the pod type. The options are as follows:

  • general-computing
  • general-computing-lite
NOTE:

This function is only supported in clusters v1.28.8-r0, v1.31.4-r0, and later.

Pod Resource Tags

You can add resource tags to classify pods.

  • Tags are only supported in clusters v1.28.10, v1.31.10, v1.32.6, and later.
  • Resource tags "CCE-Cluster-ID={cluster-ID}" and "CCE-Namespace={namespace-name}" added by CCE to pods cannot be deleted.
  • You can add custom tags to pods on the console or using YAML. You can add up to 15 custom tags to pods.

    You can create predefined tags on the TMS console. The predefined tags are available to all resources that support tags. You can use predefined tags to improve the tag creation and resource migration efficiency. For details, see Creating Predefined Tags.

    • A tag key can have a maximum of 128 characters and must not begin with _sys_. It can only contain letters, digits, spaces, and the following special characters: -_.:=+@. The key cannot be empty.
    • A tag value can have a maximum of 255 characters. It can only contain letters, digits, spaces, and the following special characters: -_.:/=+@. The value can be empty.

When creating or upgrading a workload on the console, you can add resource tags to pods. In the Advanced Settings area, choose Labels and Annotations > Pod Resource Tags and add resource tags.

When creating or upgrading a workload, you can add resource tags to pods in the following area of the YAML file:

...
spec:
  template:
    metadata:
      annotations:
        resource.cce.io/instance-type: general-computing
        pod.cce.io/tags: >-
          {"CCE-Cluster-ID":"c0751ce4-c043-11f0-8f3b-0255ac101784","CCE-Namespace":"monitoring","cce-ap-key001":"cce-ap-value1"}
      ...