定时任务迁移Kubernetes指南

1、搞定基础镜像:

docker pull openjdk:8-jre-alpine
docker tag openjdk:8-jre-alpine 10.204.82.15/kubernetes/openjdk:8-jre-alpine
docker push 10.204.82.15/kubernetes/openjdk:8-jre-alpine

2、应用打包mvn package

定时任务迁移Kubernetes指南_第1张图片

3、编写Dockerfile构建镜像

FROM 10.204.82.15/kubernetes/openjdk:8-jre-alpine

COPY target/cronjob-demo-1.0-SNAPSHOT.jar /cronjob-demo.jar

ENTRYPOINT ["java", "-cp", "/cronjob-demo.jar", "com.mooc.demo.cronjob.Main"]
docker build -t cronjob:v1 .

docker tag cronjob:v1 10.204.82.15/kubernetes/cronjob:v1

 4、编写cronjob.yaml

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: cronjob-demo
spec:
  schedule: "*/1 * * * *"
  successfulJobsHistoryLimit: 3
  suspend: false
  concurrencyPolicy: Forbid
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            app: cronjob-demo
        spec:
          restartPolicy: Never
          containers:
          - name: cronjob-demo
            image: 10.204.82.15/kubernetes/cronjob:v1

5、容器启动

kubectl apply -f cronjob.yaml

kubectl get pods -o wide

 

你可能感兴趣的:(kubernetes,容器,云原生)