kubernetes 学习 创建cronjob
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
kubernetes 学习 创建cronjob的更多相关文章
- Kubernetes学习笔记(二):部署托管的Pod -- 存活探针、ReplicationController、ReplicaSet、DaemonSet、Job、CronJob
存活探针 Kubernetes可以通过存活探针(liveness probe)检查容器是否存活.如果探测失败,Kubernetes将定期执行探针并重新启动容器. 官方文档请见:https://kube ...
- Kubernetes学习之路(一)之概念和架构解析和证书创建和分发
1.Kubernetes的重要概念 转自:CloudMan老师公众号<每天5分钟玩转Kubernetes>https://item.jd.com/26225745440.html Clus ...
- Kubernetes 学习笔记(一):基础概念
个人笔记,仅本人查阅使用,不保证正确. 零.微服务 微服务架构专注于应用解耦合,通过将应用彻底地组件化和服务化,每个微服务只包含一个非常小的功能,比如权限管理.日志收集等等.由这一组微服务组合起来,提 ...
- Kubernetes学习之路目录
Kubernetes基础篇 环境说明 版本说明 系统环境 Centos 7.2 Kubernetes版本 v1.11.2 Docker版本 v18.09 Kubernetes学习之路(一)之概念和架构 ...
- kubernetes对象之cronjob
系列目录 类似于Linux的Cron模块,CronJob用来运行定时性任务,或者周期性.重复性任务.注意CronJob启动的是kubernetes中的Job,不是ReplicaSet.DaemonSe ...
- Kubernetes Job与CronJob(离线业务)
Kubernetes Job与CronJob(离线业务) Job Job分为普通任务(Job) 一次性执行 应用场景:离线数据处理,视频解码等业务 官方文档:https://kubernetes.i ...
- Kubernetes学习笔记(八):Deployment--声明式的升级应用
概述 本文核心问题是:如何升级应用. 对于Pod的更新有两种策略: 一是删除全部旧Pod之后再创建新Pod.好处是,同一时间只会有一个版本的应用存在:缺点是,应用有一段时间不可用. 二是先创建新Pod ...
- Kubernetes学习笔记_尚硅谷
https://www.bilibili.com/video/BV1w4411y7Go?p=1 一.K8s介绍 k8s是一个编排容器的工具,其实也是管理应用的全生命周期的一个工具,从创建应用,应用的部 ...
- Spring MVC 学习 -- 创建过程
Spring MVC 学习 -- 创建过程 Spring MVC我们使用的时候会在web.xml中配置 <servlet> <servlet-name>SpringMVC< ...
随机推荐
- each方法的简单使用
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/stric ...
- spark总结5 RDD
创建RDD 有两种方式 1 通过hdfs支持的文件系统创建 RDD, RDD里面没有真正要计算的数据,只记录了一下元数据 2 从过scala集合或者数组以并行化的方式创建RDD collect 把结果 ...
- 【[NOI2011]智能车比赛】(建图+spfa+坑爹精度)
过了这题我就想说一声艹,跟这个题死磕了将近6个小时,终于是把这个题死磕出来了.首先看到这个题的第一反应,和当初做过的一个房间最短路比较相似,然后考虑像那个题那样建边,然后跑最短路.(具体建边方法请参考 ...
- spring启动加载类,手动加载bean
方法一: public final class Assembler implements BeanFactoryPostProcessor { private static ConfigurableL ...
- numpy里*与dot与multiply
一.* , dot() multiply() 1, 对于array来说,(* 和 dot()运算不同, * 和 multiply()运算相同) *和multiply() 是每个元素对应相乘 do ...
- pg数据库表接口和数据导出
导出命令 pg_dump -U postgres --inserts -t human_info > D:\human_info_backup.sql testdb 命令说明 pg_dump:是 ...
- Angular各版本和组件下载
Angular各版本和组件下载:https://code.angularjs.org/
- Linux系统memcached安装
[memcached安装] Linux系统安装memcached可以自动安装,也可以手动编译安装,这里使用手动编译安装 1.Linux系统安装memcached,首先要先安装libevent库. 下载 ...
- Mysql 高级部分
MySQL 高级部分 (1)索引(index)..................................................................... 1 (2) ...
- Eclipse_插件_05_自动下载jar包源码插件
一.Java Source Attacher 1.下载 官网:http://marketplace.eclipse.org/content/java-source-attacher#.U5RmTePp ...