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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weiyubuxxx

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值