-
Notifications
You must be signed in to change notification settings - Fork 735
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
Do not remove PVC when removing Elasticsearch resource with Operator #2328
Comments
Since the reclaim policy is decided by the storage class, and you can specify the storage class for the PVCs, it is possible to retain volumes on scale down or delete. Can you go into more details on use cases when this is not sufficient? There's an upstream issue here for allowing ssets to delete PVCs as well (also linked in the original issue you mentioned): kubernetes/kubernetes#55045 (comment) |
In the documentation of StatefulSet they explicitly mention that one shouldn't rely on volumes:
When PVC gets removed and new PVC is created with same name it gets bound to a new volume, not the existing one. So in this case I cannot have Elasticsearch attached to existing data automatically. I use https://github.com/rancher/local-path-provisioner. |
Using I agree that it is hard to reuse a PV, even if the reclaim policy is set to |
I don't have any real examples with elastic operator yet, because I use it for only couple of days so far. I shared an example with mongodb operator when I wanted to convert sharded cluster to replica set (or vice versa) and preserve the data. Knowing that there is a replica set under the hood I expected same standard behavior from elastic operator as well when deleted the resource in my dev environment. Even though StatefulSet is an implementation detail, I would expect service deployed as a StatefulSet to deal with PVCs in standard way. I do agree that it is up to operator to decide, but if such decision deviates from expected default behavior of underlying building blocks and leads to a data loss (in case if resource removal), I would expect there to be a configuration option to chose such behavior. |
Sorry, accidentally closed the issue by pressing wrong button. One other reason can be to look from perspective on running Elasticsearch without any containers and orchestrators. As I cluster admin I don't expect to have my data deleted if I remove the service from the host operating system. It is up to me to decide when to delete the data or what to do with the data further on. |
@andrii-litvinov thanks for bringing that up. I can see how it would be useful for scaling down to 0 replicas. At this time that is not a use case we support though (and in fact explicitly prevent). If we do implement that then we will also have to revisit this discussion for PVCs, as well as the overall downscale logic. |
Well, it means that in case of some issue/bug or unexpected behavior I won't have an option to delete the Elasticsearch resource and recreate it without data loss or special handling, which is unfortunate. I know that it's an extreme scenario, but how will operator handle the case when someone accidentally removed the PVC of the first replica in StatefulSet? SatefulSet itself is not capable of recreating of PVC. Will Operator be able to handle such scenarios? |
The recommended path for deleting and recreating elasticsearch resources is using snapshots. The sset operator recreates PVCs, though not perfectly |
Using snapshots means copying terabytes of data, which is not instant. It means that in case if upgrade of operator 1.0-beta to newer version will require deletion and recreation of resources, some significant downtime will be required to restore the snapshot, which is not something desirable in production environment. I guess that's also not good enough argument. Well, let's see if others will come up with reasons not to delete PVCs. Maybe that's not a concern at all. |
From this issue #2308 (comment) there is one more case when removing and recreating Elasticsearch resource can be useful.
So keeping PVCs when removing StatefulSets will make resolution of such issues way easier instead of dealing with snapshots and trying to keep volumes and manually re-creating PVCs before SatefulSet creation. |
I just ran into the very same issue described here. |
Thanks folks for raising your concerns here. I think it's worth reopening and discussing options. As you point out @jgoeres, there are 2 different mechanisms in place to remove volumes:
We can technically add new optional fields to the Elasticsearch CRD, such as:
If I understand your use case correctly @jgoeres, you would like to use something similar to the first option. Is that correct? The volumeClaimTemplate section of StatefulSets is immutable, which means once we set an ownerReference there, we cannot remove it, and the other way around. Which means we need to make those settings immutable in the Elasticsearch spec. This is hard to achieve in Kubernetes. We can check this with the validation webhook, but this webhook may be disabled. There are corner cases to consider when PVCs are kept around:
|
@sebgl |
@andrii-litvinov @jgoeres we created a script that allows recreating an Elasticsearch cluster from its old Released PersistentVolumes: https://github.com/elastic/cloud-on-k8s/tree/master/hack/reattach-pv Could you take a look at it (the README especially)? I'm wondering if that would be good enough to cover your use case. |
Sorry for letting this topic sit idle for so long. I will give this script a try ASAP. |
I'd like to second this request. In our use case, we deploy Elasticsearch as part of a bigger system through a single Helm chart. All of the stateful components we use (RabbitMQ, Consul, Cassandra) follow the same practice of leaving PVCs behind on uninstall, which makes a lot of sense as we have a number of scenarios where we install and uninstall the system as part of our maintenance routines. All stateful components except Elasticsearch persist their data and that data is available the next time we deploy our system. The CRD addition of |
@sebgl I don't find any documentation about this. Thanks |
It does not exist (yet) at the moment. |
I was able to make PVCs remain after Elasticsearch is removed with the help of a KubeMod This makes the PVCs persist and their data is picked up and available in the next deployment of Elasticsearch as long as the Elasticsearch cluster's scale is not changed between deployments. apiVersion: api.kubemod.io/v1beta1
kind: ModRule
metadata:
name: elasticsearch-pvc-modrule
spec:
type: Patch
match:
- select: '$.kind'
matchValue: PersistentVolumeClaim
- select: '$.metadata.labels["common.k8s.elastic.co/type"]'
matchValue: elasticsearch
patch:
- op: remove
path: /metadata/ownerReferences/0 |
kubernetes/enhancements#2440 got merged to make it optional to automatically remove PVCs along with StatefulSets, or when StatefulSets are downscaled. It does not include a combination that would I think be valuable to us: remove PVCs on downscale (data has been migrated away from those volumes anyway), but preserve PVCs on deletion of the entire cluster. This would allow restoring a cluster with existing data later on. |
Relates to #1288. When removing Elasticsearch I don't necessary want to remove PVC, because it will lead to a data loss.
Expected behavior from k8s is to keep PVCs:
It may be convenient for development, but in production there will be scenarios when users would want to remove the Elasticsearch and reinstall it agaian. Maybe there will be issues with upgrading the Opeartor or other Elasticsearch resources to new version. I am working with MongoDB Operator and there are plenty of scenarios when I would want to keep PVCs, for example when I convert sharded cluster to a replica set. And it is also expected behavior for other k8s users who worked with StatfulSets before.
Here is an open issue with the discussion in k8s repository #55045. I would suggest leaving it up to a StatefulSet or at least introduce a flag whether to remove the PVCs or not. Or maybe make a decision about removing PVCs depending on there is it is scale-down or removal of a ReplicaSet.
The text was updated successfully, but these errors were encountered: