jenkins with k8s to achieve application continuous integration

Keywords: Big Data Tomcat xml ssh

The previous article wrote about how to build a reusable image of tomcat. This article talked about how to use this image to build different projects repeatedly.


Go straight to the subject:

Step 1 create the corresponding mavn project job

Other configurations remain the same. The main change is the action after the build project.

Note: because my k8s cluster has only one node, all the pod s will start on the node by default, so I will directly transfer the built war to the node here.

Create another ssh action


It should be noted that the path of both the server.xml configuration file and the yml configuration file must be correct and not disorderly.

The main meaning is:

First check if there is a configmap for this project. If not, create it. If there is, no action.

Then check whether the deployment of this project is started. If there is no direct creation of the deployment, delete the deployment first, and then create it again. Realize the restart effect.

Here's another thing to note. If you modify the deployment.yml file, you need to manually delete the current deployment first, or an error will be reported.



The following shows deployment.yml

#api version number
apiVersion: apps/v1
#Create type
kind: Deployment
#Description
metadata:
  name: jlj-learning-controller
  labels:
    app: jlj-learning-controller
spec:
#Start several copies
  replicas: 1
  selector:
    matchLabels:
      app: jlj-learning-controller
  template:
    metadata:
      labels:
        app: jlj-learning-controller
    spec:
    #Create 3 volumes
      volumes:
      #war package for storing the project
      - name: "jlj-learning-controller-war"
        hostPath: 
         path: "/Disk/data/tomcat/jlj-learning-controller/code/"
      #Log for tomcat
      - name: "jlj-learning-controller-log"
        hostPath:
         path: "/Disk/data/tomcat/jlj-learning-controller/log/"
      #Get the contents of the server.xml file in the configmap created earlier
      - name: "jlj-learning-controller-server-xml"
        configMap:
         name: jlj-learning-controller.xml 
         items:
         - key: server.xml
           path: server.xml
      containers:
      - name: jlj-learning-controller
        image: fushuitong/tomcat:jdk7u21-tomcat7.0.77-cronolog1.6.2
        ports:
        - containerPort: 8080
        #Mount 3 volume s
        volumeMounts:
        #Mount the war package of the project to the webapps directory of tomcat in the container, so that when tomcat starts, it will load the project directly, which has been decompressed before.
        - name: jlj-learning-controller-war
          mountPath: /usr/local/tomcat/webapps
        #Mount the local log directory to the logs directory of tomcat in the container, so that all logs of tomcat are stored on the hard disk of the host, and the deleted logs of the container will not be lost.
        - name: jlj-learning-controller-log
          mountPath: /usr/local/tomcat/logs
        #Let's say again, why do you want to use the configfile directory of the container where the server.xml file is mounted? Because in this way, the contents of the original directory of the container will be deleted.
        #So we mount the server.xml file to the / configfile directory, because ln has been done in the last build image, so this will
        #Loaded as tomcat's configuration file.
        - name: jlj-learning-controller-server-xml
          mountPath: /configfile


Posted by jannz on Fri, 01 Nov 2019 11:26:06 -0700