Reputation: 41
I am dynamically provisioning an EBS volume using the csi driver, I would like to add tags to help manage the volumes provisioned by K8S in the AWS console.
I managed to add tags to all provided disks by passing the tag in the driver installation link, using this strategy it adds to all disks, however, I would like to add tags to differentiate disks.
Example of tags you would like to add: version name, namespace or environment
The following are manifests based on the AWS documentation.
manifest - StorageClass:
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: ebs-sc
labels:
Name: ebs-claim
volumeBindingMode: WaitForFirstConsumer
provisioner: ebs.csi.aws.com
parameters:
type: "gp3"
fsType: "ext4"
manifest - PVC:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ebs-claim
labels:
Name: ebs-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: ebs-sc
resources:
requests:
storage: 4Gi
manifest - POD:
apiVersion: v1
kind: Pod
metadata:
name: app
labels:
Name: ebs-claim
spec:
containers:
- name: app
image: centos
command: ["/bin/sh"]
args: ["-c", "while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"]
volumeMounts:
- name: persistent-storage
mountPath: /data
volumes:
- name: persistent-storage
persistentVolumeClaim:
claimName: ebs-claim
Upvotes: 4
Views: 3774
Reputation: 2014
The AWS EBS CSI Driver supports tagging through StorageClass.parameters
starting from version 1.6.0
.
If a key has the prefix tagSpecification
, the CSI driver will treat the value as a key-value pair to be applied to the dynamically provisioned volume as tags. The CSI driver also supports runtime string interpolation on the tag values.
Example:
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: ebs-sc
provisioner: ebs.csi.aws.com
parameters:
tagSpecification_1: "key1=value1"
tagSpecification_2: "key2=hello world"
tagSpecification_3: "key3="
tagSpecification_4: 'backup={{ .PVCNamespace | contains "prod" }}'
tagSpecification_5: 'billingID={{ .PVCNamespace | field "-" 2 | toUpper }}'
NOTE: Interpolated tags require the --extra-create-metadata
flag to be enabled on the external-provisioner
sidecar.
For details see StorageClass Tagging.
Upvotes: 2
Reputation: 445
See the values.yaml
in the helm chart git repo:
You should set controller.k8sTagClusterId
and controller.extraVolumeTags
variables to tag the AWS EBS resources.
As far as you configure it, the name of the EBS will look like <EKS_NAME>-dynamic-pvc-<PVC_ID>
and all tags from controller.extraVolumeTags
will be there too.
Your values for helm chart should should looks like this:
controller:
k8sTagClusterId: my-eks-cluster-name
extraVolumeTags:
tag1: value1
tag2: value2
Upvotes: 1