k8s隐藏TomCat版本信息,通过sidecar方式初始化修改server.xml文件,并挂载到容器中
1、添加initcontainers
initContainers:
- name: config
image: tomcat:jdk8-openjdk-buster
command:
- /bin/sh
- -c
- >
sed -i '/<\/Host>/i \ <Valve className="org.apache.catalina.valves.ErrorReportValve" showReport="false" showServerInfo="false" />' /usr/local/tomcat/conf/server.xml;
cp -a /usr/local/tomcat/conf/* /tmp/;
sleep 1;
volumeMounts:
- name: tomcat-config
mountPath: /tmp/
2、containers
containers:
image: tomcat:jdk8-openjdk-buster
imagePullPolicy: IfNotPresent
name: tomcat
volumeMounts:
- name: tomcat-config
mountPath: /usr/local/tomcat/conf
volumes:
- name: tomcat-config
emptyDir: {}
3、完整yaml文件
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: tomcat
name: tomcat
namespace: demo
spec:
replicas: 1
selector:
matchLabels:
app: tomcat
template:
metadata:
labels:
app: tomcat
spec:
initContainers:
- name: config
image: tomcat:jdk8-openjdk-buster
command:
- /bin/sh
- -c
- >
sed -i '/<\/Host>/i \ <Valve className="org.apache.catalina.valves.ErrorReportValve" showReport="false" showServerInfo="false" />' /usr/local/tomcat/conf/server.xml;
cp -a /usr/local/tomcat/conf/* /tmp/;
sleep 1;
volumeMounts:
- name: tomcat-config
mountPath: /tmp/
containers:
- env:
- name: TZ
value: "Asia/Shanghai"
image: tomcat:jdk8-openjdk-buster
imagePullPolicy: IfNotPresent
name: tomcat
volumeMounts:
- name: tomcat-config
mountPath: /usr/local/tomcat/conf
volumes:
- name: tomcat-config
emptyDir: {}