{"id":1007,"date":"2024-09-27T15:21:05","date_gmt":"2024-09-27T15:21:05","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=1007"},"modified":"2024-09-27T15:21:05","modified_gmt":"2024-09-27T15:21:05","slug":"resize-volume-eks-cluster","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=1007","title":{"rendered":"How to Resize Persistent Volumes in AWS EKS Cluster"},"content":{"rendered":"<p>In this blog, you will learn how to resize the persistent volume in AWS EKS cluster by using a custom storage class with the <strong><code>allowVolumeExpansion<\/code><\/strong> parameter enabled.<\/p>\n<h2 id=\"using-default-storageclass\">Using Default StorageClass<\/h2>\n<p>In every <a href=\"https:\/\/devopscube.com\/create-aws-eks-cluster-eksctl\/\">EKS cluster<\/a>, there is default Storage class with <strong><code>allowVolumeExpansion<\/code><\/strong> false. Which means you cannot update a persistent volume with the default storage class.<\/p>\n<p>Lets look at the default storage class to understand more.<\/p>\n<p>Run the following command to get the default storageclass name.<\/p>\n<pre><code>kubectl get sc<\/code><\/pre>\n<p>The name of my default storage class is given below.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-299-1.png\" class=\"kg-image\" alt=\"getting the name of default storage class\" loading=\"lazy\" width=\"1806\" height=\"394\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-299-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-299-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-299-1.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-299-1.png 1806w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>As you can see in the default storage class, the <strong><code>allowVolumeExpansion<\/code><\/strong> parameter is set as false.<\/p>\n<p>If we try to resize the persistence volume, which uses the default storage class, we will get the below forbidden error.<\/p>\n<pre><code>error: persistentvolumeclaims \"expandable-pvc\" could not be patched: persistentvolumeclaims \"expandable-pvc\" is forbidden: only dynamically provisioned pvc can be resized and the storageclass that provisions the pvc must support resize\nYou can run `kubectl replace -f \/var\/folders\/w8\/zfm6dvnj5ng6cmpv61_nydh00000gn\/T\/kubectl-edit-57474951.yaml` to try this update again.<\/code><\/pre>\n<h2 id=\"using-custom-storageclass\">Using Custom StorageClass<\/h2>\n<p>Let&#8217;s try to expand a PVC that uses custom storageclass with <strong><code>allowVolumeExpansion<\/code><\/strong> parameter set as true.<\/p>\n<h3 id=\"step-1-create-custom-storageclass\">Step 1: Create Custom StorageClass<\/h3>\n<p>Now, let&#8217;s create a custom storage class and create the PVC with the custom storageclass.<\/p>\n<p>Create a YAML file <strong>sc.yaml<\/strong> and copy the below manifest file content<\/p>\n<pre><code>apiVersion: storage.k8s.io\/v1\nkind: StorageClass\nmetadata:\n  name: expandable-sc\nprovisioner: kubernetes.io\/aws-ebs\nparameters:\n  type: gp2\nallowVolumeExpansion: true<\/code><\/pre>\n<p>You can see in the above manifest file, the <strong><code>allowVolumeExpansion<\/code><\/strong> is set as true.<\/p>\n<p>The EBS volume type is set to <strong><code>gp2<\/code><\/strong>, if you want to use other volume types refer to this <a href=\"https:\/\/docs.aws.amazon.com\/ebs\/latest\/userguide\/ebs-volume-types.html?ref=devopscube.com\">guide<\/a>.<\/p>\n<p>Let&#8217;s create the PVC using the custom storageclass and try to expand the volume size.<\/p>\n<p>Run the following command to create the custom storageclass<\/p>\n<pre><code>kubectl apply -f sc.yaml<\/code><\/pre>\n<p>Now, run the below command to check if the storageclass is created<\/p>\n<pre><code>kubectl get sc<\/code><\/pre>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-303-1.png\" class=\"kg-image\" alt=\"listing the storage class\" loading=\"lazy\" width=\"1792\" height=\"532\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-303-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-303-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-303-1.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-303-1.png 1792w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>The custom storageclass <code>volumeBindingMode<\/code> is set as Immediate, which means the PVC will be created and bound with a PV immediately after it&#8217;s created.<\/p>\n<h3 id=\"step-2-create-pvc\">Step 2: Create PVC<\/h3>\n<p>Create a manifest file <strong>pvc.yaml<\/strong> and copy the below PVC manifest content<\/p>\n<pre><code>apiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n  name: expandable-pvc\nspec:\n  accessModes:\n    - ReadWriteOnce\n  volumeMode: Filesystem\n  resources:\n    requests:\n      storage: 1Gi\n  storageClassName: expandable-sc<\/code><\/pre>\n<p>You can see the storage requested is <strong><code>1Gi<\/code><\/strong>. Run the following command to create a PVC<\/p>\n<pre><code>kubectl apply -f pvc.yaml<\/code><\/pre>\n<p>Run the following command to check if the PVC is created.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-304-1.png\" class=\"kg-image\" alt=\"checking the status of pvc\" loading=\"lazy\" width=\"2000\" height=\"459\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-304-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-304-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-304-1.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-304-1.png 2032w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>As you can see, the PVC is in the bound state even without being claimed by a <a href=\"https:\/\/devopscube.com\/kubernetes-pod\/\">pod <\/a>because the custom storageclass we created has the <strong><code>volumeBindingMode<\/code><\/strong> as <strong><code>Immediate<\/code><\/strong>.<\/p>\n<h3 id=\"step-3-deploy-a-pod\">Step 3: Deploy a Pod<\/h3>\n<p>Now, create a manifest file <strong>pod.yaml<\/strong> and copy the below pod deployment manifest content<\/p>\n<pre><code>apiVersion: v1\nkind: Pod\nmetadata:\n  name: volume-test\nspec:\n  containers:\n  - name: volume-test\n    image: nginx\n    volumeMounts:\n    - name: expandable-storage\n      mountPath: \/data\n  volumes:\n  - name: expandable-storage\n    persistentVolumeClaim:\n      claimName: expandable-pvc<\/code><\/pre>\n<p>Run the following command to deploy the pod<\/p>\n<pre><code>kubectl apply -f pod.yaml<\/code><\/pre>\n<h3 id=\"step-4-expand-the-volume-size\">Step 4: Expand the Volume Size<\/h3>\n<p>Now, run the following command to edit the PVC to expand the volume size.<\/p>\n<pre><code>k edit pvc expandable-pvc<\/code><\/pre>\n<p>Then, change the storage request size to <strong><code>2Gi<\/code><\/strong> as shown below<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-305-1.png\" class=\"kg-image\" alt=\"editing the storage size in pvc yaml\" loading=\"lazy\" width=\"794\" height=\"458\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-305-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-305-1.png 794w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Save the changes and exit.<\/p>\n<p>Wait for some time, and the PV and PVC capacity will be increased, as shown below.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-306.png\" class=\"kg-image\" alt=\"checking the volume size of pvc and pv\" loading=\"lazy\" width=\"2000\" height=\"683\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-306.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-306.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-306.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-306.png 2312w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Now that the volume has been increased, it&#8217;s important to check if the filesystem&#8217;s size inside the pod has also increased.<\/p>\n<p>Run the following command to check whether the filesystem size is increased.<\/p>\n<pre><code>kubectl exec -it volume-test -- df -h \/data<\/code><\/pre>\n<p>You can see the filesystem size has been increased as well.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-307-1.png\" class=\"kg-image\" alt=\"checking if the filesystem size has been changed or not\" loading=\"lazy\" width=\"976\" height=\"444\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-307-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-307-1.png 976w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>In this blog, you have seen what happens if we change the volume size in the EKS cluster using the default storage class, which has <strong><code>allowVolumeExpansion<\/code><\/strong> parameter disabled.<\/p>\n<p>Also, you have learned how to expand a volume size using a custom storage class, which has <strong><code>allowVolumeExpansion<\/code><\/strong> parameter enabled.<\/p>\n<p>Also, resizing volume is one of the important topic in <a href=\"https:\/\/devopscube.com\/cka-exam-study-guide\/\">CKA certification<\/a>.<\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/resize-volume-eks-cluster\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to Resize Persistent Volumes in AWS EKS Cluster \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/resize-volume-eks-cluster\/<\/p>\n","protected":false},"author":1,"featured_media":1008,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1007","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/1007","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1007"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/1007\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/1008"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1007"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1007"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1007"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}