就绪探针失败,状态码:401

时间:2020-02-06 19:52:11

标签: spring-boot kubernetes

我试图按如下所示在部署yaml文件上启用“就绪”探针,但我收到“就绪”探针失败:HTTP probe failed with statuscode: 401,我通过解密密码进行了验证,并且我的授权代码正确。

spec:
  containers:
  - name: mycontainer
    image: myimage
    env:
      - name: MY_SECRET
        valueFrom:
          secretKeyRef:
            name: actuator-token
            key: token
    livenessProbe:
        httpGet:
          path: test/actuator/health
          port: 9001
          httpHeaders:
          - name: Authorization
            value: $MY_SECRET

更新

如果我在值字段中对令牌进行硬编码..它可以正常工作。

我们非常感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

只能在容器内部访问此秘密,因此常规的活动探针(在k8s内部容器中运行)无法解决此问题,请阅读here

一种解决方法是在pod本身中以命令的形式运行livenessProbe:

 livenessProbe:
    exec:
      command:
      - bash 
      - "-c" 
      - | 
        curl http://localhost:9001/test/actuator/health --header "Authorization: $MY_TOKEN"

您可能需要弄乱curl语法才能使其正常工作