【问题标题】:using curl command in pod lifecycle poststart hooks在 pod 生命周期 poststart 挂钩中使用 curl 命令
【发布时间】:2021-10-27 00:52:19
【问题描述】:

我正在尝试使用 curl 为我的 pod 添加一个 poststart 挂钩,比如向我的 slack 频道发送一条消息 在 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 参数,我可以用引号传递多行命令,但在生命周期->poststart->exec->command 中它不支持 args 参数

我也尝试过,但没有运气

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

但我从来没有收到我的松弛消息

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

【问题讨论】:

  • 你已经说了它没有做什么,但你还没有说它在做什么——它执行@987654325 @(或curl)但是payload有问题?或者它不执行它们?还是无法解析 DNS 条目? TLS 配置错误?它会重新启动您的计算机?会发生什么?
  • 谢谢,我已经通过 ${TOKEN} 解决了这个问题

标签: kubernetes curl


【解决方案1】:

它终于通过将 () 替换为 {} 来解决 要在命令中使用环境变量,它应该是 ${TOKEN}

【讨论】:

    猜你喜欢
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多