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< ...
随机推荐
- DataX-ElasticSearch(写)
DataX写入ElasticSearch 1 快速介绍 数据导入elasticsearch的插件 2 实现原理 使用elasticsearch的rest api接口, 批量把从reader读入的数据写 ...
- VC读取文件内容
// chopper.cpp : Defines the entry point for the console application. // #include "stdafx.h&quo ...
- ajax设置Access-Control-Allow-Origin实现跨域访问
ajax跨域访问 1.jsonp方法,jsonp方法是一种非官方方法,这种方法只支持GET方式, 不如POST方式安全.(即使使用jquery的jsonp方法,type设为POST, 也会自动变为GE ...
- 在Silverlight中使用SESSION
首先Session是运行在服务器上的,而Silverlight运行在客户端.因此在Silverlight中使用SESSION的说法并不准确, 只因大家经常这样搜索才起这个名字. 首先Session ...
- SQL Server中的执行引擎入门
简介 当查询优化器(Query Optimizer)将T-SQL语句解析后并从执行计划中选择最低消耗的执行计划后,具体的执行就会交由执行引擎(Execution Engine)来进行执行.本文旨在 ...
- POJ - 2195 最小费用最大流
题意:每个人到每个房子一一对应,费用为曼哈顿距离,求最小的费用 题解:单源点汇点最小费用最大流,每个人和房子对于建边 #include<map> #include<set> # ...
- ural 2022 Riding a Toad
2022. Riding a Toad Time limit: 1.0 secondMemory limit: 64 MB A tribe of leafmen live in the old for ...
- (转)Android 弹软键盘时listview的变化控制
本文转自于:http://blog.csdn.net/hellohaifei/article/details/9377483 问题描述:界面中有三部分,上面是标题栏,中间是Listview,下面是输入 ...
- 剑指offer--11.数组中出现次数超过一半的数字
unique(), count()函数好用 ---------------------------------------------------------------------- 时间限制:1秒 ...
- c语言%.*s是什么
int i; ;i<;i++) printf("%.*s%s\n", i, " ", "########"); ; *用来指定宽度,对 ...