简体   繁体   English

Kubernetes目录configMap和Java系统属性

[英]Kubernetes directory configMap and java system properties

I'm trying to use a directory config map as a mounted volume inside of my docker container running a spring boot application. 我正在尝试使用目录配置映射作为运行Spring Boot应用程序的Docker容器内部的挂载卷。 I am passing some of the mounted paths to the things like the spring application.yaml, but it doesn't appear the mount is working as expected as it can't find the config. 我正在将某些安装路径传递给诸如spring application.yaml之类的东西,但是由于找不到配置,因此似乎没有按预期方式进行安装。 For example 例如

Create the configmap like so 像这样创建configmap

kubectl create configmap example-config-dir \
 --from-file=/example/config/

Kubernetes yaml Kubernetes yaml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: example
  labels:
   app: example
spec:
  replicas: 1
  selector:
   matchLabels:
     app: example
  template:
    metadata:
      labels:
        app: example
    spec:
     containers:
     - name: example
       image: example:latest
       ports:
         - containerPort: 8443
       volumeMounts:
          - name: config-vol
            mountPath: /config
     volumes:
       - name: config-vol
         configMap:
           name: example-config-dir

And the Dockerfile (there are other steps which copy the jar file in which I haven't detailed) 还有Dockerfile(还有其他步骤可以复制我未详细介绍的jar文件)

VOLUME /tmp
RUN echo "java -Dspring.config.location=file:///config/ -jar myjarfile.jar" > ./start-spring-boot-app.sh"
CMD ["sh", "start-spring-boot-app.sh"]

As explained in Create ConfigMaps from Directories and Create ConfigMaps from files , when you create a ConfigMap using --from-file , the filename becomes a key stored in the data section of the ConfigMap . 从目录 创建ConfigMap从文件创建ConfigMap中所述 ,当使用--from-file 创建ConfigMap时, 文件名成为存储在ConfigMap的data部分中的键 The file contents become the key's value. 文件内容成为密钥的值。

To do the way you want, a better way would be creating the yml like this 要按照您想要的方式进行操作,更好的方法是像这样创建yml

apiVersion: v1
kind: ConfigMap
metadata:
  name: special-config
  namespace: default
data:
  SPECIAL_LEVEL: very
  SPECIAL_TYPE: charm

and then apply like this: 然后像这样申请:

kubectl create -f https://k8s.io/examples/configmap/configmap-multikeys.yaml

When the pod runs, the command ls /config produces the output below: 当pod运行时,命令ls /config产生以下输出:

special.level
special.type

The way you did, should generate a file with same name as your original files and within it the contents of the file. 这样做的方式应该生成一个与原始文件同名的文件,并在其中包含文件内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何基于激活的弹簧配置文件从 kubernetes configMap 加载属性 - How to load properties from kubernetes configMap based on activated spring profiles Spring 引导:覆盖来自 Kubernetes ConfigMap 的 application.yml 属性 - Spring Boot: override application.yml properties from Kubernetes ConfigMap Dockerized Spring Boot 应用程序不使用挂载的 Kubernetes ConfigMap (application.properties) - Dockerized Spring Boot app not using mounted Kubernetes ConfigMap (application.properties) ConfigMap 数据(yml 格式)——Kubernetes - ConfigMap data (yml format) - Kubernetes 调用刷新时,从文件系统挂载和加载的 K8s ConfigMap 属性不起作用 - K8s ConfigMap Properties mounted and loaded from file system does not work when refresh is called 使用 Kube.netes configmap 作为 spring 引导的配置服务器 - Using Kubernetes configmap as config server for spring boot 使用带有 Spring Boot Kubernetes 的 ConfigMap 外部化配置 - Externalize configuration using ConfigMap with Spring Boot Kubernetes 如何在 kubernetes configMap 中从重新加载中排除 @ConfigurationProperties - How to exclude @ConfigurationProperties from reloading in kubernetes configMap Spring Cloud Kubernetes ConfigMap 重新加载不起作用 - Spring Cloud Kubernetes ConfigMap reload not working springboot应用程序未获取Kubernetes configmap名称 - Kubernetes configmap name is not picked up by springboot application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM