1.idea新建一个springboot web程序。(controller 路径我设为 /test)
2.pakage打包,并且更名为app.jar
3,制作Dockerfile
- # Docker image for springboot file run
- # VERSION 0.0.1
- # Author: eangulee
- # 基础镜像使用java
- # FROM java:8
- FROM openjdk:8u292-jre-buster
- # 作者
- MAINTAINER eangulee <jim123123@163.com>
- ENV TZ=Asia/Shanghai
- RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
- # VOLUME 指定了临时文件目录为/tmp。
- # 其效果是在主机 /var/lib/docker 目录下创建了一个临时文件,并链接到容器的/tmp
- VOLUME /tmp
- # 将jar包添加到容器中并更名为app.jar
- ADD app.jar app.jar
- # 运行jar包
- RUN bash -c 'touch /app.jar'
- ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
4. docker build -t test2 .
5.docker tag test2 changyw/test2
6.docker push changyw/test
7.制作deploy.yaml
- apiVersion: apps/v1beta2
- kind: Deployment #部署
- metadata:
- name: springboot-app
- spec:
- replicas: 2 #2个副本
- selector:
- matchLabels:
- app: springboot-app
- template:
- metadata:
- labels:
- app: springboot-app
- spec:
- containers:
- - name: springboot-app
- image: changyw/test2 #刚刚push到阿里云上的镜像地址
- ports:
- - containerPort: 8080 #默认springboot端口
-
- ---
-
- apiVersion: v1
- kind: Service
- metadata:
- name: springboot-app
- spec:
- selector:
- app: springboot-app #选中上面的 Deployment
- ports:
- - port: 7003 #对外7003端口
- targetPort: 8080
8.执行 kubectl apply -f deployment.yaml
9.查看运行log
10.curl访问 curl http://xxxxx:7003/test