[英]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.