Kubernetes CronJob - 多个 CronJob 配置不起作用

Kubernetes CronJob - Multiple CronJob configuration is not working

我必须 运行 Kubernetes (AWS-EKS) 中的两个 CronJobs,并且我有以下配置。当我应用模板时,只会创建一个 CronJob。被创建的总是第二个。所以看起来第一个被第二个覆盖了。我无法弄清楚我做错了什么。

# Source: deploy-k8s-app/templates/multicron.yaml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  labels:
    app: my-app
  name: my-app
  namespace: commercial
spec:
  schedule: '5/15 * * * *'
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      parallelism: 1
      completions: 1
      activeDeadlineSeconds: 900
      template:
        metadata:
          labels:
            app: my-app
          name: my-app
          namespace: commercial
        spec:
          containers:
          - env:
            - name: SERVER_SERVLET_CONTEXT_PATH
              value: "/my-app"
            - name: IS_JACOCO_ENABLED
              value: "false"
            - name: SPRING_PROFILES_ACTIVE
              value: "int-dc4"
            - name: METRICS_ADDRESS
              value: "NA"
            - name: APP_MODULE
              value: "expand"
            - name: JAVA_TOOL_OPTIONS
              value: "-Xms256M -Xmx512M"
            image: "xxxxx.dkr.ecr.us-east-1.amazonaws.com/my-ecr:my-app-latest-10"
            imagePullPolicy: IfNotPresent
            name: my-app
            ports:
            - name: http
              containerPort: 8080
              protocol: TCP
            resources:
              limits:
                cpu: 160m
                memory: 1024Mi
              requests:
                cpu: 100m
                memory: 256Mi
            volumeMounts:
            - name: apps-logs
              mountPath: /var/log/containers
            - name: fluentdconf
              mountPath: /fluentd/etc
          - name: fluentd
            image: fluent/fluentd-kubernetes-daemonset:v1.11.2-debian-cloudwatch-1.0
            env:
            - name: REGION
              value: us-east-1
            - name: AWS_REGION
              value: us-east-1
            - name: CLUSTER_NAME
              value: MY-EKS-Cluster
            - name: CI_VERSION
              value: "k8s/1.0.1"
            - name: LOG_GROUP_NAME
              value: /aws/containerinsights/MY-EKS-Cluster/springapp
            resources:
              limits:
                cpu: 160m
                memory: 1024Mi
              requests:
                cpu: 100m
                memory: 256Mi
            volumeMounts:
            - name: fluentdconf
              mountPath: /fluentd/etc
            - name: apps-logs
              mountPath: /var/log/containers
          volumes:
            - name: fluentdconf
              configMap:
                name: fluentd-spring-config
            - name: apps-logs
              emptyDir: {}
            - name: my-app-shared
              emptyDir: {}
          restartPolicy: OnFailure
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  labels:
    app: my-app
  name: my-app-addl
  namespace: commercial
spec:
  schedule: '15/30 * * * *'
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      parallelism: 1
      completions: 1
      activeDeadlineSeconds: 1800
      template:
        metadata:
          labels:
            app: my-app
          name: my-app
          namespace: commercial
        spec:
          containers:
          - env:
            - name: SERVER_SERVLET_CONTEXT_PATH
              value: "/my-app"
            - name: IS_JACOCO_ENABLED
              value: "false"
            - name: SPRING_PROFILES_ACTIVE
              value: "int-dc4"
            - name: METRICS_ADDRESS
              value: "NA"
            - name: APP_MODULE
              value: "expand"
            - name: JAVA_TOOL_OPTIONS
              value: "-Xms256M -Xmx512M"
            image: "xxxxx.dkr.ecr.us-east-1.amazonaws.com/my-ecr:my-app-latest-10"
            imagePullPolicy: IfNotPresent
            name: my-app
            ports:
            - name: http
              containerPort: 8080
              protocol: TCP
            resources:
              limits:
                cpu: 160m
                memory: 1024Mi
              requests:
                cpu: 100m
                memory: 256Mi
            volumeMounts:
            - name: apps-logs
              mountPath: /var/log/containers
            - name: fluentdconf
              mountPath: /fluentd/etc
          - name: fluentd
            image: fluent/fluentd-kubernetes-daemonset:v1.11.2-debian-cloudwatch-1.0
            env:
            - name: REGION
              value: us-east-1
            - name: AWS_REGION
              value: us-east-1
            - name: CLUSTER_NAME
              value: MY-EKS-Cluster
            - name: CI_VERSION
              value: "k8s/1.0.1"
            - name: LOG_GROUP_NAME
              value: /aws/containerinsights/MY-EKS-Cluster/springapp
            resources:
              limits:
                cpu: 160m
                memory: 1024Mi
              requests:
                cpu: 100m
                memory: 256Mi
            volumeMounts:
            - name: fluentdconf
              mountPath: /fluentd/etc
            - name: apps-logs
              mountPath: /var/log/containers
          volumes:
            - name: fluentdconf
              configMap:
                name: fluentd-spring-config
            - name: apps-logs
              emptyDir: {}
            - name: my-app-shared
              emptyDir: {}
          restartPolicy: OnFailure

kubectl apply -f multicron.yaml
cronjob.batch/my-app-addl created 

(期望:创建两个CronJob。实际:只创建了一个,也就是第二个)

kubectl get cronjob -n commercial
NAME            SCHEDULE        SUSPEND   ACTIVE   LAST SCHEDULE   AGE
my-app-addl     15/30 * * * *   False     0        <none>          9s

(期望:创建两个CronJob。实际:只创建了一个,也就是第二个)

谢谢! 阿比拉什

我可以通过在 CronJob 条目之间使用 --- 分隔文档来解决这个问题