如何删除或忽略挂载卷中不需要的 .snapshot?

How can I remove or ignore unwanted .snapshot in mounted volume?

我正在 运行使用 NFS NAStorage 连接一个 kubernetes 集群,当我挂载卷时,它们会在挂载点创建一个 .snapshot 目录。这会导致问题,例如在使用 Helm Charts 时,因为这些不期望某些路径中的未知只读目录(例如 chown ... <dir> 可能会失败,使容器崩溃)。

安装 Graylog Helm Chart 时,我注意到 graylog pod 的 initContainer 由于 chown: ... Read-only file system 在 运行 宁以下 chown 行之后崩溃:

chown -R 1100:1100 /usr/share/graylog/data/

安装以下卷的位置:

...
volumeMounts:
  - mountPath: /usr/share/graylog/data/journal
    name: journal
...

我尝试通过将命令修改为失败 "quietly" 来解决此问题,方法是在失败时将其设置为 运行 ::

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 目录,最好是 unmount/never 首先安装它的方法。那,或者任何让容器正确地完全忽略目录的方法,以使其不干扰容器中的进程,因为它的存在似乎会严重破坏。但是,我还没有找到任何类似的东西,而且我似乎找不到任何人遇到过类似的问题(至少可以说,在 kubernetes 中引入卷快照并没有使搜索变得更容易)。

编辑 1

我尝试(半成功,我得到上面的 Parent path ... is not a directory 错误)来实现 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 目录。如果其他人 运行 遇到类似问题,我将 post 我的发现和可能的潜在知识化。

如果有人想到一个更精简的解决方案,它仍然非常受欢迎 - 我相信可以改进这个。

在他们确定需要应用的配置后,我们终于让存储服务提供商解决了这个问题。如果有人运行遇到同样的问题,需要知道哪个配置,请联系我,我会询问我们的服务提供商。

在我们修复配置之前可行的解决方法如下: (包括--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
  • 中使用持久卷(在本例中为 name: journal)的所有 volumeMounts
...
        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

这可以在 vim 中通过键入 :g/name: <volume-name>/norm osubPath: mount 快速完成。 请注意 "o" 和 "subPath" 之间缺少 space,并注意这会将行添加到 volumeClaimTemplate,这需要即将被删除。 “mount”也可以叫别的名字。

  • 部署
$ kubectl apply -f graylog-template.yaml