How to use file, within "ConfigMap"

Hello, I would like to use, a template file, which is located in different directory.

File location: /current/addons/config.yaml

ConfigMap

---
 kind: ConfigMap
 apiVersion: v1
 appVersion: "1.0"

 # -- Meta Data(s)
 metadata:
   name: exporter
   namespace:  wider

 # -- Config File
 data:
   config.yml: << Need to show relative path.

Can someone help me with this small question?

You can define the path at the pod level when its mounted there, please see the configmap volume docs here:

1 Like

You can keep your ConfigMap definition just like this itself.

When you mount this ConfigMap to a pod or Deployment, provide the volume mount configuration like you mount that volume populated by the ConfigMap to the path you need.

Eg,

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: exporter-deployment
  labels:
    app: exporter-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: exporter-deployment
  template:
    metadata:
      labels:
        app: exporter-deployment
    spec:
      serviceAccountName: exporter-deployment
      containers:
      - name: exporter
        image: image_name
        imagePullPolicy: Always
        volumeMounts:
        - mountPath: /current/addons/config.yaml
          name: exporter-config
          subPath: config.yaml
      volumes:
      - name: exporter-vol
        configMap:
          name: exporter
2 Likes