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

8/11/2021

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
-- DiegoBulhoes
amazon-eks
amazon-web-services
kubernetes

0 Answers