使用 kubernetes 将 tomcat conf 文件发送到容器

Dav*_*jan 1 java tomcat7 docker kubernetes docker-container

我是 docker 和 Kubernetes 的新手,我正在尝试创建一个容器,tomcat7/Java7以便我可以将webapps其部署到其中。我唯一担心的是tomcat/conf配置文件,其中有细节database connectionsthreadpoolJava Memory等。

我想要的是将这些文件从 Kubernetes 服务器复制到 docker-container 并将它们放在正确的位置,同时启动容器。

PS:我不想通过环境变量来做,因为如果我为配置文件中的每个条目保留一个变量,它们的数量将会很大。

小智 5

你可以在你的 Kubernetes 中添加一个 ConfigMap,从你的 tomcat 配置(文件或整个目录)

kubectl -n staging create configmap special-config --from-file={path-to-tomcat-conf}/server.xml
Run Code Online (Sandbox Code Playgroud)

然后将它挂载到你的 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
Run Code Online (Sandbox Code Playgroud)

Kubernetes 文档