<p>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.</p>
<p>I managed to add tags to <strong>all</strong> provided disks by passing the tag in the driver installation <a href="https://github.com/kubernetes-sigs/aws-ebs-csi-driver/blob/master/charts/aws-ebs-csi-driver/values.yaml#L68" rel="nofollow noreferrer">link</a>, using this strategy it adds to all disks, however, I would like to add tags to differentiate disks.</p>
<p>Example of tags you would like to add: version name, namespace or environment</p>
<p>The following are manifests based on the AWS documentation.</p>
<p>manifest - StorageClass:</p>
<pre><code>kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: ebs-sc
  labels:
    Name: ebs-claim
volumeBindingMode: WaitForFirstConsumer
provisioner: ebs.csi.aws.com
parameters:
  type: &quot;gp3&quot;
  fsType: &quot;ext4&quot;
</code></pre>
<p>manifest - PVC:</p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ebs-claim
  labels:
    Name: ebs-claim
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: ebs-sc
  resources:
    requests:
      storage: 4Gi
</code></pre>
<p>manifest - POD:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: app
  labels:
    Name: ebs-claim
spec:
  containers:
    - name: app
      image: centos
      command: [&quot;/bin/sh&quot;]
      args: [&quot;-c&quot;, &quot;while true; do echo $(date -u) &gt;&gt; /data/out.txt; sleep 5; done&quot;]
      volumeMounts:
        - name: persistent-storage
          mountPath: /data
  volumes:
    - name: persistent-storage
      persistentVolumeClaim:
        claimName: ebs-claim
</code></pre>

DiegoBulhoes
<p>The AWS EBS CSI Driver supports tagging through <code>StorageClass.parameters</code> starting from v1.6.0.</p>
<p>If a key has the prefix <code>tagSpecification</code>, 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.</p>
<p>Example:</p>
<pre class="lang-yaml prettyprint-override"><code>kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: ebs-sc
provisioner: ebs.csi.aws.com
parameters:
  tagSpecification_1: &quot;key1=value1&quot;
  tagSpecification_2: &quot;key2=hello world&quot;
  tagSpecification_3: &quot;key3=&quot;
  tagSpecification_4: 'backup={{ .PVCNamespace | contains &quot;prod&quot; }}'
  tagSpecification_5: 'billingID={{ .PVCNamespace | field &quot;-&quot; 2 | toUpper }}'
</code></pre>
<p><strong>NOTE</strong>: Interpolated tags require the <code>--extra-create-metadata</code> flag to be enabled on the <code>external-provisioner</code> sidecar.</p>
<p>For details see <a href="https://github.com/kubernetes-sigs/aws-ebs-csi-driver/blob/master/docs/tagging.md#storageclass-tagging" rel="nofollow noreferrer">StorageClass Tagging</a>.</p>
