繁体   English   中英

如何在不使用卷的情况下将 ConfigMap 作为文件挂载

[英]How to mount a ConfigMap as a file without using volume

这个问题背后的目的是要知道如何在 Pod 中有一个文件,如果我们使用 ConfigMap,如果 configMap 会改变,我不想应用更改

谢谢

我不太明白,你为什么不想使用卷? 将 confgimap 挂载到 pod 的正确方法如下所示: Configmap- 在data部分中指定文件的名称:

apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: 2016-02-18T18:52:05Z
  name: txt-file-configmap
  namespace: default
  resourceVersion: "516"
  selfLink: /api/v1/namespaces/default/configmaps/game-config
  uid: b4952dc3-d670-11e5-8cd0-68f728db1985
data:
  file.txt: |
    here
    are
    filecontents

在一个 pod 中,指定一个带有 configmap 名称和 volumeMount 的卷,指向一个路径,在哪里安装卷:

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh", "-c", "cat /etc/txtfiles/file.txt" ]
      volumeMounts:
      - name: txt-file
        mountPath: /etc/txtfiles
  volumes:
    - name: txt-file
      configMap:
        name: txt-file-configmap

我提供给您的示例 pod 会将 configmap 作为文件安装并打印其内容。

我认为您想要一个 pod 内的文件,但如果配置映射已更新,您不想更新该文件。 所以你不能使用 configmap 因为它会在 pod 重启时更新文件。

所以我能想到的唯一选择是在创建 pod 后推送文件,例如“kubectl cp”命令将文件复制到 pod。

kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar

问题将是当 pod 重新启动时文件消失了,因此您必须以某种方式使其自动化,

下面是使用 init 容器。

您可以将文件放在某个 XYZ 位置并通过 init 容器下载它。

  initContainers:
  - name: download-conf
    image: busybox:1.28
    command: ['sh', '-c', 'curl http://exampel.com/conf.file -o statfull.conf']

注意:- 这是一种未经测试的公正方法代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM