Difference between revisions of "Kubernetes PVC expansion: kubectl patch pvc"

From wikieduonline
Jump to navigation Jump to search
 
(29 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
Expand your pvc size.
  
  
 +
1) List your PVCs:
 +
[[kubectl get pvc -A]]
  
 +
NAMESPACE    NAME                                          STATUS  VOLUME                                    CAPACITY  ACCESS MODES  STORAGECLASS  AGE
 +
dev          elasticsearch-master-elasticsearch-master-0  Bound    pvc-25c6e973-8fc4-463b-9288-123456678903  30Gi      RWO            standard      2y234d
  
* <code>kubectl -n [[your-namespace]] patch pvc your-pvc-name -p '{"spec":{"resources":{"requests":{"storage":"16Gi"}}}}}'</code>
+
2) Review your StorageClass has AllowVolumeExpansion configured to true.
 +
[[kubectl describe sc standard]] | grep [[AllowVolumeExpansion]]
 +
[[AllowVolumeExpansion]]: True
  
 +
3) Request new size
 +
* <code>kubectl -n [[your-namespace]] [[kubectl patch|patch]] [[pvc]] your-pvc-name -p '{"spec":{"resources":{"requests":{"storage":"16Gi"}}}}'</code>
 +
 +
4) Verify it
 +
[[kubectl get pvc]] YOURPVC
 +
 +
 +
 +
== Outputs ==
 +
  kubectl -n yournamespace patch pvc yourstoragename -p '{"spec":{"resources":{"requests":
 +
{"storage":"1Gi"}}}}'
 +
The PersistentVolumeClaim "yourstoragename" is invalid:
 +
* spec: Forbidden: spec is immutable after creation except resources.requests for bound
 +
claims
 +
  core.PersistentVolumeClaimSpec{
 +
        AccessModes: {"ReadWriteOnce"},
 +
        Selector:    nil,
 +
        Resources: core.ResourceRequirements{
 +
                Limits: nil,
 +
-              Requests: core.ResourceList{
 +
-                      s"storage": {i: resource.int64Amount{value: 123456}, s: "1Gi",
 +
Format: "BinarySI"},
 +
-              },
 +
+              Requests: core.ResourceList{
 +
+                      s"storage": {i: resource.int64Amount{value: 123456}, s: "5Gi",
 +
Format: "BinarySI"},
 +
+              },
 +
        },
 +
        VolumeName:      "",
 +
        StorageClassName: &"yourclass",
 +
        ... // 3 identical fields
 +
  }
 +
 +
* spec.resources.requests.storage: Forbidden: field can not be less than previous value
  
 
== Related ==
 
== Related ==
* <code>[[kubectl patch]]</code>
+
* <code>[[kubectl get storageclass]]</code>
 +
* <code>[[kubectl patch pvc]]</code>
 +
* <code>FileSystemResizeSuccessful [[MountVolume.NodeExpandVolume]] succeeded for volume "pvc-678509b5-158b-11e9-8abc-1234567890"</code>
 +
* <code>[[The PersistentVolumeClaim XXX is invalid]]</code>
  
 +
== Activities ==
 +
* Read https://www.gooksu.com/2022/08/how-to-increase-space-for-your-elasticsearch-instances-in-k8s-on-eck/
 +
* Read https://www.percona.com/blog/percona-operator-volume-expansion-without-downtime/
  
 +
== See also ==
 
* {{PVC}}
 
* {{PVC}}
 +
* {{K8s storage}}
 +
 +
[[Category:K8s]]

Latest revision as of 12:56, 15 January 2024

Expand your pvc size.


1) List your PVCs:

kubectl get pvc -A
NAMESPACE    NAME                                          STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
dev          elasticsearch-master-elasticsearch-master-0   Bound    pvc-25c6e973-8fc4-463b-9288-123456678903   30Gi       RWO            standard       2y234d

2) Review your StorageClass has AllowVolumeExpansion configured to true.

kubectl describe sc standard | grep AllowVolumeExpansion
AllowVolumeExpansion:  True

3) Request new size

4) Verify it

kubectl get pvc YOURPVC


Outputs[edit]

 kubectl -n yournamespace patch pvc yourstoragename -p '{"spec":{"resources":{"requests": 
{"storage":"1Gi"}}}}' 
The PersistentVolumeClaim "yourstoragename" is invalid: 
* spec: Forbidden: spec is immutable after creation except resources.requests for bound 
claims
  core.PersistentVolumeClaimSpec{
        AccessModes: {"ReadWriteOnce"},
        Selector:    nil,
        Resources: core.ResourceRequirements{
                Limits: nil,
-               Requests: core.ResourceList{
-                       s"storage": {i: resource.int64Amount{value: 123456}, s: "1Gi", 
Format: "BinarySI"},
-               },
+               Requests: core.ResourceList{
+                       s"storage": {i: resource.int64Amount{value: 123456}, s: "5Gi", 
Format: "BinarySI"},
+               },
        },
        VolumeName:       "",
        StorageClassName: &"yourclass",
        ... // 3 identical fields
  } 

* spec.resources.requests.storage: Forbidden: field can not be less than previous value

Related[edit]

Activities[edit]

See also[edit]

Advertising: