Attach a Persistent Volume Without knowing fileType and partition number in EKS

3

I have a EBS volume and EKS cluster. I want to attach the volume to a cluster's node programatically but I don't have information on disk's fsType and partition number. Is there any way to fetch the info or any plugin I can use which can mount all the partitions in the volume.

Here is the storage class and persistent Volume with aws csi driver. I have to know the fsType and partition number to mount correctly.

kind: PersistentVolume
metadata:
  name: name-pv
spec:
  storageClassName: "gp2"
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: "100Gi"
  volumeMode: Filesystem
  csi:
    driver: ebs.csi.aws.com
    fsType: <NotKnown>
    volumeHandle: "vol-XXXX"
    volumeAttributes:
      partition: "<NotKnown>"

---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  annotations:
    name: gp2
  parameters:
    fsType: <NotKnown>
    type: gp2
provisioner: kubernetes.io/aws-ebs
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
1 Answer
1
Accepted Answer

You can use the blockVolume feature of the AWS EBS CSI driver to attach the volume without knowing the file system type and partition number. This feature allows the EBS volume to be attached to the node as a block device without being formatted or mounted. You can then use tools such as lsblk or blkid to inspect the device and determine the file system type and partition number.

Here's an example of how to create a PersistentVolume and attach an EBS volume using the blockVolume feature:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-pv
spec:
  capacity:
    storage: 10Gi
  volumeMode: Block
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  csi:
    driver: ebs.csi.aws.com
    volumeHandle: vol-xxxxxx
    volumeAttributes:
      blockVolume: "true"

Once the volume is attached to the node, you can use the following commands to inspect the device and determine the file system type and partition number:

# List all available block devices
lsblk

# Determine the file system type
file -s /dev/xvdf

# Determine the partition table
fdisk -l /dev/xvdf

Note that the device name may vary depending on your setup, so adjust the commands accordingly. Once you have determined the file system type and partition number, you can update the PersistentVolume definition to include the correct values for fsType and partition.

Here are some useful links that provide more information about the AWS EBS CSI driver and attaching EBS volumes in Kubernetes:

profile pictureAWS
answered a year ago
profile pictureAWS
EXPERT
reviewed 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions