【问题标题】:How can I remove or ignore unwanted .snapshot in mounted volume?如何删除或忽略已安装卷中不需要的 .snapshot?
【发布时间】:2019-06-26 16:35:21
【问题描述】:

我正在运行一个带有 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”,为每个卷安装添加一行,添加

...
subPath: mount

或类似的东西。通过这样做,我应该将卷中的实际挂载点和实际挂载在容器中的目录分开一层,将 .snapshot 目录隐藏在抽象卷对象中。如果其他人遇到类似问题,我将发布我的发现和可能的定制化。

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

【问题讨论】:

  • 嗨,请分享您是如何创建共享卷存储的信息以及您使用的云提供商?
  • 您好,我添加了一些有关您要求的详细信息以及我对潜在解决方法的想法。干杯!
  • 你好,同样的问题,如果你解决了,你能帮我分享你的解决方案吗?谢谢!

标签: linux kubernetes snapshot graylog persistent-volumes


【解决方案1】:

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

在我们修复配置之前有效的解决方法如下: (包括--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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-17
    • 2021-06-13
    • 2019-02-06
    • 2020-03-08
    • 1970-01-01
    相关资源
    最近更新 更多