custom tag on EBS volume provisioned dynamically by Kubernetes
Asked Answered
S

3

20

I'm dynamically provisioning a EBS Volume (Kubernetes on AWS through EKS) through PersistentVolumeClaim with a StorageClass

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: k8sebs
parameters:
  encrypted: "false"
  type: gp2
  zones: us-east-1a
provisioner: kubernetes.io/aws-ebs
reclaimPolicy: Delete
volumeBindingMode: Immediate 

PVC below

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: testk8sclaim
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: k8sebs
  resources:
    requests:
      storage: 1Gi

And pod that uses the volume:

kind: Pod
apiVersion: v1
metadata:
  name: mypod
spec:
  containers:
    - name: alpine
      image: alpine:3.2
      volumeMounts:
      - mountPath: "/var/k8svol"
        name: mypd
  volumes:
    - name: mypd
      persistentVolumeClaim:
        claimName: testk8sclaim

I need to tag the EBS volume with a custom tag.

Documentation mentions nothing about tagging for provisioner aws-ebs, storageclass or PVC. I've spent hours to try to add a tag to the dynamically provided EBS volume but not luck.

Is creating custom tags for EBS a possibility in this scenario and if it is how can it be achieved?

Thank you,

Greg

Stercoraceous answered 14/8, 2018 at 15:35 Comment(0)
S
9

Seems like at this point in time is not something possible yet.

Found these:

https://github.com/kubernetes/kubernetes/pull/49390

https://github.com/kubernetes/kubernetes/issues/50898

Hopefully something will be done soon.

Stercoraceous answered 31/8, 2018 at 15:20 Comment(3)
Update: see github.com/kubernetes-sigs/aws-ebs-csi-driver/issues/333 and github.com/kubernetes-sigs/aws-ebs-csi-driver/pull/353Plaza
@FernandoCorreia could you please share some examples like how to add tags custom tags.Severe
@DineshKumar If you are deploying the EBS CSI Driver using helm, this is how you would specify custom tags to be added to all volumes: helm --install aws-ebs-csi-driver --set 'extraVolumeTags.tagName=tagValue' aws-ebs-csi-driver/aws-ebs-csi-driverHaroldharolda
E
7

The current approach is to use the AWS EBS CSI Driver instead of the K8s intree provisioner: https://docs.aws.amazon.com/eks/latest/userguide/ebs-csi.html

If you use this new provisioner, you can add default tags using extraVolumeTags, or you can add tags for specific storage classes like so:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: "examplename" # MUST be lowercase!
parameters:
  csi.storage.k8s.io/fstype: ext4
  type: gp3
  tagSpecification_1: "ExampleKey=ExampleValue"
provisioner: ebs.csi.aws.com
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer

Docs: https://github.com/kubernetes-sigs/aws-ebs-csi-driver/blob/master/docs/tagging.md#storageclass-tagging

Elsy answered 28/6, 2021 at 14:55 Comment(0)
O
0

aws-ebs-csi-driver that you can install in EKS as an EKS addon support Volume Tagging.

When using ebs-csi-driver you can add aws tags to EBS volumes in two ways

  • via extraTags
  • via the StorageClass .parameters.tagSpecification_x,`
  • via the PersistentVolumeClaim .spec.volumeAttributesClassName

via StorageClass

As explained in 5, with the following StorageClass...

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: k8sebs
provisioner: ebs.csi.aws.com
parameters:
  tagSpecification_1: "Name={{ .PVCName }}"
  tagSpecification_2: "key2=hello world"

...you will get EBS volumes tagged with 2 tags Name=testk8sclaim and key2=hello world plus all the tags automatically added by aws-ebs-csi-driver like CSIVolumeName, CSIVolumeSnapshotName, ebs.csi.aws.com/cluster, kubernetes.io/cluster/xxxxx.

via PersistentVolumeClaim / VolumeAttributesClass

As explained in [6], with the following VolumeAttributesClass/ PersistentVolumeClaim...

---
apiVersion: storage.k8s.io/v1alpha1
kind: VolumeAttributesClass
metadata:
  name: io2-class
driverName: ebs.csi.aws.com
parameters:
  tagSpecification_1: "location=Seattle"
  tagSpecification_2: "cost-center=" // If the value is left blank, tag is created with an empty value
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: testk8sclaim
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: k8sebs
  volumeAttributesClassName: io2-class
  resources:
    requests:
      storage: 1Gi

Oldest answered 19/7 at 7:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.