DEV Community

Cover image for Efficiently Scaling Disk Size in StatefulSet on EKS
Ahmed Zidan for AWS Community Builders

Posted on • Originally published at dailytask.co

Efficiently Scaling Disk Size in StatefulSet on EKS

Dealing with stateful set in k8s is one of the most challenges specially Dealing with stateful sets in Kubernetes, particularly when scaling persistence volume, presents several challenges. It's crucial to consider factors such as data maintenance, cost management, minimizing downtime, and establishing effective monitoring for the future.

Scaling Disk Size in a StatefulSet

Let's streamline the process of increasing the size of a Neo4j StatefulSet in an EKS cluster:

Note: The following steps will result in downtime, so ensure your business can accommodate this.

  1. Set/Ensure allowVolumeExpansion: true:
  • Edit your Storage class using the command:
kubectl edit storageClass gp2
Enter fullscreen mode Exit fullscreen mode
  • Add or confirm the presence of allowVolumeExpansion: true:
provisioner: kubernetes.io/aws-ebs
......
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
Enter fullscreen mode Exit fullscreen mode
  1. Delete your StatefulSet (STS):
kubectl delete sts --cascade=orphan neo4j-cluster
Enter fullscreen mode Exit fullscreen mode
  1. Edit your Persistent Volume Claim (PVC):
 kubectl edit pvc data-neo4j-cluster-0 
Enter fullscreen mode Exit fullscreen mode
  • Modify the spec to the desired size.
  1. Update your Helm Chart:
  • Adjust your Helm chart values.yaml to reflect the changes:
volumes:
  data:
    mode: defaultStorageClass
    defaultStorageClass:
      accessModes:
        - ReadWriteOnce
      requests:
        storage: 50Gi
Enter fullscreen mode Exit fullscreen mode
  1. Upgrade your Helm Chart:
helm upgrade --install neo4j-cluster neo4j/neo4j --namespace neo4j --values values.yaml --version v5.15.0
Enter fullscreen mode Exit fullscreen mode

Automation

I always look for the possibilities to automate the code so you can take all these steps and write a simple bash script which can do the job for you.

#!/usr/bin/env bash

kubectl delete sts STATEFULSET_NAME
kubectl patch pvc PVC_NAME -p '{"spec": {"resources": {"requests": {"storage": "50Gi"}}}}'
helm upgrade --install neo4j-cluster neo4j/neo4j --namespace neo4j --values values.yaml --version v5.15.0
kubectl get pvc
Enter fullscreen mode Exit fullscreen mode

For further insights or any questions, connect with me on:

Top comments (0)