EDITORIAL
1. About docker + k8s of the building method and process, please refer before a blog
2. We use the architecture is duboo architectural pattern. All applications except tomcat jar and have to start the virtual machine.
Use containers to start tomcat
Because the use of container started the project, there must be a process running in the foreground, otherwise the container will automatically exit after the run up. So we carried on the official secondary mirror tomcat build and do some of your own configuration.
tomcat image after the official start of the container, the tomcat logs are placed in the front desk printed out, and do not log cutting. After the container exit logs lost. We have to solve these two problems.
One problem: the log cutting
First, compile and install container cronolog tools. But the system needs to install the software before installing cronolog gcc, tomcat official mirror is very clean, and we did not need to first install gcc gcc at the same time you are installing it make.
Second problem: the problem log output in the foreground.
Way mirror tomcat official launch container is catalina.sh run way to start. Such direct output start log in the foreground, you can ensure that the container does not quit. But we aim it is to log onto a local.
We start to tomcat's put it another way, to write a script start.sh, as follows:
#!/bin/sh sh /usr/local/tomcat/bin/startup.sh tail -f /usr/local/tomcat/bin/catalina.sh
Because if you start tomcat directly startup.sh way, will lead to the foreground process is not running, it will cause the container to exit, so add a tail -f command behind us. That tail just write a file on the line.
This ensures that the tomcat log that is done at the same time cutting the log kept in the background.
Dockerfile the document reads as follows:
FROM tomcat:7.0-slim LABEL maintainer="ZhiYu Xin<[email protected]>" ADD ./catalina.sh /usr/local/tomcat/bin/ ADD ./cronolog-1.6.2.tar.gz /opt/ ADD ./start.sh /usr/local/tomcat/bin/ WORKDIR /opt/cronolog-1.6.2 RUN echo "deb http://ftp.us.debian.org/debian/ jessie main contrib non-free" >> \ /etc/apt/sources.list && echo "deb-src http://ftp.us.debian.org/debian/ jessie main contrib non-free" \ >> /etc/apt/sources.list && apt-get update -y && apt-get install -y gcc-4.8 g++-4.8 g++-4.8-multilib make && \ ./configure && make && make install && chmod a+x /usr/local/tomcat/bin/start.sh EXPOSE 8080 ENTRYPOINT ["/bin/sh", "/usr/local/tomcat/bin/start.sh" ]
Three issues: how to log storage container is directly output to the host of docker.
We need to start at the time of the container, the container to mount / usr / local / tomcat next volume to / logs directory on it.
Before starting the best in local container to create the corresponding directory.
yml start the container contents are as follows:
apiVersion: apps/v1 kind: Deployment metadata: name: tomcat labels: app: tomcat spec: replicas: 1 selector: matchLabels: app: tomcat template: metadata: labels: app: tomcat spec: # Declare a volume for later use volumes: - name: "tomcat-log" hostPath: path: "/data" containers: - name: tomcat1 image: xinsir8/tomcat:v1 ports: - containerPort: 8080 # Mount a volume volumeMounts: # Which directory to mount - mountPath: /usr/local/tomcat/logs name: tomcat-log # Resource constraints resources: requests: memory: "64Mi" cpu: "250m" limits: memory: "128Mi" cpu: "500m"
Question 4: How to troubleshoot network issues, communications, and tomcat jar of scheduling and communications nginx tomcat and so on.
In fact, very simple solution to this problem, we create a service able to solve this problem. yml file creation service reads as follows
apiVersion: v1 kind: Service metadata: # Service name name: tomcat-service spec: # Service types, including but not limited to type [NodePort, ClusterIP, NodePort, LoadBalancer] type: NodePort ports: Container port # - port: 8080 After mapping the port # nodePort: 31003 selector: # This service will be applied to all container labels for the app equal to the tomcat app: tomcat