其他分享
首页 > 其他分享> > AWS EKS 如何调整 Persistent Volumes (EBS)大小

AWS EKS 如何调整 Persistent Volumes (EBS)大小

作者:互联网

在AWS EKS群集上,在编写本文时,默认情况下,无法调整使用默认gp2 StorageClass配置的卷的大小。这是因为在默认StorageClass上,allowVolumeExpansion设置为false,从而阻止卷扩展:

$ kubectl get sc
NAME            PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
gp2 (default)   kubernetes.io/aws-ebs   Delete          WaitForFirstConsumer   false                  78d

为了解决这个问题,我们可以检查默认定义中的allowVolumeExpansion设置是否存在:

$ kubectl get sc gp2 -o yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  (...)
  name: gp2
parameters:
  fsType: ext4
  type: gp2
provisioner: kubernetes.io/aws-ebs
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer

为了能够修改此StorageClass,我们可以使用kubectl patch命令,如下所示:

$ kubectl patch sc gp2 -p '{"allowVolumeExpansion": true}'
storageclass.storage.k8s.io/gp2 patched

此设置将告诉Kubernetes CSI可以调整基础卷(EBS volume)的大小。使用kubectl get sc,我们可以看到ALLOWVOLUMEEXPANSION更改为true:

$ kubectl get sc 
NAME            PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
gp2 (default)   kubernetes.io/aws-ebs   Delete          WaitForFirstConsumer   true                   78d

我们可以使用kubectl get pv查看卷的当前大小,或者通过使用df简单地检查pod上的卷大小:

$ kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                          STORAGECLASS   REASON   AGE
pvc-a1448f38-5f28-492e-a09c-8a900b9fb43e   35Gi       RWO            Delete           Bound    pet2cattle/pet2cattle-static   gp2                     9d6h
$ kubectl exec -it pet2cattle-79979695b-7rmg6 -- df -hP
Filesystem      Size  Used Avail Use% Mounted on
overlay          20G   11G  9.5G  53% /
tmpfs            64M     0   64M   0% /dev
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/xvda1       20G   11G  9.5G  53% /tmp
shm              64M     0   64M   0% /dev/shm
/dev/xvdbg       35G  1.3G   34G   4% /opt/pet2cattle/static
tmpfs           3.9G   12K  3.9G   1% /run/secrets/kubernetes.io/serviceaccount
tmpfs           3.9G     0  3.9G   0% /proc/acpi
tmpfs           3.9G     0  3.9G   0% /proc/scsi
tmpfs           3.9G     0  3.9G   0% /sys/firmware

请记住,在容器上识别带有linux挂载的VolumeMounts可能是一项复杂的任务。
最后,要调整卷的大小,我们可以将存储属性更改为要调整其大小的新大小:

$ kubectl get pvc pet2cattle-data -o yaml | sed 's/storage: 35Gi/storage: 40Gi/g' | kubectl apply -f -
persistentvolumeclaim/pet2cattle-data configured

CSI可能需要一段时间来进行更改,但最终我们将能够看到卷的大小被修改
请注意AWS eks 修改 storage 大小,每6小时可以修改一次,不可以频繁修改

$ kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                          STORAGECLASS   REASON   AGE
pvc-a1448f38-5f28-492e-a09c-8a900b9fb43e   40Gi       RWO            Delete           Bound    pet2cattle/pet2cattle-static   gp2                     9d6h
$ kubectl exec -it pet2cattle-79979695b-7rmg6 -- df -hP
Filesystem      Size  Used Avail Use% Mounted on
overlay          20G   11G  9.5G  53% /
tmpfs            64M     0   64M   0% /dev
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/xvda1       20G   11G  9.5G  53% /tmp
shm              64M     0   64M   0% /dev/shm
/dev/xvdbg       40G  1.3G   38G   4% /opt/pet2cattle/static
tmpfs           3.9G   12K  3.9G   1% /run/secrets/kubernetes.io/serviceaccount
tmpfs           3.9G     0  3.9G   0% /proc/acpi
tmpfs           3.9G     0  3.9G   0% /proc/scsi
tmpfs           3.9G     0  3.9G   0% /sys/firmware

标签:kubectl,AWS,Persistent,Volumes,0%,tmpfs,pet2cattle,gp2,3.9
来源: https://www.cnblogs.com/faberbeta/p/16646655.html