其他分享
首页 > 其他分享> > K8S 如何隐藏产品TomCat版本信息

K8S 如何隐藏产品TomCat版本信息

作者:互联网

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: {}

标签:TomCat,tomcat,版本信息,local,usr,conf,K8S,config,name
来源: https://www.cnblogs.com/jerry-0910/p/15897046.html