从 Spring 启动应用程序 Kubernetes 访问 NFS 卷安装

Access NFS volume mounts from Spring Boot application Kubernetes

我在 Kubernetes 上的 Spring 引导容器 运行 添加了一个 NFS 卷装载。下面是我的 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

如何从我的Spring启动应用程序访问挂载路径来实现文件读写。

如果我的理解正确,您可以通过环境变量将外部信息传递给 sprint 启动应用程序。 Here 是一篇文章,其中包含有关如何操作的更详细信息。

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.

另外,您可能想熟悉一下 this documentation。它展示了如何引用同样已安装的机密,因此您可能会发现它对您的情况有所帮助。

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.

如果有帮助,请告诉我。