In order to understand the CICD deployment process using jenkins, harbor and gitlab, I first carried out the deployment process without using its software, understood this process, and knew it when configuring the above automatic deployment tools.
Take deploying a helloword program using springboot as an example
1. Package the spingboot project into a jar file with maven
Using the command mvn clean package in the project directory, you can see the generated helloworld.jar file in the target directory,
Use the java -jar helloword.jar command to run it to see if it can be used normally. No problem. Go to the next step
2. Generate docker image file
Spring boot uses the jdk environment image. First, use docker to pull the jdk image locally
sudo docker pull openjdk:8-alpine
Write Dockerfile file
FROM openjdk:8-alpine COPY target/helloworld.jar /springboot-web.jar ENTRYPOINT ["java", "-jar", "/springboot-web.jar"]
Package to generate image
sudo docker build -t springboot-web:v1 .
3. Push the image to the private harbor warehouse
sudo docker tag springboot-web:v1 core.harbor.shell.com:32042/library/springboot-web:v1
sudo docker login -u admin core.harbor.shell.com:32042
//After successful login
sudo docker push core.harbor.shell.com:32042/library/springboot-web:v1
Check the library Directory in the harbor warehouse. If there is a springboot web image, it indicates that the push is successful
4. Write k8s deployment script deploy.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: springboot-web namespace: default spec: replicas: 1 selector: matchLabels: app: springboot-web release: canary template: metadata: labels: app: springboot-web release: canary spec: containers: - name: springboot-web image: core.harbor.shell.com:32042/library/springboot-web:v1 imagePullPolicy: IfNotPresent ports: - name: http containerPort: 8084 --- apiVersion: v1 kind: Service metadata: name: springboot-web namespace: default spec: selector: app: springboot-web release: canary ports: - name: http targetPort: 8084 port: 8084 --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-nginx namespace: default spec: ingressClassName: traefik rules: - host: springboot.shell.com http: paths: - path: / pathType: Prefix backend: service: name: springboot-web port: name: http
Then deploy kubectl apply -f deploy.yaml
It should be noted here that if you deploy the pod directly, the image will not be pulled down and no will be displayed such Host. This is because the host of node k8s deploying pod is not configured with the host of harbor. You need to add the address resolution of core.harbor.shell.com in / etc/hosts.
In addition, X509 permission error will be reported during deployment, and there is no permission to pull the image.
I've seen many reports on the Internet that imagePullSecrets and the secret accessed by docker need to be configured. I tried it and it didn't work. I don't know what the problem is at present. My solution: k8s deploying pod is to use docker to pull the image on the allocated node, so add the configuration of docker accessing harbor on its node( CSDN ), you can pull normally after configuration. I suggest configuring all worker nodes
Check the domain name set in Xpress and configure the resolution of the relevant domain name for the accessed client machine, so that you can normally access the services written by the springboot project.