将ConfigMap用作挂载卷时,将删除Pod挂载位置内的所有现有文件和文件夹。
使用以下命令创建ConfigMap:
where
部署yaml文件:
$ kubectl create configmap tomcat-configmap --from-file=./config/tomcat-config.xml
我尝试了不同的配置,但没有成功:(
任何建议都会很有帮助
我正在使用Windows的docker提供的kubernetes:
kind: Service
apiVersion: v1
metadata:
name: tomcat-svc
spec:
selector:
app: tomcat-container
ports:
- protocol: TCP
port: 83
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-deployment
spec:
selector:
matchLabels:
app: tomcat-container
replicas: 1
template:
metadata:
labels:
app: tomcat-container
spec:
containers:
- name: tomcat
image: bitnami/tomcat:latest
ports:
- containerPort: 8080
volumeMounts:
- name: tomcat-configmap-volume
mountPath: /usr/local/tomcat/webapps/examples/WEB-INF/classes/com/test/app-conf.xml
subPath: app-conf.xml
volumes:
- name: tomcat-configmap-volume
configMap:
name: tomcat-configmap
答案 0 :(得分:1)
这里的问题是,您正在使用subPath
,并且它是一个目录,并且您认为app-conf.xml
应该作为文件创建。
您真正想要的就是这个:
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-deployment
spec:
selector:
matchLabels:
app: tomcat-container
replicas: 1
template:
metadata:
labels:
app: tomcat-container
spec:
containers:
- name: tomcat
image: bitnami/tomcat:latest
ports:
- containerPort: 8080
volumeMounts:
- name: tomcat-configmap-volume
mountPath: /usr/local/tomcat/webapps/examples/WEB-INF/classes/com/test
volumes:
- name: tomcat-configmap-volume
configMap:
name: tomcat-configmap
并命名文件app-conf.xml
,以便在创建ConfigMap时在ConfigMap本身中为其分配一个data
键app-conf.xml
:
$ kubectl create configmap tomcat-configmap --from-file=./app-conf.xml
然后您的ConfigMap将如下所示:
$ kubectl describe cm tomcat-configmap
Name: tomcat-configmap
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
app-conf.xml:
----
<xml>
...
...
</xml>
Events: <none>
答案 1 :(得分:0)
kind: Service
apiVersion: v1
metadata:
name: tomcat-svc
spec:
selector:
app: tomcat-container
ports:
- protocol: TCP
port: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-deployment
spec:
selector:
matchLabels:
app: tomcat-container
replicas: 1
template:
metadata:
labels:
app: tomcat-container
spec:
containers:
- name: tomcat
image: bitnami/tomcat:latest
ports:
- containerPort: 8080
volumeMounts:
- name: tomcat-configmap-volume
mountPath: /usr/local/tomcat/webapps/examples/WEB-INF/classes/com/test
#subPath: app-conf.xml
volumes:
- name: tomcat-configmap-volume
configMap:
name: tomcat-configmap
Rico上面提供的答案应该可行,无论如何,我在下面提供实施结果:
注释掉子路径,当您想覆盖现有的配置文件时,子路径非常有用。另外,您的tomcat路径在您使用的映像中为/ opt / bitnami / tomcat,并且您正在/ usr / local / tomcat /中的动态创建的自定义位置中装载文件,请确保您的意思是覆盖内容