Search code examples
amazon-web-serviceskubernetesclouddevopsamazon-eks

How to use volume gp3 in storage class on EKS?


I'm converting volume gp2 to volume gp3 for EKS but getting this error.
Failed to provision volume with StorageClass "gp3": invalid AWS VolumeType "gp3"
This is my config.

StorageClass

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
  name: gp3
parameters:
  fsType: ext4
  type: gp3
provisioner: kubernetes.io/aws-ebs
reclaimPolicy: Retain
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer   

PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    app: test-pvc
  name: test-pvc
  namespace: default
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: gp3   

When I type kubectl describe pvc/test. This is response:

Name:          test-pvc
Namespace:     default
StorageClass:  gp3
Status:        Pending
Volume:        
Labels:        app=test-pvc
Annotations:   volume.beta.kubernetes.io/storage-provisioner: kubernetes.io/aws-ebs
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      
Access Modes:  
VolumeMode:    Filesystem
Used By:       <none>
Events:
  Type     Reason              Age                  From                         Message
  ----     ------              ----                 ----                         -------
  Warning  ProvisioningFailed  58s (x9 over 4m35s)  persistentvolume-controller  Failed to provision volume with StorageClass "gp3": invalid AWS VolumeType "gp3"   

I'm using Kubernetes version 1.18.
Can someone help me. Thanks!


Solution

  • I found the solution to use volume gp3 in storage class on EKS.

    1. First, you need to install Amazon EBS CSI driver with offical instruction here.
    2. The next, you need to create the storage class ebs-sc after Amazon EBS CSI driver is installed, example:

    cat << EOF | kubectl apply -f -
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: ebs-sc
    provisioner: ebs.csi.aws.com
    parameters:
      type: gp3
    reclaimPolicy: Retain
    volumeBindingMode: WaitForFirstConsumer
    EOF
    

    So, you can use volume gp3 in storage class on EKS.
    You can check by deploying resources:

    cat << EOF | kubectl apply -f -
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: ebs-gp3-claim
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
      storageClassName: ebs-sc
    ---
    apiVersion: v1
    kind: Pod
    metadata:
      name: app-gp3-in-tree
    spec:
      containers:
      - name: app
        image: nginx
        volumeMounts:
        - name: persistent-storage
          mountPath: /usr/share/nginx/html
      volumes:
      - name: persistent-storage
        persistentVolumeClaim:
          claimName: ebs-gp3-claim
    EOF
    

    Detailed documentation on Migrating Amazon EKS clusters from gp2 to gp3 EBS volumes: https://aws.amazon.com/vi/blogs/containers/migrating-amazon-eks-clusters-from-gp2-to-gp3-ebs-volumes/

    References: Persistent Storage in EKS failing to provision volume