Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(volume): Reclaim persistent volumes when the StatefulSet is deleted #88

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

jsirianni
Copy link
Member

@jsirianni jsirianni commented Feb 15, 2024

Description of Changes

When upgrading a StatefulSet to use a Prometheus sidecar, the StatefulSet needs to be deleted first. We need the volume reclaim settings to be set to "retain" to avoid dataloss. When the new StatefulSet is created, it will attach to the same volume and avoid dataloss.

You can learn more here: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#persistentvolumeclaim-retention

Testing

Start minikube: minikube start

Create the following values.yaml file.

config:
  username: bpuser
  password: bppass
  secret_key: 12D8FB6E-1532-4A4C-97AF-95A430BE5E6E
  sessions_secret: 4484766F-5016-4077-B8E0-0DE1D637854B
dev:
  collector:
    create: true

Deploy

helm template --values ./values.yaml charts/bindplane | kubectl apply -f -

Port forward and connect to the UI:

kubectl port-forward pod/release-name-bindplane-0 3011:3001 --address 0.0.0.0

http://localhost:3011

Create a config. You do not need to roll it out or anything, we just need a way to prove that we have not lost data.

With a config created, update the values file to include the Prometheus sidecar.

prometheus:
  enable: true
  enableSideCar: true
config:
  username: bpuser
  password: bppass
  secret_key: 12D8FB6E-1532-4A4C-97AF-95A430BE5E6E
  sessions_secret: 4484766F-5016-4077-B8E0-0DE1D637854B
dev:
  collector:
    create: true

If you re-deploy with helm, you will see this error:

The StatefulSet "release-name-bindplane" is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', 'updateStrategy', 'persistentVolumeClaimRetentionPolicy' and 'minReadySeconds' are forbidden

Delete the StatefulSet in order to re-create it.

kubectl delete sts release-name-bindplane
helm template --values ./values.yaml charts/bindplane | kubectl apply -f -

The bindplane pod should be re-created and contain two containers. Re-run the port forward command and check the UI for your configuration. If the configuration exists, we have not lost data despite deleting the StatefulSet.

Please check that the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • CI passes

@jsirianni jsirianni marked this pull request as ready for review February 15, 2024 21:18
@jsirianni jsirianni requested a review from a team as a code owner February 15, 2024 21:18
@jsirianni jsirianni requested review from cpheps and Mrod1598 February 15, 2024 21:18
Copy link
Contributor

@Mrod1598 Mrod1598 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM testing got expected outcome.

@jsirianni jsirianni merged commit 620a258 into main Feb 19, 2024
16 checks passed
@jsirianni jsirianni deleted the bindplane-sts-volume-reclaim branch February 19, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants