A tag is a key-value pair that you can use to identify elastic container instances. You can use tags to manage elastic container instances by group and perform searches and batch operations. This topic describes how to bind custom tags to a pod. After you bind custom tags to a pod, you can manage the pod based on the tags. For example, you can analyze costs of the pod based on tags.
Background information
A tag is a key-value pair. A tag is similar to a label in terms of features. Alibaba Cloud tags identify cloud resources and allow you to manage cloud resources by category. By default, the elastic container instances that are created by using Container Service for Kubernetes(ACK) have the following tags bound:
-
ManagedBy: The cluster type.
-
ClusterId: The cluster ID.
-
NameSpace: The namespace of the cluster.
-
OwnerReferenceKind: The workload type created in the cluster, such as Deployment or Job.
-
OwnerReferenceName: The workload name created in the cluster, such as a Deployment name or a Job name.
-
PodName: The pod name.
Configurations
You can add the k8s.aliyun.com/eci-custom-tags annotation to a pod to bind custom tags to the pod. Up to three tags can be bound to a pod. Separate a tag key and a tag value with a colon (:). Separate multiple tags with commas (,).
Annotations must be added to the metadata in the configuration file of the pod. For example, when you create a Deployment, you must add annotations in the spec.template.metadata section.
Elastic Container Instance-related annotations are only applied when a pod is created. Adding or modifying these annotations on an existing pod will have no effect.
Sample configurations:
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
labels:
app: test
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
name: nginx-test
labels:
app: nginx
alibabacloud.com/eci: "true"
annotations:
k8s.aliyun.com/eci-custom-tags: "env:test,name:alice" # Apply custom tags
spec:
containers:
- name: nginx
image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
ports:
- containerPort: 80
After you use the annotation to bind tags, you can run the kubectl describe command to query the details of the pod. The custom tags are displayed as the values of k8s.aliyun.com/eci-custom-tags in the Annotations section.
~$ kubectl get pod
NAME READY STATUS RESTARTS AGE
test-555f6995c6-jrmtl 1/1 Running 0 31m
test-555f6995c6-tqjjk 1/1 Running 0 31m
~$ kubectl describe pod test-555f6995c6-jrmtl
Name: test-555f6995c6-jrmtl
Namespace: default
Priority: 0
Node: virtual-kubelet-cn-beijing-k/172.16.xxx.xxx
Start Time: Tue, 22 Nov 2022 02:49:42 +0000
Labels: alibabacloud.com/eci=true
app=nginx
pod-template-hash=555f6995c6
Annotations: ProviderCreate: done
k8s.aliyun.com/cluster-dns:
k8s.aliyun.com/cluster-domain: cluster.local
k8s.aliyun.com/eci-client-token: bbb1a0f7-ad20-440c-a95c-00d9c064f4bc
k8s.aliyun.com/eci-created-by-template: true
k8s.aliyun.com/eci-custom-tags: env:test,name:alice
k8s.aliyun.com/eci-drop-apiserver-interactive-caps:
k8s.aliyun.com/eci-instance-cpu: 2.0
To view the ECI pod's tags directly, go to the Container Group page of the Elastic Container Instance console.