Context: AWS only supports to increase EBS volume size. So, if we want to reduce EBS volume, we need to do it ourselves.
Basically, we need to create a new EBS volume with a smaller size and copy data from current EBS volume to a new one. However, we need to make sure there is no write operation to EBS volume (readonly mode) while we perform copy. In addition, there are lots of demandes to ask for assuring the environments available during business hours (so that other people can continue working) that make it difficult, especially while the operation takes time. In one case, in the past, we had increased an EBS volume for Jira to 1200GB. However, the space of Jira is occupied by backup files. After developing a cronjob to only keep backup files for a month, we realized that we could reduce the Jira EBS volume to 150 GB. But it takes sometime to copy such data if we need to perform it manually. So, instead we developed a pipeline in AzureDevOps to do it at night.
To be safe (if something goes wrong, we are able to restore completely), we create EBS snapshot before doing, then we create new EBS volume. After that, we copy tags (that makes sense in our case to keep same tags because our cluster works based on tags to make sure if it has permission to do any actions for an resources) and copy EBS data. When it’s done, we need to backup PVC and PV to S3 (so that we can restore it completely if Something goes wrong) and recreate PV (with new EBS volume) and PVC (with the newly created PV and new capacity). Here are some steps (I don’t put inputs for functions):
turnOfService
for pvc in "${pvcs[@]}"
do
new_size=?
pv=$(extractPV …)
ebsId=$(extractEbsId …)
az=$(extractAZ …)
newEbsId=$(createNewEbs …)
copyTags …
copyEbsData …
backupPvAndPvcToS3 …
recreatePvAndPvc …
done
turnOnService
Leave a Reply