[英]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.