k8s部署springboot项目
1.Dockerfile
FROM base/jre1.8-chinese:latest
ENV HOME /app
##设置控制台字符集编码
ENV LANG C.UTF-8
###设置docker容器的时间
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD earthquake-resp-creator-0.0.1-SNAPSHOT.jar ${HOME}/earthquake-resp-creator-0.0.1-SNAPSHOT.jar
WORKDIR ${HOME}
EXPOSE 8083
ENTRYPOINT ["java","-jar","-Xms2048m", "-Xmx4096m","earthquake-resp-creator-0.0.1-SNAPSHOT.jar","--spring.config.local=application.properties"]
2.yaml文件
apiVersion: v1
kind: ConfigMap
metadata:
name: earthquake-resp-creator
namespace: dz-piecloud-business
data:
application.properties: |
server.port=8083
server.servlet.context-path=/v1/resp/creator
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://*.*.*.*:*/db_base?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
spring.datasource.username=
spring.datasource.password=
# mybatis
mybatis.mapper-locations=classpath:/Mapper/*.xml
mybatis.type-aliases-package=cn.piesat.entity
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.call-setters-on-nulls=true
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
generate.resp.file.py=/pie/data/earthquake-share/common-transform/generate_resp_file.py
resp.file.out.path=/pie/data/earthquake-share/resp/respOut
json.out.path=/pie/data/earthquake-share/resp/jsonOut
# resp.file.out.path=/data/dz-server/common-services/earthquake-resp-creator/out/respOut
# json.out.path=/data/dz-server/common-services/earthquake-resp-creator/out/jsonOut
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: earthquake-resp-creator
namespace: dz-piecloud-business
spec:
replicas: 1
selector:
matchLabels:
name: earthquake-resp-creator
template:
metadata:
labels:
name: earthquake-resp-creator
spec:
nodeSelector:
dz-business-common: "true"
hostAliases:
- ip: "*.*.*.*"
hostnames:
- "myhbase"
containers:
- name: earthquake-resp-creator
image: dz-server/earthquake-resp-creator:latest
imagePullPolicy: Always
ports:
- containerPort: 8083
volumeMounts:
- name: configmap-volume
mountPath: /app/application.properties
subPath: application.properties
- name: data
mountPath: /pie/data
- name: out
mountPath: /data
volumes:
- name: configmap-volume
configMap:
name: earthquake-resp-creator
items:
- key: application.properties
path: application.properties
- name: data
hostPath:
path: /pie/data
- name: out
hostPath:
path: /data
---
apiVersion: v1
kind: Service
metadata:
namespace: dz-piecloud-business
name: earthquake-resp-creator
labels:
app: earthquake-resp-creator
spec:
type: NodePort
selector:
name: earthquake-resp-creator
ports:
- port: 8083
targetPort: 8083
nodePort: 31173
3.restart.sh
#!/bin/bash
kubectl delete -f earthquake-resp-creator.yaml
sleep 3
docker rmi -f dz-server/earthquake-resp-creator:latest
docker build -t dz-server/earthquake-resp-creator:latest .
docker push dz-server/earthquake-resp-creator:latest
kubectl apply -f earthquake-resp-creator.yaml