Access NFS volume mounts from Spring Boot application Kubernetes

11/14/2019

I have added a NFS volume mount to my Spring Boot container running on Kubernetes. Below is my deployment file for Kubernetes.

apiVersion: apps/v1
kind: Deployment
metadata: 
  labels: 
    app: ldap
spec: 
  replicas: 3
    spec: 
      serviceAccountName: xxx-staging-take-poc-admin
      volumes:
        - name: nfs-volume
          nfs:
           server: 10.xxx.xxx.xxx
           path: /ifs/standard/take1-poc 
      containers: 
        - 
          image: image-id
          volumeMounts:
            - name: nfs-volume
              mountPath: /var/nfs
          name: ldap

How do I access the mount path from my Spring Boot application to achieve file read and write.

-- Abhishek Anand
kubernetes
nfs
spring-boot

1 Answer

11/14/2019

If I understand you correctly you can pass external info to sprint boot application through environment variables. Here is an article with more detailed info of how to do it.

Kubernetes ConfigMaps also allows us to load a file as a ConfigMap property. That gives us an interesting option of loading the Spring Boot application.properties via Kubernetes ConfigMaps.

Also, you may want to get familiar with this documentation. It shows how to reference secrets which are also mounted so you may find it helpful in your case.

The Spring Cloud Kubernetes plug-in implements the integration between Kubernetes and Spring Boot. In principle, you could access the configuration data from a ConfigMap using the Kubernetes API.

Please let me know if that helped.

-- OhHiMark
Source: StackOverflow