title: Reading a config file from kubernetes using configMap and Volumes
body: <p>So i am struggling to read a xml file from kubernetes. I am running an open liberty server and a maven packaged war application. what do i need to change from my Java code so i can read file from kubernetes.</p>
  
  <p>The issue here is that the code reads pdp.xml from the resources folder inside the war file, not externally in a kubernetes volume.</p>
  
  <p>My configMap looks like this</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>kind: ConfigMap
  apiVersion: v1
  metadata:
    name: testing-config
  data:
    pdp.xml: |
     &lt;pdp    xmlns="http://authzforce.github.io/core/xmlns/pdp/7"
             xmlns:att="za.co.some.data"
             xmlns:xacml="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
             version="7.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
     &lt;/pdp&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here's the yaml file with volumes  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: testing-app
    labels:
      app: testing-app
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: testing-app
    template:
      metadata:
        labels:
          app: testing-app
      spec:
        containers:
        - name: testing-app
          image: testing-app:1.0.24-SNAPSHOT
          imagePullPolicy: Always
          volumeMounts:
          - name: testing-app-volume
            mountPath: /config/pdp.xml
            subPath: pdp.xml
            readOnly: true
        volumes:
        - name: testing-app-volume
          configMap:
            name: testing-app-config
        restartPolicy: Always</code></pre>
  </div>
  </div>
  </p>
  
  <p>I don't really know Java that well but here's how i'm reading the file.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>Resource resource = new ClassPathResource("pdp.xml");
  InputStream cfgFile = null;
  byte[] buffer = null;
  try {
    cfgFile = resource.getInputStream();
    buffer = new byte[cfgFile.available()];
  } catch (IOException e) {
    log.error(ERROR_MESSAGE);
    throw new IllegalStateException(ERROR_MESSAGE);
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>this is the folder structure inside the container</p>
  
  <p><a href="https://i.stack.imgur.com/Bu5LA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Bu5LA.png" alt="enter image description here"></a></p>