如何在不使用卷的情况下将 ConfigMap 安装为文件

Sma*_*lns 4 kubernetes configmap

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

谢谢

Mar*_*szt 5

我不太明白,为什么不想使用卷?将 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
Run Code Online (Sandbox Code Playgroud)

在 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
Run Code Online (Sandbox Code Playgroud)

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