问题描述
我是docker和Kubernetes的新手,我试图创建一个具有tomcat7/Java7
的容器,以便可以将webapps
部署到其中.我唯一关心的是tomcat/conf
配置文件,其中包含database connections
,threadpool
,Java Memory
等的详细信息.
I am new to docker and Kubernetes, I am trying to create a container having tomcat7/Java7
so that I could deploy my webapps
into it. The only concern I have are the tomcat/conf
config files, which have details of database connections
, threadpool
, Java Memory
etc.
我想要的是在启动容器时将这些文件从Kubernetes服务器复制到docker-container并将它们放置在正确的位置.
What I want is to copy these files from Kubernetes server to docker-container and place them at right places, while starting the container.
P.S:我不想通过环境变量来完成此操作,因为如果我在配置文件中为每个条目保留一个变量,它们的数量将会很大.
P.S: I don't want to do it via enviroment variables, as they are going to be huge in numbers if I keep a variable for every entry in config files.
推荐答案
您可以从您的tomcat配置(文件或整个目录)中在Kubernetes中添加ConfigMap
You could add a ConfigMap in your Kubernetes, from your tomcat config (files or a whole dir)
kubectl -n staging create configmap special-config --from-file={path-to-tomcat-conf}/server.xml
然后将其安装在您的Pod上(kubectl创建-f path/to/the/pod.yaml)
And then mount it on your pod (kubectl create -f path/to/the/pod.yaml)
apiVersion: v1
kind: Pod
metadata:
name: tomcat-test-pod
spec:
containers:
- name: test-container
image: tomcat:7.0
command: [ "catalina.sh", "run" ]
volumeMounts:
- name: config-volume
mountPath: /usr/local/tomcat/conf/server.xml
volumes:
- name: config-volume
configMap:
# Provide the name of the ConfigMap containing the files you want
# to add to the container
name: special-config
这篇关于使用kubernetes将tomcat conf文件发送到容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!