簡體   English   中英

Kubernetes - 將 cronjob 計划傳遞給容器 env

[英]Kubernetes - Pass the cronjob schedule to container env

假設我有這樣的 CronJob 定義:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: "*/1 * * * *"  # pass this value to container's env
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: cronjob-test
            image: myiamge:latest
            imagePullPolicy: Never
            env:
            - name: schedule
              value: # pass the schedule value here 
          restartPolicy: OnFailure

如何將schedule值從CronJob.specCronJob.spec.jobTemplate.spec.template.spec.containers.env 甚至可能嗎?

通常,我會做這樣的事情:

valueFrom:
  fieldRef:
    fieldPath: spec.timezone

但在這種情況下,它不會得到這個值。

提前感謝您的幫助!

不幸的是,當CronJob定義時, schedule應該是一定的值。 並且fieldRef引用的值在您的 pod(container) 運行時作為 env 變量傳遞給其容器,因此fieldRef無法在 CronJob 定義時傳遞某個值來schedule 通常,在這個用例中,模板格式是合適的。 例如像 Helm 和類似的。

apiVersion: batch/v1beta1
kind: CronJob
:
spec:
  schedule: {{ .Values.schedule }}

您可以使用 Helm 格式替換schedule值。

// Values.yaml in the Helm format
schedule: '"*/1 * * * *"'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM