我试图使用configMap和volumeMount在deployment.yaml文件中替换容器中的属性文件。下面是我的部署文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-properties
spec:
selector:
matchLabels:
app: agent-2
replicas: 2
template:
metadata:
labels:
app: agent-2
spec:
containers:
- name: agent-2
image: agent:latest
ports:
- containerPort: 8080
volumeMounts:
- mountPath: "/usr/local/tomcat/webapps/agent/WEB-INF/classes/conf/application.properties"
name: "applictaion-conf"
subPath: "application.properties"
volumes:
- name: applictaion-conf
configMap:
name: dddeagent-configproperties
items:
- key: "application.properties"
path: "application.properties"下面是来自configMap的片段
apiVersion: v1
kind: ConfigMap
metadata:
name: agent-configp
data:
application.properties: |-
AGENT_HOME = /var/ddeagenthome
LIC_MAXITERATION=5
LIC_MAXDELAY=10000部署后,将安装完整的文件夹结构,而不是单个文件。因此,所有文件都将从现有文件夹中删除。
版本- 1.21.13
发布于 2021-08-10 14:36:29
我检查了这个配置,几乎没有拼写错误。您所指的是配置映射"dddeagent-configproperties“,但您已经定义了一个名为"agent-configp”的ConfigMap对象。
configMap:名称: dddeagent-configproperties
应:
configMap: name: agent-configp此外,还有一些缩进错误,所以我将粘贴一个固定的文件在答案的末尾。
就你的问题而言:你的方法是正确的,当我在我的设置中测试时,一切都正常工作,没有任何问题。我用安装ConfigMap的方式创建了一个示例荚(在有其他文件的目录中)。ConfigMap按其应有的方式作为文件挂载,其他文件仍可在目录中使用。
挂载:/app/上载/测试-文件夹/文件-1来自应用程序-conf (rw,path="application.properties")
您的方法与描述的here相同。
请再次检查在没有挂载配置映射的吊舱上,目录/usr/local/tomcat/webapps/agent/WEB-INF/classes/conf确实存在,其他文件也在这里。由于您的映像不可公开,所以我使用tomcat映像进行检查,/usr/local/tomcat/webapps/目录为空。注意,即使这个目录是空的,当您想要挂载一个文件时,Kubernetes也会在这里创建agent/WEB-INF/classes/conf目录和application.properties文件。
修正了具有良好缩进和拼写错误的部署和ConfigMap文件:
部署文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-properties
spec:
selector:
matchLabels:
app: agent-2
replicas: 2
template:
metadata:
labels:
app: agent-2
spec:
containers:
- name: agent-2
image: agent:latest
ports:
- containerPort: 8080
volumeMounts:
- mountPath: "/usr/local/tomcat/webapps/agent/WEB-INF/classes/conf/application.properties"
name: "application-conf"
subPath: "application.properties"
volumes:
- name: application-conf
configMap:
name: agent-configp
items:
- key: "application.properties"
path: "application.properties"配置文件:
apiVersion: v1
kind: ConfigMap
metadata:
name: agent-configp
data:
application.properties: |-
AGENT_HOME = /var/ddeagenthome
LIC_MAXITERATION=5
LIC_MAXDELAY=1000https://stackoverflow.com/questions/68722837
复制相似问题