【问题标题】:Kubernetes configmap removes all the contents of existing directoryKubernetes configmap 删除现有目录的所有内容
【发布时间】:2019-04-05 19:32:34
【问题描述】:

我已经创建了一个 configmap 和一个 pod yaml 文件。

我尝试了多种解决方案,但没有一个对我有用。

kubectl describe cm cf3
Name:         cf3
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
index.html:
----
hii im marimmo

Events:  <none

pod yaml 文件

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
  - name: test-container
    image: manya97/manya_tomcat:0.1

  volumeMounts:
  - name: config-volume
    mountPath: /apache-tomcat-8.0.32/webapps/SampleWebApp/index.html
    subPath: index.html
volumes:
- name: config-volume
  configMap:
          name: cf3

restartPolicy: Never

这应该替换现有的 index.html 文件,但不知何故,它删除了 SampleWebApp 的所有内容并仅放置 index.html。 我不知道是否以正确的方式完成,我只想替换 index.html 的内容。我不知道安装可能会以这种方式工作。

【问题讨论】:

  • 我不确定您是否可以使用文件作为路径。您可以为配置文件使用不同的挂载路径,然后在启动容器时将其复制到/SampleWebApp(请参阅stackoverflow.com/questions/28976455/…

标签: kubernetes configmap


【解决方案1】:

挂载总是基于目录的。因此,在您的 yaml 文件中挂载会告诉 k8s 将 configMap 的内容(可能是一个或多个文件)挂载到目录中。

挂载之前目录中的任何内容都消失了。

查看官方文档:https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/

有提示说“注意:如果挂载目录中有文件,会被删除。”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    相关资源
    最近更新 更多