Analyze Pod costs with custom tags
Tags are metadata that you can add to resources as key-value pairs to categorize and describe them. Container Compute Service (ACS) allows you to use annotations to bind custom Alibaba Cloud tags to Pods. This allows you to filter resources by tag for billing and cost analysis.
Background
Alibaba Cloud tags provide a flexible and customizable way to identify and categorize cloud resources. By tagging your cloud resources, you can manage and organize them more effectively. For more information, see What are tags?.
By default, Pods created by Container Compute Service (ACS) have the following tags:
|
System tag key |
Description |
|
acs:acc:cluster_id |
The cluster ID. |
|
acs:acc:cluster_name |
The cluster name. |
|
acs:acc:compute_class |
The instance type. |
|
User tag key |
Description |
|
ClusterId |
The cluster ID. |
|
NameSpace |
The namespace in the cluster. |
|
OwnerReferenceKind |
The workload type, such as Deployment or Job. |
|
OwnerReferenceName |
The name of the workload, such as the Deployment name or Job name. |
Currently, ACS supports configuring tags only for features such as cost analysis.
Configuration
You can bind up to five custom tags to an ACS Pod by using the alibabacloud.com/custom-tags annotation. Separate a tag key from its value with a colon (:), and separate multiple tags with a comma (,).
-
Add the annotation under the Pod's metadata. For example, when you create a Deployment, add the annotation under
spec.template.metadata. -
Custom tags take effect only when you add the annotation during the creation of an ACS Pod. Adding or modifying the annotation when updating an ACS Pod has no effect.
-
The key and value must comply with the tagging conventions.
-
Because the colon (
:) is used as a delimiter, it cannot be part of the key or value. -
Any content that does not conform to the key-value pair format is ignored.
Configuration example
The following example shows how to configure custom tags for Pods in a Deployment by using a YAML manifest.
-
Create a file named
nginx.yamlwith the following content.apiVersion: apps/v1 kind: Deployment metadata: name: nginx labels: app: nginx spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: name: nginx-test labels: app: nginx alibabacloud.com/compute-class: general-purpose alibabacloud.com/compute-qos: default annotations: alibabacloud.com/custom-tags: "<tag_key1>:<tag_value1>,<tag_key2>:<tag_value2>" #Bind custom tags spec: containers: - name: nginx image: registry.cn-hangzhou.aliyuncs.com/acs-sample/nginx:latest ports: - containerPort: 80The YAML above adds two tags,
<tag_key1>:<tag_value1>and<tag_key2>:<tag_value2>, to theannotationssection. Refer to Configuration instructions to add custom tag keys and values. -
Run the following command to view the Pod details. Replace
<Pod name>with the actual Pod name, such asnginx-789f4xxxxx-vnjxz.kubectl describe pod <Pod name> | grep -A 10 AnnotationsExpected output:
Annotations: ProviderCreate: done alibabacloud.com/client-token: edf29202-54ac-438e-9626-a1ca007xxxxx alibabacloud.com/custom-tags: <tag_key1>:<tag_value1>,<tag_key2>:<tag_value2> alibabacloud.com/instance-id: acs-2ze008giupcyaqbxxxxx alibabacloud.com/pod-ephemeral-storage: 30Gi alibabacloud.com/pod-use-spec: 0.25-0.5Gi alibabacloud.com/request-id: A0EF3BF3-37E7-5A07-AC2D-68A0CFCxxxxx alibabacloud.com/schedule-result: finished alibabacloud.com/user-id: 14889995898xxxxx kubernetes.io/pod-stream-port: 10250 kubernetes.io/preferred-scheduling-node: virtual-kubelet-cn-beijing-g/1As you can see, in
Annotations, the newly addedalibabacloud.com/custom-tagshas taken effect. -
Go to the Billing Management page to use the tags for cost analysis.
-
(Optional) Enable cost tags
Designate your custom tags as cost tags to use them for cost analysis.
-
Go to the Cost Tags page in Billing Management.
-
On the Cost Tags page, read the instructions and click Next.
-
Select the tags you want to use for cost allocation, and then click Next.
-
Click Confirm Enablement.
-
-
View cloud resources associated with cost tags
-
Go to the Cost Analysis page in Billing Management.
-
In the Filters pane on the right, click Tags.
-
Select the cost tags that you enabled, such as
<tag_key1>:<tag_value1>,<tag_key2>:<tag_value2>, to view their associated cost details. -
Click Apply Filters.
Note-
Cost Analysis supports selecting multiple tags. The relationship between multiple tags is a logical OR.
-
Tags added in the product console are synchronized to the cost tags list the next day (T+1).
-
If you determine a tag is no longer in use, you can choose not to enable it.
-
-
References
You can use tags to allocate the costs of your cloud resources. For more information, see Use tags for cost allocation.