使用秘密的httpHeaders定义livenessProbe

时间:2017-01-21 00:54:17

标签: kubernetes kubernetes-health-check

我想定义一个带有httpHeader的livenessProbe,其值为secret。

此语法无效:

livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
    httpHeaders:
      - name: X-Custom-Header
        valueFrom:
          secretKeyRef:
            name: my-secret-key
            value: secret

如果我将值my-secret-key指定为secret作为名为MY_SECRET_KEY的环境变量,则可以使用以下内容:

livenessProbe:
  exec:
    command:
      - curl
      - --fail
      - -H
      - "X-Custom-Header: $MY_SECRET_KEY"
      - 'http://localhost:8080/healthz'

不幸的是,由于报价的评估方式,它并不存在。如果我直接在容器上键入命令curl --fail -H "X-Custom-Header: $MY_SECRET_KEY" http://localhost:8080/healthz,它就可以工作。

我还试过很多单引号组合并转义双引号。

有没有人知道解决方法?

2 个答案:

答案 0 :(得分:1)

我能想到的一个解决方法是创建一些bash脚本来运行此运行状况检查,并照常将您的机密数据放入环境中。

答案 1 :(得分:0)

以下是带有curl和wget的示例:

exec:
command:
  - /bin/sh
  - -c
  - "curl -H 'Authorization: Bearer $(AUTH_TOKEN)' 'http://example.com'"

exec:
  command:
  - /bin/sh
  - -c
  - "wget --spider --header \"Authorization: Bearer $AUTH_TOKEN\" http://some.api.com/spaces/${SPACE_ID}/entries"