Home > Back-end >  Is there a different way to include .conf file in my pod?
Is there a different way to include .conf file in my pod?

Time:06-28

I'm making use of a conf file in my pod which is necessary for my application. Right now I'm adding this conf file directly to my Docker image with

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

This is the contents of my conf file

[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. How do I approach this problem ?

CodePudding user response:

You should use volume and volumeMount to refactor your project.

k8s volume

configMap

Note:

  • You can create a ConfigMap before you can use it.
  • A container using a ConfigMap as a subPath volume mount will not receive ConfigMap updates.
  • Text data is exposed as files using the UTF-8 character encoding. For other character encodings, use binaryData.

e.g.

configmap.yaml

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

pod.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
  • Related