简体   繁体   English

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

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

The aim behind this question is to know how having a file inside a Pod, if we use ConfigMap, I don't want to apply changes if the configMap will change这个问题背后的目的是要知道如何在 Pod 中有一个文件,如果我们使用 ConfigMap,如果 configMap 会改变,我不想应用更改

Thanks谢谢

I am not really understanding, why don't you want to use a volume?我不太明白,你为什么不想使用卷? A proper way, to mount a confgimap to a pod looks like this: Configmap- specify name of the file in a data section:将 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

And in a pod, specify a volume with a configmap name and volumeMount, pointing a path, where to mount the volume:在一个 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

The example pod which I provided you, will have the configmap mounted as a file and will print it's contents.我提供给您的示例 pod 会将 configmap 作为文件安装并打印其内容。

I think you want a file inside a pod but you don't want to get that updated if the config map is updated.我认为您想要一个 pod 内的文件,但如果配置映射已更新,您不想更新该文件。 So you can not use configmap because it will update files if pod restart.所以你不能使用 configmap 因为它会在 pod 重启时更新文件。

So the only option I can think to push file after the pod is created something like "kubectl cp" command to copy a file to the pod.所以我能想到的唯一选择是在创建 pod 后推送文件,例如“kubectl cp”命令将文件复制到 pod。

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

The problem will be when pod restarted the file be gone so you have to automate it by somehow one way,问题将是当 pod 重新启动时文件消失了,因此您必须以某种方式使其自动化,

Below is using init container.下面是使用 init 容器。

you can put the file in some XYZ location and download it by init container.您可以将文件放在某个 XYZ 位置并通过 init 容器下载它。

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

NOTE:- This is an just approach code have't tested注意:- 这是一种未经测试的公正方法代码

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

相关问题 如何将 configMap 挂载为有状态集中的卷挂载 - How to mount a configMap as a volume mount in a Stateful Set 将 configmap 文件挂载到主机路径卷上 - Mount configmap file onto hostpath volume Helm - 如何使用 ConfigMap 在卷中写入文件? - Helm - How to write a file in a Volume using ConfigMap? 使用 configmap 卷挂载将文件挂载(添加)到现有目录 - Mount (add) files to existing directory using configmap volume mount Kubernetes 卷装载 ConfigMap 到 pod 内的文件,而不覆盖所有其他文件 - Kubernetes Volume Mount ConfigMap to File within the pod without overwriting all other files 如何使用清单 yaml 在 Kubernetes configmap 中挂载属性文件 - How to mount the properties file in Kubernetes configmap using manifest yaml 如何为 VMWare 的 fluentd 操作员安装 ConfigMap 卷? - How do I mount a ConfigMap volume for VMWare's fluentd operator? 如何使用 configmap 在 Kubernetes 中挂载整个目录? - How to mount entire directory in Kubernetes using configmap? 将现有的 azure 文件共享挂载为持久卷而不使用机密 - Mount existing azure file share as a persistent volume without using secret 如何在不创建 ConfigMap 的情况下将动态生成的文件挂载到 pod 中? - How can I mount a dynamically generated file into a pod without creating a ConfigMap?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM