Hi Welcome You can highlight texts in any article and it becomes audio news that you can hear
  • Sun. Nov 24th, 2024

How to Resize a Kubernetes StatefulSet’s Volumes

Byindianadmin

Oct 7, 2022
How to Resize a Kubernetes StatefulSet’s Volumes

Kubernetes StatefulSets are utilized to release stateful applications inside your cluster. Each Pod in the StatefulSet can access regional consistent volumes that adhere to it even after it’s rescheduled. This permits Pods to keep private state that’s different from their next-door neighbors in the set.

Unfortunately these volumes include a huge constraint: Kubernetes does not supply a method to resize them from the StatefulSet item. The spec.resources.requests.storage home of the StatefulSet’s volumeClaimTemplates field is immutable, avoiding you from using any capability increases you need. This post will reveal you how to workaround the issue.

Creating a StatefulSet

Copy this YAML and wait to ss.yaml:

 apiVersion:  v1 kind:  Service metadata:  name:  nginx labels:  app:  nginx specification:  selector:  app:  nginx ports:  - name:  nginx port: 80 clusterIP:  None-- apiVersion:  apps/v1 kind:  StatefulSet metadata:  name:  nginx specification:  selector:  matchLabels:  app:  nginx reproduction:  3 serviceName:  nginx design template:  metadata:  labels:  app:  nginx specification:  containers:  - name:  nginx image:  nginx: most current ports:  - name:  web containerPort: 80 volumeMounts:  - name:  information mountPath: / usr/share/nginx/ html volumeClaimTemplates:  - metadata:  name:  information specification:  accessModes: ["ReadWriteOnce"] resources:  demands:  storage:  1Gi

Apply the YAML to your cluster with Kubectl:

$ kubectl use -f ss.yaml
 
 service/nginx developed 
 statefulset.apps/ nginx produced

You’ll require a storage class and provisioner in your cluster to run this example. It develops a StatefulSet that runs 3 reproductions of an NGINX web server.

While this isn’t agent of when StatefulSets ought to be utilized, it’s appropriate as a demonstration of the volume issues you can deal with. A volume claim with 1 Gi of storage is installed to NGINX’s information directory site. Your web material might outgrow this reasonably little allowance as your service scales. Attempting to customize the volumeClaimTemplates.spec.resources.requests.storage field to 10 Gi will report the following mistake when you run kubectl use:

$ kubectl use -f ss.yaml
 
 service/nginx the same
 
 The StatefulSet" nginx" is void: specification: Forbidden: updates to statefulset specification for fields other than 'reproductions', 'design template', 'updateStrategy', 'persistentVolumeClaimRetentionPolicy' and 'minReadySeconds' are prohibited

This happens due to the fact that practically all the fields of a StatefulSet’s manifest are immutable after production.

Manually Resizing StatefulSet Volumes

You can bypass the limitation by manually resizing the consistent volume claim (PVC). You’ll then require to recreate the StatefulSet to launch and rebind the volume from your Pods. This will activate the real volume resize occasion.

First utilize Kubectl to discover the PVCs connected with your StatefulSet:

$ kubectl get pvc
 
 NAME STATUS VOLUME CAPACITY ACCESS MODES
 
 data-nginx-0 Bound pvc-ccb2c835- e2d3-4632- b8ba-4c8c142795 e4 1Gi RWO 
 
 data-nginx-1 Bound pvc-1b0b27 fe-3874 -4 ed5-91 be-d8e552 e515 f2 1Gi RWO 
 
 data-nginx-2 Bound pvc-4b7790 c2-3ae6-4e04- afee-a2e1bae4323 b 1Gi RWO

There are 3 PVCs due to the fact that there are 3 reproductions in the StatefulSet. Each Pod gets its own specific volume.

Now usage kubectl edit to change the capability of each volume:

$ kubectl edit pvc data-nginx-0

The PVC’s YAML manifest will appear in your editor. Discover the spec.resources.requests.storage field and alter it to your brand-new preferred capability:

 # ... specification:  resources:  demands:  storage: 10 Gi  # ...

Save and close the file. Kubectl must report that the modification has actually been used to your cluster.

 persistentvolumeclaim/data-nginx -0 modified

Now repeat these actions for the StatefulSet’s staying PVCs. Noting your cluster’s consistent volumes ought to then reveal the brand-new size versus every one:

$ kubectl get pv
 
 NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM 
 
 pvc-0a0d0b15-241 f-4332 -8 c34- a24 b61944 fb7 10 Gi RWO Delete Bound default/data-nginx -2
 
 pvc-33 af452 d-feff-429 d-80 cd-a45232 e700 c1 10 Gi RWO Delete Bound default/data-nginx -0
 
 pvc-49 f3a1c5-b780-4580 -9 eae-17 a1f002 e9f5 10 Gi RWO Delete

Read More

Click to listen highlighted text!