How can I expand a PVC for Cassandra on AKS without losing data?

8/1/2021

I need to start by saying that I have no experience using Cassandra and I am not the one who who created this deployment.

I have Cassandra running in a cluster in AKS. The PVC as configured in the statefulset is 1000Gi. Currently the pods are out of storage and are in a constant unhealthy state.

I am looking to expand the volumes attached to the pods. The problem I am facing is that I cannot scale down the statefulset because the statefulsets only scale down when all their pods are healthy.

I even tried deleting the statefulset and then recreateing it with a larger PVC (as recomended here)

Howerver, I can't seem to delete the statefulset. It looks to me like the CassandraDatacenter CRD keeps recreating the statefulset as soon as I delete it. Giving me no time to change anything.

My question are as follows:

  1. Is there a standard way to expand the volume without losing data?
  2. What would happen if I scale down the replicas in the CassandraDatacenter? Will it delete the PVC or keep it?
  3. If there is no standard, does anyone have any ideas on how to accomplish expanding the volume size without losing storage?

    1: https://adamrushuk.github.io/increasing-the-volumeclaimtemplates-disk-size-in-a-statefulset-on-aks

-- yammering
azure-aks
cassandra
kubernetes
kubernetes-pvc
kubernetes-statefulset

2 Answers

8/1/2021

Ordinarily in a Cassandra cluster, the best practice is to scale horizontally (not vertically). You want more Cassandra nodes to spread the load out to achieve maximum throughput.

The equivalent in Kubernetes is to scale up your deployment. As you increase the node count, the amount of data on each individual Cassandra node will decrease proportionally.

If you really want to resize the PVC, you will only be able to do it dynamically if you have enabled allowVolumeExpansion. You won't lose data as you do this.

Deleting a STS isn't going to work because by design it will be automatically replaced as you already know. You also won't be able to scale down because there isn't enough capacity (disk space) in your cluster if you do. Cheers!

-- Erick Ramirez
Source: StackOverflow

2/18/2022

Answer for: How can I expand a PVC for StatefulSet on AKS without loosing data?

While the answer of @Erick Raminez is a very good advice for Cassandra specific, I would like to answers the more general question "How can I expand a PVC for my StatefulSet on AKS without loosing data?".

If downtime is allowed, you can follow these 4 steps:

# Delete StatefulSet 
# This is required on AKS since the azure disk must have status "Unattached" 
kubectl delete statefulsets.apps STATEFULSET_NAME

# Edit capacity in 
# - your statefulset yaml file
# - each pvc
kubectl patch pvc PVC_NAME -p '{"spec": {"resources": {"requests": {"storage": "3Gi"}}}}'

# Deploy updated statefulset yaml (or helm chart)
kubectl apply -f statefulset.yaml

# Verify Capacity
kubectl get pvc

If you don't want downtime, check the first reference for some additional steps.

References:

-- Dirc
Source: StackOverflow