Openshift或者K8S上部署xxl-job

本案例以版本2.3.0为例

1. package jar by source code

source code:
https://github.com/xuxueli/xxl-job/blob/2.3.0/

2. init mysql database

sql code:
https://github.com/xuxueli/xxl-job/blob/2.3.0/doc/db/tables_xxl_job.sql

3. build image:

refer to:
https://github.com/xuxueli/xxl-job/blob/2.3.0/xxl-job-admin/Dockerfile

FROM openjdk:8-jre-slim
MAINTAINER xuxueli

ENV PARAMS=""

ENV TZ=PRC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

ADD target/xxl-job-admin-*.jar /app.jar

ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /app.jar $PARAMS"]

4. deploy on ocp

kind: Deployment
apiVersion: apps/v1
metadata:
  name: xxl-job
  labels:
    app.kubernetes.io/instance: xxl-job
spec:
  replicas: 1
  selector:
    matchLabels:
      app: xxl-job
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: xxl-job
        deployment: xxl-job
    spec:
      containers:
        - resources:
            limits:
              cpu: '1'
              memory: 4Gi
            requests:
              cpu: 500m
              memory: 4Gi
          readinessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds: 30
            timeoutSeconds: 1
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          name: xxl-job
          livenessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds: 30
            timeoutSeconds: 1
            periodSeconds: 30
            successThreshold: 1
            failureThreshold: 3
          env:
            - name: PARAMS
              value: '--spring.datasource.url=jdbc:mysql://xxx:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai  --spring.datasource.username=xxx --spring.datasource.password=xxx' ###这里需要填写mysql的连接信息
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          image: 'xxx' ## xxl-job的镜像地址
      restartPolicy: Always
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  revisionHistoryLimit: 1
---
kind: Service
apiVersion: v1
metadata:
  name: xxl-job
spec:
  ports:
    - name: 8080-tcp
      protocol: TCP
      port: 8080
      targetPort: 8080
  type: ClusterIP
  selector:
    deployment: xxl-job
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
  name: xxl-job
spec:
  ingressClassName: openshift-default
  rules:
    - host: xxx ## 这边填写域名
      http:
        paths:
          - path: /xxl-job-admin
            pathType: Prefix
            backend:
              service:
                name: xxl-job
                port:
                  name: 8080-tcp

5. visit xxl-job web

初始的
username: admin
password: 123456

你可能感兴趣的:(openshift,kubernetes,容器)