1、mvn打jar包:mvn clean package

2、上传到linux指定目录

3、编写Dockerfile文件,内容如下

FROM openjdk:8-jdk-alpine
ADD ./jimureport-demo-1.0.0-SNAPSHOT.jar /usr/local/app/jimureport-demo-1.0.0-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar", "/usr/local/app/jimureport-demo-1.0.0-SNAPSHOT.jar"]
EXPOSE 9000

4、生成镜像

docker build -f Dockerfile -t 192.168.111.243:8858/senge-test/senge-jimureport-demo:v1 .

注意:“192.168.111.243:8858/senge-test”表示harbor创建的项目路径

5、查看镜像是否成功

6、命令登录&推送

#登录harbor
docker login -u admin -p Harbor12345 http://192.168.111.243:8858/
#推送
docker push 192.168.111.243:8858/senge-test/senge-jimureport-demo:v1

推送成功,如下图:

7、登录harbor管理页面,查看是否成功

8、编写deployment.yaml文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jimureport-demo-deployment
  namespace: dev
  labels:
    app: jimureport-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jimureport-demo
  template:
    metadata:
      labels:
        app: jimureport-demo
    spec:
      containers:
        - name: senge-jimureport-demo
          image: 192.168.111.243:8858/senge-test/senge-jimureport-demo:v1
          ports:
            - containerPort: 9000

9、编写service.yaml(和deployment.yaml中的“app”值要一致)

****此文件是配置为外网可以访问:通过32260端口号

apiVersion: v1
kind: Service
metadata:
  name: jimureport-demo-service
  namespace: dev
spec:
  selector:
    app: jimureport-demo
  ports:
    - name: http
      port: 9000
      targetPort: 9000
      nodePort: 32260
  type: NodePort

10、文件生效

kubectl apply -f deployment.yaml
kubectl apply -f service.yaml

11、查看是否成功

#deployment是否成功
kubectl get pods -n dev

#service是否成功
kubectl get svc -n dev

12、访问程序

​http://192.168.111.241:32260/jmreport/list?token=123​

13、删除服务

#根据.yaml文件删除
kubectl delete -f deployment.yaml
kubectl delete -f service.yaml
#根据name删除
kubectl delete svc -n dev jimureport-service
kubectl delete deploy -n dev jimureport-demo-deployment-5b75d9cb8f-hvj5q

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐