要使用Spring Boot框架實現Java項目的自動化部署,可以按照以下步驟進行操作:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
FROM openjdk:8-jdk-alpine
COPY target/demo.jar demo.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","demo.jar"]
docker build -t demo .
docker tag demo:latest <your-docker-registry>/demo:latest
docker push <your-docker-registry>/demo:latest
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo
spec:
replicas: 3
selector:
matchLabels:
app: demo
template:
metadata:
labels:
app: demo
spec:
containers:
- name: demo
image: <your-docker-registry>/demo:latest
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: demo
spec:
selector:
app: demo
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: LoadBalancer