Kubernetes / Helm:在Init和Main容器之间共享一个非属性文件

问题描述 投票:0回答:2

在kubernetes(minikube)/ helm env中,我有一个ldif文件,我想在Init容器和普通容器之间的卷上共享该文件。我不想共享存储此文件的整个文件夹。

不幸的是,除非该文件是一个属性文件(语法为“ key = value”),否则无法实现。

我使用configMap / subPath进行测试,似乎如果不遵守键/值语法,则Init容器甚至无法启动,否则一切正常,文件也将显示在主容器上。

所以我想知道是否有可能完成这种共享。

BR

kubernetes kubernetes-helm volume data-sharing configmap
2个回答
0
投票

要在初始化容器和其他容器之间共享文件,可以将volume mount与EmptyDir一起使用

  volumes:
  - name: cache-volume
    emptyDir: {}

初始化容器要共享的文件可以由容器进程复制到emptyDir的mountPath上,然后主容器从emptyDir卷的uthPath中选择它。

这样,即使pod重新启动后,有问题的文件(例如,路径/ path1 / file中的文件也将被复制到/ path2 / file(initcontainer上的emptyDir的uthPath),然后在将emptyDir挂载到主容器上时保持在那里)直到pod重新启动


0
投票

是的,有可能,而且您处在正确的轨道上。

这是如何执行此操作的示例。

---
kind: ConfigMap 
apiVersion: v1 
metadata:
  name: example-configmap 
data:
  my-file.ldif: |
     dn: cn=The Postmaster,dc=example,dc=com
     objectClass: organizationalRole
     cn: The Postmastermongodb
---
kind: Pod
apiVersion: v1
metadata:
  name: example-pod
spec:
  volumes: 
  - name: config-volume
    configMap:
      name: example-configmap
  initContainers:
  - name: init
    image: busybox
    volumeMounts:
    - name: config-volume
      mountPath: /path/in/the/init-container/my-file.ldif
      subPath: my-file.ldif
  containers:
  - name: main
    image: busybox
    volumeMounts:
    - name: config-volume
      mountPath: /path/in/the/container/my-file.ldif
      subPath: my-file.ldif

如果发布您的配置图,将会有所帮助。您可能会被提示,因为要使其正常工作,您需要文件的全部内容作为configmap中一个键的值。

© www.soinside.com 2019 - 2024. All rights reserved.