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ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ