Kubernetes cronjob args与环境变量

时间:2018-11-26 19:31:48

标签: docker curl kubernetes

我正在尝试在curl中的容器内执行gke命令。

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: app
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: app
            image: appropriate/curl
            env:
            - name: URL
              value: "https://app.com"
            - name: PASSWORD
              value: "pass"
            args: ["-vk", "-H", "\"Authorization: Bearer $(PASSWORD)\"", "$(URL)"]
          restartPolicy: OnFailure

错误:

curl: option -vk -H "Authorization: Bearer pass" https://app.com: is unknown

我只是不知道如何使用环境变量通过curl字段执行args

此curl命令在我的PC中有效。
我在做什么错了?
如何将env var与容器curl命令args集成在一起?

1 个答案:

答案 0 :(得分:2)

您无需将auth标头用引号引起来,kubernetes会为您完成。

Get-ADPrincipalGroupMembership (Get-ADComputer ComputerName) | select-object name

您可以执行以下操作来测试输出yaml:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: app
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: app
            image: appropriate/curl
            env:
            - name: URL
              value: "app.com"
            - name: PASSWORD
              value: "pass"
            args: ["-vk", "-H", "Authorization: Bearer $(PASSWORD)", "$(URL)"]
          restartPolicy: OnFailure

表明最终输出很好

kubectl apply -f job.yaml -o yaml --dry-run

我用https://requestbin.fullcontact.com/进行了测试,并且承载令牌成功通过传递