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< ...
随机推荐
- vector对象
vector是模板而非类型,由vector生成的类型必须包含vector中元素的类型,例如vector<int> 定义和初始化vector对象: vector<T> v1 ...
- web容器调用Filter和Servlet顺序学习
web容器调用Filter和Servlet顺序学习 一直对Filter和Servlet在哪里被web容器调用迷惑,后查看tomcat源码,揭开了其面纱.1. 下面是一个简单的时序图: 2. 对上 ...
- UOJ67 新年的毒瘤
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- Git---之上传远程仓库
一:在GitHub上注册账号 官网 : https://github.com/ 二:与远程仓库关联 在本地生成ssh key 运行命令 ssh-keygen -t rsa -C "50 ...
- alias 中使用awk
alias hehistory10='history |awk "{print \$2}"|sort|uniq -c|sort -rn|head -10' $要转义
- iTerm2 + Oh My Zsh
iTerm2 http://iterm2.com/downloads.html https://iterm2.com/downloads/stable/iTerm2-2_1_4.zip Oh My Z ...
- ural 2016 Magic and Science
2016. Magic and Science Time limit: 1.0 secondMemory limit: 64 MB Scientists who specialize in witch ...
- android 取mac若干问题
问题一:Error:Error: The WIFI_SERVICE must be looked up on the Application context or memory will leak o ...
- android:descendantFocusability用法简析(转)
开发中很常见的一个问题,项目中的listview不仅仅是简单的文字,常常需要自己定义listview,自己的Adapter去继承BaseAdapter,在adapter中按照需求进行编写,问题 ...
- 数论板子——来自Loi_black
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> usin ...