【发布时间】:2021-09-08 23:35:36
【问题描述】:
我将描述我的目标是什么,然后展示我为实现它所做的工作......我的目标是:
- 创建一个包含属性文件路径的配置映射
- 创建一个部署,其中有一个卷从 configmap 中配置的路径安装文件
我做了什么:
配置映射:
apiVersion: v1
kind: ConfigMap
metadata:
name: my-configmap
data:
my_properties_file_name: "my.properties"
部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-client-deployment
spec:
selector:
matchLabels:
app: my-client
replicas: 1 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: my-client
spec:
containers:
- name: my-client-container
image: {{ .Values.image.client}}
imagePullPolicy: {{ .Values.pullPolicy.client }}
ports:
- containerPort: 80
env:
- name: MY_PROPERTIES_FILE_NAME
valueFrom:
configMapKeyRef:
name: my-configmap
key: my_properties_file_name
volumeMounts:
- name: config
mountPath: "/etc/config"
readOnly: true
imagePullSecrets:
- name: secret-private-registry
volumes:
# You set volumes at the Pod level, then mount them into containers inside that Pod
- name: config
configMap:
# Provide the name of the ConfigMap you want to mount.
name: my-configmap
# An array of keys from the ConfigMap to create as files
items:
- key: "my_properties_file_name"
path: "my.properties"
结果是在/etc/config 下有一个名为my.properties 的文件,但该文件的内容是“my.properties”(因为它在配置映射中显示为文件名),而不是属性的内容文件,因为它实际上在我的本地磁盘中。
如何使用 configmap 中配置的路径挂载该文件?
【问题讨论】:
标签: kubernetes docker-volume configmap