前情提要
部署的架构可以看我之前的博客:k8s 使用 helm 文件部署 8.12.2 es 分角色集群,当时部署 master 角色的时候,没有给节点配置持久化,导致所有节点都下线后重新启动,data 节点无法加入集群,data 节点会有类似下面这样的报错(报错的内容非常的长,这里只截取关键的信息)
This node previously joined a cluster with UUID [n9CFoZ_yTi6zkdJcHq6ZbQ] and is now trying to join a different cluster with UUID [bGyuhfljQxyT5oEMrWH-aA]. This is forbidden and usually indicates an incorrect discovery or cluster bootstrapping configuration. Note that the cluster UUID persists across restarts and can only be changed by deleting the contents of the node's data paths [] which will also remove any data held by this node
- 报错的原因是 master 节点和 data 节点都需要做数据持久化,因为这两个角色都会保存集群元数据,可以看官方的 Node data path settings 里面写的
Every data and master-eligible node requires access to a data directory where shards and index and cluster metadata will be stored
解决方案
解决流程
- 停止所有 es 集群的服务
- 相关的依赖服务都要停止,比如 logstash,filebeat 这种 output 是 es 的,都需要停止
- 给 master 节点增加 pvc ,对数据目录增加持久化功能
- 新建一个 pod 挂载所有数据节点的 pvc
- 使用
elasticsearch-node detach-cluster
命令清除掉集群元数据(集群的_cluster/setting
也会被清除)- 使用
dangling api
还原本地磁盘的数据到 data 节点
实践过程
这里是拿自己的学习环境来模拟的,毕竟这种场景也是百分百复现的,也能完美做到数据脱敏的效果
停止 es 节点
- data 节点一定要停了,才可以操作
elasticsearch-node detach-cluster
命令,前面提到的上下游依赖,记得都停了,避免造成数据丢失- 下面是我环境的内容,大家替换成自己环境的相关信息,作用是把 statefulset 的副本数改为 0,让服务实现下线的场景(直接 yaml 来 delete 和 apply 是一件非常危险的事情,但凡有 edit 的操作没更新 yaml 的,重启之后就废了)
k scale sts -n es-logs es-cluster-data --replicas=0
master 节点增加数据持久化
这一步就不细致拆解了,参考我之前的 helm 部署博客,创建好 pv 和 pvc,然后把
persistence.enabled
配置成 true,然后执行helm upgrade xxx -f xxx
来更新 master 节点就可以了
新建 es-node-tools pod
- 利用