简体   繁体   English

有没有其他方法可以在我的 pod 中包含 .conf 文件?

[英]Is there a different way to include .conf file in my pod?

I'm making use of a conf file in my pod which is necessary for my application.我正在使用我的 pod 中的一个 conf 文件,这是我的应用程序所必需的。 Right now I'm adding this conf file directly to my Docker image with现在我正在将此 conf 文件直接添加到我的 Docker 映像中

COPY ./example.conf  /etc/example.conf

This is the contents of my conf file这是我的conf文件的内容

[example]
url = url
username = username
password = password

I want to be able to give the url dynamically via helm (or some other way), so the docker image method is not suitable.我希望能够通过 helm(或其他方式)动态提供 url,因此 docker image 方法不适合。 How do I approach this problem ?我该如何解决这个问题?

You should use volume and volumeMount to refactor your project.您应该使用volumevolumeMount来重构您的项目。

k8s volume k8s体积

configMap 配置映射

Note:笔记:

  • You can create a ConfigMap before you can use it.您可以先创建一个 ConfigMap,然后才能使用它。
  • A container using a ConfigMap as a subPath volume mount will not receive ConfigMap updates.使用 ConfigMap 作为 subPath 卷挂载的容器将不会收到 ConfigMap 更新。
  • Text data is exposed as files using the UTF-8 character encoding.文本数据使用 UTF-8 字符编码作为文件公开。 For other character encodings, use binaryData.对于其他字符编码,请使用 binaryData。

eg例如

configmap.yaml configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-conf
data:
  example.conf: |
    url = url
    username = username
    password = password  

pod.yaml豆荚.yaml

apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
    - name: test
      image: busybox:1.28
      volumeMounts:
        - name: conf
          mountPath: /etc/
  volumes:
    - name: conf
      configMap:
        name: test-conf

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM