Add custom tag in dynamically provisioned EBS using aws-ebs-csi-driver

Viewed 741

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
1 Answers

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
Related