来自K8S POD的CURL

时间:2019-09-24 12:14:20

标签: curl kubernetes kubernetes-pod

我试图通过传递Environment变量的值作为路径参数来运行curl命令。但是以某种方式未传递环境变量的值,而是传递了文字字符串 $ CUSTOMER_ID 。以下是我要配置的cron作业的定义。

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: test-cron-job
spec:
  schedule: "*/15 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: OnFailure
          containers:
            - name: test-cron-job
              image: myImage
              command: [
                "curl",
                "-X",
                "DELETE",
                "http://application:8080/api/customer/"$CUSTOMER_ID""
              ]
              env:        
                - name: CUSTOMER_ID
                  valueFrom:
                    configMapKeyRef:              
                      name: app-config-map              
                      key: customer_id
              volumeMounts:
              - name: app-config-map
                mountPath: /etc/app-config-map
          volumes:
            - name: app-config-map
              configMap:
                name: app-config-map

我不确定这有什么问题。任何指针都会有所帮助。

1 个答案:

答案 0 :(得分:2)

这里的问题是,您需要一个Shell来评估环境变量。

您的命令应如下所示:

command:
 - /bin/sh
 - -c
 - curl -X DELETE "http://application:8080/api/customer/$CUSTOMER_ID"