POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>XXXXXXXXXX</groupId>
<artifactId>XXXXXXX</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build> <properties>
<redis.version>2.9.0</redis.version>
</properties>
<dependencies>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${redis.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>dist</id>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>含有main函数的类的全名</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<!-- Add config folder into classpath of MANIFEST -->
<manifestEntries>
<Class-Path>src/main/resources</Class-Path>
</manifestEntries>
</archive>
<classesDirectory></classesDirectory>
<!--<excludes> <exclude>*.conf</exclude> <exclude>*.xml</exclude>
</excludes> -->
</configuration>
</plugin>
<!-- Copy dependency Jars to lib folder -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

assembly.xml

<assembly>
<id>dist</id>
<formats>
<format>zip</format>
</formats>
<!-- set to false the archive created will unzip its content to the current directory. -->
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<!-- copy file from target folder -->
<fileSet>
<directory>${basedir}/target</directory>
<includes>
<include>*.jar</include>
</includes>
<outputDirectory></outputDirectory>
</fileSet>
<fileSet>
<directory>${basedir}/target/lib</directory>
<outputDirectory>lib</outputDirectory>
</fileSet>
<!-- copy file from source folder -->
<fileSet>
<directory>${basedir}/dist</directory>
<outputDirectory></outputDirectory>
<fileMode>744</fileMode>
<lineEnding>unix</lineEnding>
<includes>
<include>start</include>
<include>stop</include>
</includes>
</fileSet>
</fileSets>
</assembly>

logback.xml

<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->
<configuration>
<property name="APP_NAME" value="your application name"/>
<property name="SERVICE_NAME" value="your service name" />
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH:-/var/log/${APP_NAME}.log}</file>
<encoder>
<pattern>[%date{ISO8601}] [${SERVICE_NAME}] [${HOSTNAME}] [%thread] [%-5level] [%logger{36}] :%msg%n
</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/${APP_NAME}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>60</maxHistory>
<totalSizeCap>20GB</totalSizeCap>
</rollingPolicy>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>512</queueSize>
<appender-ref ref="ROLLING"/>
</appender>
<logger name="ImagesDownLoad" additivity="false">
<level value="INFO" />
<appender-ref ref="STDOUT" />
</logger> <root level="INFO">
<appender-ref ref="ASYNC"/>
</root>
</configuration>

dockerfile

FROM openjdk:8-jre

ARG PACKAGE="XXXXXXXXXXXXX-1.0-SNAPSHOT-dist.zip"

COPY target/${PACKAGE} /${PACKAGE}
COPY XXX.jks /var/lib/XXX.jks RUN mkdir /build && \
unzip /${PACKAGE} -d /build EXPOSE 9000 ENTRYPOINT ["java", "-cp", "/build/*", "含有main的类全名"]

yaml文件:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: XXXXXX
spec:
schedule: "*/30 * * * *" // 每隔30分钟执行一次
jobTemplate:
spec:
template:
spec:
imagePullSecrets:
- name: XXXXXXXXX-key // pull image的时候,需要认证
containers:
- name: imagedownload
image: 私有image仓库的地址/imagedownloadjob:259
env:
- name: DB_HOST
value: "XXXXXXX"
restartPolicy: OnFailure

过程:

1: 在工程目录下:   mvn clean pcage -P dist           // 打包,安装POM中定义的dist的方式进行打包

2:  创建docker 镜像:

   docker build -t url/forecasting/imagedownloadjob:196 --compress --force-rm --build-arg VERSION=196 --build-arg                        MICROSERVICE=job.imagedownloadjob --build-arg REPOSITORY=url/forecasting/imagedownloadjob .

(  -t, --tag list                Name and optionally a tag in the

--compress                Compress the build context using gzip

--force-rm                Always remove intermediate containers

--build-arg list          Set build-time variables)

3:  推送docker镜像到私有仓库之前,先要登录一下docker仓库     docker login URL

把docker镜像推到私有仓库:

docker push url/forecasting/imagedownloadjob:196

通过pull命令验证是否推送成功
            docker pull url/forecasting/imagedownloadjob:196

        4:  kubectl create -f cronjob.yaml //创建job

              kubectl get cronjob hello //查看job状态

kubectl get jobs --watch // 查看

kubectl describe pod fail-1036623984-hxoas // 查看pod失败的原因

kubectl delete cronjob hello //删除cronjob

使用kubectl delete jobs –all可以删除当前namespaces下所有的job

  

最新文章

  1. PHP如何实现网址伪静态
  2. C#调用天气查询服务
  3. Linux下提示 bash: xxx command not found
  4. python常用小模块使用汇总
  5. FZU2169 shadow题解
  6. java&#23454;&#29616;&#25991;&#20214;&#21333;&#35789;&#39057;&#29575;&#32479;&#35745; topN top K
  7. CSS去除firefox点击链接时的虚线边框
  8. No.012:Integer to Roman
  9. jmeter随笔(23)--在csv中维护变量参数
  10. sublime text2 快捷键
  11. python自动化测试应用-番外篇--接口测试1
  12. Android开发技巧——实现底部图标文字的导航栏(已更新)
  13. gcc如何生成预编译头文件(.gch)
  14. MySQL如何系统学习
  15. Python爬虫入门之Urllib库的基本使用
  16. 培训班课程课时及费用管理系统V3.0,适合钢琴培训班、艺术培训班等
  17. vm虚拟机 模板机进行克隆导致centos 7.2 无法加载网卡
  18. ethereum/EIPs-1271 smart contract
  19. Java中部分常见语法糖
  20. ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) A

热门文章

  1. oracle 字典表查询
  2. Java循环日期
  3. MyEclipse+PyDev配置搭建Python开发环境
  4. UVA 11827 水
  5. aodh M版本新特性 - queue between alarm evaluator and alarm notifier
  6. 《Advanced Bash-scripting Guide》学习(十七):用more来查看gzip文件
  7. hdu6242 计算几何
  8. 51nod 1267 二分
  9. 去掉标题栏的方法(使用requestWindowFeature(Window.FEATURE_NO_TITLE);为什么失效?不仅失效,可能会挂)
  10. application.yml配置log日志