docker - curl命令参数上的YAML解析错误
问题描述
我正在尝试在 k8s 中创建一个小型 cronjob,它只是在busybox 容器中使用 curl 执行 HTTP Post。格式是错误的,我不知道我必须改变什么。
我试过用谷歌搜索我收到的错误消息,并以各种方式更改 curl 命令的格式,但没有任何成功。
apiVersion: batch/v1beta1
kind: CronJob
#namespace: test
metadata:
name: test-cron
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: test-cron
image: busybox
args:
- /bin/sh
- -c
- curl "https://test-es01.test.svc.clu01.test.local:9200/logs_write/_rollover" -H 'Content-Type: application/json' -d '{"conditions: {"max_size": "5gb"}}'
restartPolicy: OnFailure
然后我尝试运行该文件:
kubectl -n test apply -f test-cron.yaml
并得到以下错误:
error: error parsing test-cron.yaml: error converting YAML to JSON: yaml: line 20: mapping values are not allowed in this context
有谁知道格式的问题是什么?
谢谢
解决方案
thats because your curl
command contains semicolon so yaml thinks you are trying to define an object. to fix the error:
- escape every
"
with backlslash:\"
- wrap the entire line with
"
therefore-
- curl "https://test-es01.test.svc.clu01.test.local:9200/logs_write/_rollover" -H 'Content-Type: application/json' -d '{"conditions: {"max_size": "5gb"}}'
should be escaped to
- "curl \"https://test-es01.test.svc.clu01.test.local:9200/logs_write/_rollover\" -H 'Content-Type: application/json' -d '{\"conditions: {\"max_size\": \"5gb\"}}'\n"
http://www.yamllint.com/ is a great place to track down such bugs.
推荐阅读
- reactjs - 无法让 Redux mapStateToProps 在四分之一的组件上工作
- amazon-web-services - ALB 访问日志请求发起者域
- html - 如何在任何屏幕上使用最小宽度和最小高度来适应整个 HTML 页面?
- google-cloud-platform - 如何在 GCP 中关闭项目级别的开放互联网端口?
- javascript - 事件监听源js文件
- angular - Guard中的Angular canActivate函数执行了两次
- scala - Spark RDD 不变性混淆
- function - Eloquent JavaScript Book : 不懂例子
- excel - 如何在网页中使用 VBA 触发隐藏字段
- python - 在 python 中从 MySql 数据库中获取数据时出错