来自 K8S POD 的 CURL
CURL from K8S POD
我正在尝试 运行 通过将环境变量的值作为路径参数传递给 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
我不确定这有什么问题。任何指针都会有所帮助。
这里的问题是您需要 shell 来评估环境变量。
您的命令应如下所示:
command:
- /bin/sh
- -c
- curl -X DELETE "http://application:8080/api/customer/$CUSTOMER_ID"
我正在尝试 运行 通过将环境变量的值作为路径参数传递给 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
我不确定这有什么问题。任何指针都会有所帮助。
这里的问题是您需要 shell 来评估环境变量。
您的命令应如下所示:
command:
- /bin/sh
- -c
- curl -X DELETE "http://application:8080/api/customer/$CUSTOMER_ID"