首页 > 解决方案 > 后端的readinessProbe路径是否需要在Endpoint openapi.yaml文件中声明?

问题描述

我正在部署一个作为 GKE 容器后端的项目,前端有一个 Cloud Endpoints API。它通过一个 Ingress 和 NodePort 服务。我已经在 ESP 容器上声明了一个就绪探测:

        readinessProbe:
          httpGet:
            path: /ping
            port: 8080

但是我观察到 /ping 路径必须在没有任何安全性的情况下在 openapi.yaml 中声明,否则它返回 404,如果声明了一些安全性定义,则返回 401。

这是预期的吗?我在 Endpoints Samples 存储库中看不到任何相关内容:

https://github.com/GoogleCloudPlatform/endpoints-samples/tree/master/k8s

标签: google-cloud-platformgoogle-kubernetes-enginegoogle-cloud-endpointsgoogle-cloud-networking

解决方案


我遇到了同样的问题,但似乎可以对 GCE 边车和最终的后端(例如您实际构建的 api)进行健康检查。

诀窍是,您的 api 的运行状况检查必须配置为云端点容器(而不是您的 api 容器)上的就绪探针。您检查的端点也必须没有针对它的安全性,因此它是可公开访问的(尽管您似乎也可以使用 api 密钥配置运行状况检查)。

我遵循了之前的建议,并将“healthz”参数添加到 esp 容器中。我的 API 在端口 80 上运行,其状态端点为未受保护/api/status

spec:
  containers:
  - name: esp
    image: gcr.io/endpoints-release/endpoints-runtime:1
    args: [
      "--http_port=8081",
      "--backend=127.0.0.1:80",
      "--service=MY SERVICE",
      "--rollout_strategy=managed",
      "-z", "healthz",
    ]
    ports:
    - containerPort: 8081
    readinessProbe:
      httpGet:
        path: /api/status/
        port: 8081
  - name: api
    image: MY IMAGE
    ports:
      - containerPort: 80

这行得通,因此检查现在正在验证两个容器都在运行一个readinessProbe. 有趣的是,当我检查 LoadBalancer 时,它还配置了一个反对/healthz. 这对于诊断端点容器正在工作的情况很有用,但该 api 不是


推荐阅读