babbyldockr
babbyldockr

Reputation: 45

Best practice for adding app configuration files into kubernetes pods

I have the following setup:

An azure kubernetes cluster with some nodes where my application (consisting of multiple pods) is running. I'm looking for a good way to make a project-specific configuration file (a few hundred lines) available for two of the deployed containers and their replicas.

The configuration file is different between my projects but the containers are not.

I'm looking for something like a read-only file mount in the containers, but haven't found an good way. I played around with persistent volume claims but there seems to be no automatic file placement possibility apart from copying (including uri and secret managing).

Best thing would be to have a possiblility where kubectl makes use of a yaml file to access a specific folder on my developer machine to push my configuration file into the cluster.

Can anybody guide me to a good solution that matches my situation?

Upvotes: 2

Views: 2587

Answers (1)

chresse
chresse

Reputation: 5815

You can use a configmap for this, but the configmap includes your config file. You can create a configmap with the content of your config file via the following:

kubectl create configmap my-config --from-file=my-config.ini=/path/to/your/config.ini

and the bind it as a volume in your pod:

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: mypod
    ...
    volumeMounts:
    - name: config
      mountPath: "/config"
      readOnly: true
  volumes:
  - name: config
    configMap:
      name: my-config #the name of your configmap

Afterwards your config is available in your pod under /config/my-config.ini

Upvotes: 7

Related Questions