gpt4 book ai didi

kubernetes - 在 pod 生命周期启动后 Hook 中使用 curl 命令

转载 作者:行者123 更新时间:2023-12-05 04:46:05 27 4
gpt4 key购买 nike

我正在尝试使用 curl 为我的 pod 添加一个 poststart Hook ,比如向我的 slack channel 发送消息在 shell 中,命令如下所示

curl -d "text=Hi I am a bot that can post messages to any public channel." -d "channel=C1234567" -H "Authorization: Bearer xoxb-xxxxxxxxxxxxxxxx" -X POST https://slack.com/api/chat.postMessage

在我的 pod 定义中,我试过这样的东西

apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod
spec:
containers:
- name: test-container
image: curlimages/curl
env:
- name: TOKEN
valueFrom:
configMapKeyRef:
name: my-config
key: token
command: ["sleep"]
args: ["3000"]
lifecycle:
postStart:
exec:
command:
- "sh"
- "-c"
- |
curl -d "text=Hi going to start." -d "channel=C1234567" -H "Authorization: Bearer $(TOKEN)" -X POST https://slack.com/api/chat.postMessage

与 container->command 不同,它有 args 参数,我可以用引号传递多行命令,但在 lifecycle->poststart->exec->command 中它不支持 args 参数

我也试过,但是没有运气

command: ["curl","-d","text=Hi going to start.",....]

但我从来没有收到我的 slack 消息

我的问题是,如何在 lifecycle->poststart->exec->command 中传递带引号的长 curl 命令?

最佳答案

最后用{}替换()解决了要在命令中使用环境变量,它应该是 ${TOKEN}

关于kubernetes - 在 pod 生命周期启动后 Hook 中使用 curl 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68947359/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com