Kubernetes configmap 和数据在同一个目录下

时间:2021-01-19 20:25:27

标签: kubernetes configmap syncthing

我试图让 syncthing 在 kubernetes 中运行,我发现了 subPath,因为我想操作 /var/syncthing/config/config.xml 中的文件。然而,syncthing 还想在这个目录中存储其他东西,它似乎是在启动时创建的。

这里是一些简化的配置:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: syncthing
  namespace: network-daemons
spec:
  ...
  spec:
    containers:
      - name: syncthing
        image: syncthing/syncthing
        ...
        volumeMounts:
          - name: syncthing-config-volume
            mountPath: /var/syncthing/config/config.xml
            subPath: config.xml
    volumes:
      - name: syncthing-config-volume
        configMap:
          name: syncthing-config
          items:
            - key: config.xml
              path: config.xml
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: syncthing-config
  namespace: network-daemons
data:
  config.xml: |
    <configuration version="26">
      <folder></folder>
      <device></device>
      <gui enabled="true" tls="false" debugging="false">
        <address>0.0.0.0:8384</address>
      <options></options>
    </configuration>

应用此会导致错误消息:

19:52:53 WARNING: chmod /var/syncthing/config: operation not permitted
[monitor] 19:52:53 INFO: Default folder created and/or linked to new config
19:52:53 WARNING: chmod /var/syncthing/config: operation not permitted
[start] 19:52:53 INFO: syncthing v1.12.1 "Fermium Flea" (go1.15.6 linux-amd64) docker@build.syncthing.net 2020-12-06 12:46:27 UTC [noupgrade]
[start] 19:52:53 INFO: Generating ECDSA key and certificate for syncthing...
[start] 19:52:53 WARNING: Failed to load/generate certificate: save cert: open /var/syncthing/config/cert.pem: permission denied
[monitor] 19:52:53 INFO: Syncthing exited: exit status 1

...所以看起来设置 subPath 的行为会使 /var/syncthing/config 目录不可写。

我还想知道 configmap 是否是正确的方法 - 证书和密钥在第一次运行时自动生成,我可能不希望在重新启动 pod 时重新创建它们。大多数 config.xml 都是一样的 - 我只想更改一些项目以便在 0.0.0.0 上公开接口,而不是默认的 127.0.0.1 以便它可以作为服务公开给 k8s,加上也许其他一些位。也许 PersistentVolumeClaim 会是一个更好的主意..?我基本上需要 config.xml 文件是可配置的,并且目录的其余部分可以被 pod 访问。

0 个答案:

没有答案