-
Familiar with Spring Cloud microservice projects
-
Source code compilation and build
-
Build the project image and push it to the image warehouse
-
Make a mirror
-
Push the image to the harbor warehouse
-
-
K8s service orchestration
-
Deploy basic environment
-
Deploy Nacos cluster in K8s (registration and configuration center)
-
Deploy Seata distributed transactions in k8s
-
Deploy
mysql, redis, rabbitmq, minio, xxl-job
on linux
-
-
Deploy microservice program
-
Deploy microservice front-end
-
Microservices are released to the outside world
-
NorePort mode exposed
-
Ingress mode exposed
-
k8s container deployment process
Specific steps:
-
Step 1: Familiarize yourself with Spring Cloud microservice projects
-
Step 2: Source code compilation and construction
-
Step 3: Build the project image and push it to the image warehouse
-
Step 4: K8s service orchestration
-
Step 5: Deploy the basic environment required for the service
-
Step 6: Deploy microservice program
-
Step 7: Deploy microservice front-end
-
Step 8: Release the microservice to the outside world
Familiar with Spring Cloud microservice projects
Microservice architecture diagram
Source code compilation and construction
Pull warehouse code
git clone http://192.168.0.126/saas-wms/linkinsense-wms-public.git
Compile code
mvn clean package -Dmaven.test.skip=true -Pdev
The long build time here is because the first build requires downloading maven dependencies, and subsequent builds will be very fast.
Build the project image and push it to the image warehouse
-
Basic image: centos, ubuntu
-
Middleware image: jdk, nginx
-
Project image: base image + middleware image + project code
Make a mirror
https://blog.csdn.net/qq_40722827/article/details/126337904
Write the DockerFile of the gateway service and create an image
vi Dockerfile
FROM openjdk:8-jre RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN echo 'Asia/Shanghai' > /etc/timezone WORKDIR/wms-center/wms-gateway ADD ./target/wms-gateway-1.0.0.jar ./ EXPOSE 8901 CMD java -jar wms-gateway-1.0.0.jar
The file location where the completed DockerFile is placed
Build image through DockerFile
docker build -t wms-gateway:v1 -f wms-gateway/Dockerfile ./wms-gateway/
View the built image
docker images
Push the image to harbor warehouse
The previously deployed mirror warehouse Harbor: http://192.168.0.127:8084/
, if not, you can register an account with docker-hub.
Log in to the warehouse
docker login 192.168.0.127:8084
Pushing the image to the image warehouse needs to meet the image name of the image warehouse, so the built image needs to be tagged.
Tag the built image
docker tag wms-gateway:v1 192.168.0.127:8084/onlee/gateway:v1
Push mirror warehouse
docker push 192.168.0.127:8084/onlee/gateway:v1
Other modules build and push reference gateway module
K8s service orchestration
Make the k8s yaml file of gateway (gateway.yaml)
--- apiVersion: apps/v1 Kind: Deployment metadata: name: gateway namespace: wms-dev spec: replicas: 1 selector: matchLabels: project: wms-dev app: gateway template: metadata: labels: project: wms-dev app: gateway spec: imagePullSecrets: - name: registry-harbor containers: - name: gateway image: 192.168.0.127:8084/onlee/gateway:v1 imagePullPolicy: Always ports: - protocol: TCP containerPort: 8901 env: - name: JAVA_OPTS value: "-Xmx1g" resources: requests: CPU: 0.5 memory: 256Mi limits: cpu: 1 memory: 1Gi readinessProbe: tcpSocket: port: 8901 initialDelaySeconds: 60 periodSeconds: 10 livenessProbe: tcpSocket: port: 8901 initialDelaySeconds: 60 periodSeconds: 10
For other modules to write k8s yaml files, please refer to the gateway module.
Deploy basic environment
This step is omitted for now and will be added later…
-
Deploy Nacos cluster in K8s (registration and configuration center)
-
Deploy Seata distributed transactions in k8s
-
Deploy mysql, redis, rabbitmq, minio, xxl-job on linux
Deploy microservice program
Prepare namespace
kubectl create namespace wms-dev
Deployment service
kubectl apply -f gateway.yaml
For other module deployment services, please refer to the gateway module.
Deploy microservice front-end
Write DockerFile file
FROM nginx COPY dist /usr/share/nginx/html/ EXPOSE 80
Build image
docker build -t wms-web:v1 -f Dockerfile .
Mirror tag
docker tag wms-web:v1 192.168.0.127:8084/onlee/wms-web:v1
Push to mirror warehouse
docker push 192.168.0.127:8084/onlee/wms-web:v1
Service orchestration (web.yaml)
apiVersion: apps/v1 Kind: Deployment metadata: labels: app: wms-web name: wms-web namespace: wms-dev spec: progressDeadlineSeconds: 600 replicas: 1 selector: matchLabels: app: wms-web strategy: rollingUpdate: maxSurge: 50% maxUnavailable: 50% type: RollingUpdate template: metadata: labels: app: wms-web spec: imagePullSecrets: - name: registry-harbor containers: - image: 192.168.0.127:8084/onlee/wms-web:v1 imagePullPolicy: Always name: app ports: - containerPort: 80 protocol:TCP resources: limits: cpu: 300m memory: 600Mi terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy:ClusterFirst restartPolicy: Always terminationGracePeriodSeconds: 30
Deployment service
kubectl apply -f web.yaml
Microservices are released to the outside world
Through the entire microservice architecture, we can see that only the gateway and front-end need to expose services.
NorePort mode exposed
gateway exposed to the outside world
gateway-nortport.yaml
--- apiVersion: v1 Kind: Service metadata: name: gateway namespace: wms-dev spec: ports: - port: 8901 name: gateway protocol: TCP targetPort: 8901 nodePort: 32074 selector: project: wms app: gateway type: NodePort
Front end exposed to the outside world
web-noreport.yaml
--- apiVersion: v1 Kind: Service metadata: labels: app: wms-web name: wms-web namespace: wms-dev spec: ports: - name: http port: 80 protocol:TCP targetPort: 80 nodePort: 32248 selector: app: wms-web sessionAffinity: None type: NodePort
Ingress mode exposed
https://blog.csdn.net/qq_40722827/article/details/127929141
gateway exposed to the outside world
--- apiVersion: networking.k8s.io/v1 Kind: Ingress metadata: name: gateway namespace: wms-dev annotations: kubernetes.io/ingress.class: "nginx" nginx.ingress.kubernetes.io/backend-protocol: "HTTP" spec: rules: - host: gateway.wms.com http: paths: - path: / pathType: Prefix backend: service: name: gateway port: number: 8901 --- apiVersion: v1 Kind: Service metadata: name: gateway namespace: wms-dev spec: ports: - port: 8901 name: gateway selector: project: wms-dev app: gateway
Front end exposed to the outside world
--- apiVersion: networking.k8s.io/v1 Kind: Ingress metadata: name: wms-web namespace: wms-dev annotations: kubernetes.io/ingress.class: "nginx" nginx.ingress.kubernetes.io/backend-protocol: "HTTP" spec: rules: -host: dev.wms.com http: paths: - path: / pathType: Prefix backend: service: name: wms-web port: number: 80 --- apiVersion: v1 Kind: Service metadata: labels: app: wms-web name: wms-web namespace: wms-dev spec: ports: - name: http protocol: TCP port: 80 targetPort: 80 type:ClusterIP selector: app: wms-web sessionAffinity: None
At this point, all microservices have been migrated to Kubernetes containers.
Putting what we did manually above into an automated deployment process through components such as Jenkins involves DevOps-related knowledge. This section will be written next.
There are still some imperfections in the above content, which will be continuously improved in the future.
Source: blog.csdn.net/qq_40722827/
article/details/127958192
Back-end exclusive technology group
To build a high-quality technical exchange community, HR personnel engaged in programming development and technical recruitment are welcome to join the group. Everyone is also welcome to share their own company’s internal information, help each other, and make progress together!
Speak in a civilized manner, focusing on
communication technology
,recommendation for positions
, andindustry discussion
Advertisers are not allowed to enter, and do not trust private messages to prevent being deceived.