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 年前檢視次數 577 次
1 個回答
1
已接受的答案

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
已回答 1 年前
profile pictureAWS
專家
已審閱 10 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南