为什么 curl 在 kubernetes 中的 livenessProbe 中不起作用



我有一个像这样的liveessprobe

livenessProbe:
exec:
command:
- curl
- --fail
- -X POST
- http://localhost/test
- '-d "data"'

这个探针没有通过,我看到kubectl describe pods/pod_name错误

Liveness probe failed:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100     7    0     0  100     7      0     62 --:--:-- --:--:-- --:--:--    63
curl: (22) The requested URL returned error: 400

但是当我将相同的curl查询放到文件/tmp/a.sh

curl --fail -X POST http://localhost/test -d "data"
exit $?

并在此文件上设置活动探测

livenessProbe:
exec:
command:
- sh
- /tmp/a.sh

everythink工作,没有错误400从curl。当我手动进入容器并运行curl查询时,也可以。

为什么相同的命令在活动探针中不同的工作,当它被放在文件中?

将-X POST作为一个shell字传递,将导致Curl发送一个带有前导空格的HTTP方法POST

删除空格-XPOST工作

最新更新