使用kubernetes将tomcat conf文件发送到容器 [英] send tomcat conf files to container using kubernetes

查看:112
本文介绍了使用kubernetes将tomcat conf文件发送到容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是docker和Kubernetes的新手,我试图创建一个具有tomcat7/Java7的容器,以便可以将webapps部署到其中.我唯一关心的是tomcat/conf配置文件,其中包含database connectionsthreadpoolJava 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

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆