如何删除或忽略已安装卷中不需要的 .snapshot?
回答问题
我正在使用 NFS NAStorage 运行 kubernetes 集群,当我挂载卷时,它们会在挂载点创建一个 .snapshot 目录。这会导致问题,例如在使用 Helm Charts 时,因为这些图表不会期望某些路径中存在未知的只读目录(例如chown ... <dir>可能会失败,从而导致容器崩溃)。
在安装Graylog Helm Chart时,我注意到在运行以下chown行后,由于chown: ... Read-only file system导致 graylog pod 的 initContainer 崩溃:
chown -R 1100:1100 /usr/share/graylog/data/
安装以下卷的位置:
...
volumeMounts:
- mountPath: /usr/share/graylog/data/journal
name: journal
...
我尝试通过修改命令以“安静地”失败来解决这个问题,方法是让它在失败时运行::
chown -fR 1100:1100 /usr/share/graylog/data/ || :
这使得 initContainer 成功,但现在主容器崩溃了,这一次仅仅是因为 .snapshot 目录的存在。
...
kafka.common.KafkaException: Found directory /usr/share/graylog/data/journal/.snapshot, '.snapshot' is not in the form of topic-partition
If a directory does not contain Kafka topic data it should not exist in Kafka's log directory
...
我也尝试过修改卷的挂载点,将其上移一级,但这会导致新问题:
...
volumeMounts:
- mountPath: /usr/share/graylog/data
name: data-journal
...
com.github.joschi.jadconfig.ValidationException: Parent path /usr/share/graylog/data/journal for Node ID file at /usr/share/graylog/data/journal/node-id is not a directory
我本来希望有某种方法可以禁用 .snapshot 目录的创建,理想情况下是一种卸载/从不安装它的方法。那,或者让容器完全忽略目录的任何方式,使其不会干扰容器中的进程,因为它的存在似乎会严重破坏。但是,我还没有找到任何类似的东西,而且我似乎找不到任何人遇到过类似的问题(至少可以说,在 kubernetes 中引入卷快照并没有使搜索变得更容易)。
编辑 1
我尝试(半成功,我得到上面的Parent path ... is not a directoryerror)来实现subPath: journal,从而绕过 .snapshot 目录(或者我相信),但这仍然意味着可能编辑集群中使用的每个图表。希望可以找到更高级别的替代方案。
volumeMounts:
- mountPath: /usr/share/graylog/data/journal
name: data-journal
subPath: journal
编辑 2
我正在运行一个裸机集群,使用 MetalLB 和 Nginx 作为负载均衡器+入口控制器。存储解决方案由第三方提供商提供,.snapshot 目录是根据他们的备份解决方案制作的。
我想象的解决方法
由于这主要是在使用 Helm Charts 或其他部署时卷安装或多或少超出我们控制的问题,因此我将研究应用“kustomization”,为每个volumeMount添加一行,添加
...
subPath: mount
或类似的东西。通过这样做,我应该将卷中的实际挂载点和实际挂载在容器中的目录分开一层,并将 .snapshot 目录隐藏在抽象卷对象中。如果其他人遇到类似问题,我将发布我的发现和可能产生的潜在定制化。
如果有人想到一个更简化的解决方案,它仍然非常受欢迎 - 我相信可以改进这个解决方案。
Answers
在他们确定需要应用哪个配置之后,我们终于让存储服务提供商解决了这个问题。如果有人遇到同样的问题并且需要知道哪种配置,请联系我们,我会询问我们的服务提供商。
在我们修复配置之前有效的解决方法如下:(包括--namespace是可选的)
- 安装 mongodb-replicaset 和 elasticsearch (v 6.8.1)
$ helm install --name mongodb-replicaset --namespace graylog stable/mongodb-replicaset
# We add the elastic repo since the 'stable' repo will be deprecated further on
$ helm repo add elastic https://helm.elastic.co
# We run elasticsearch version 6.8.1 since Graylog v3 currently is incompatible with later versions.
$ helm install elastic/elasticsearch --name elasticsearch --namespace graylog --set imageTag=6.8.1
# Wait for deployments to complete, then you can test to see all went well
$ helm test mongodb-replicaset
$ helm test elasticsearch
- Extraxt Graylog 部署模板
$ helm fetch --untar stable/graylog
$ helm dependency update graylog
$ helm template graylog -n graylog -f graylog-values.yaml > graylog-template.yaml
#graylog-values.yaml
tags:
install-mongodb: false
install-elasticsearch: false
graylog:
mongodb:
uri: "mongodb://mongodb-replicaset-0.mongodb-replicaset.graylog.svc.cluster.local:27017/graylog?replicaSet=rs0"
elasticsearch:
hosts: "http://elasticsearch-client.graylog.svc.cluster.local:9200"
# + any further values
-
将
namespace: graylog添加到graylog-template.yaml中的所有对象 -
将
subPath: mount添加到graylog-template.yaml中使用持久卷的所有volumeMounts(在本例中为name: journal)
...
volumeMounts:
- mountPath: /usr/share/graylog/data/journal
name: journal
+ subPath: mount
...
volumeMounts:
- mountPath: /usr/share/graylog/data/journal
name: journal
+ subPath: mount
...
volumeClaimTemplates:
- metadata:
creationTimestamp: null
name: journal
这可以通过键入:g/name: <volume-name>/norm osubPath: mount在 vim 中快速完成。 请注意“o”和“subPath”之间缺少空格,并注意这会将行添加到volumeClaimTemplate,需要删除。 “mount”也可以叫别的东西。
- 部署
$ kubectl apply -f graylog-template.yaml
更多推荐
所有评论(0)