简体   繁体   中英

Reading Value form ConfigMap that are mounted as file in Kubernetes cluster JAVA

Here is my ConfigMap


apiVersion: v1
data:
  application_config.properties: |-
    id= abc
    mode= abc
    username= abc
    endpoint: abc
    url= abc
    id= abc
kind: ConfigMap
metadata:
  name: yml-config

and here is my deployment

   ---
apiVersion: apps/v1
kind: Deployment
metadata:
....
spec:
....
  template:
    metadata:
      labels:
        app: demo
      name: demo
    spec:
      containers:
      - image: abc:1.0
        imagePullPolicy: Always
        name: demo
        resources:
          limits:
            cpu: 500m
            memory: 650Mi
          requests:
            cpu: 500m
            memory: 650Mi
      volumeMounts:
        - mountPath: /opt/config/application_config.properties
          subPath: application_config.properties
          name: application-config-volume           
      ........
      volumes:
      - name: application-config-volume
        configMap:
          name: yml-config

What I need is -> I wish to mount my configmap as a single properties file in the mentioned location and just wish to read the values in core java by doing some I/O usage.

But I tried many ways used subpath, items and keys tag too. But I am only getting File not found exception.

(point to note - I dont have the access to look into the container which is creating some issue ) It would be great if someone could help me along with the java code showing how to fetch the value based on the mount path. Which I may try. Thanks in advance.

You can use any function or command that is used to read file at that location

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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