如何正确设置 Kubernetes 的 readinessProbe 的基本身份验证?

How to set basic auth to Kubernetes' readinessProbe correctly?

如何正确设置Kubernetes的readinessProbe的basic auth?

如果在部署类型中为 Kubernetes readinessProbe 设置此配置。

readinessProbe:
  httpGet:
    path: /healthcheck
    port: 8080
    httpHeaders:
    - name: Authorization
      value: Basic <real base64 encoded data>

将其部署到GKE,GCP的健康检查无法通过使用基本身份验证访问内部应用程序。

但从来看,似乎应该使用这种语法。为什么不能通过?

服务器端正在 /healthcheck 点使用 JSON 响应。 AcceptContent-Type 是否也需要设置为 httpHeaders

还有,这个健康检查设置成livenessProbe还是readinessProbe好不好?

根据 kubernetes 文档:

If the process in your container is able to crash on its own whenever it encounters an issue or becomes unhealthy, you do not necessarily need a liveness probe; the kubelet will automatically perform the correct action in accordance with the Pod's restartPolicy. If you'd like your container to be killed and restarted if a probe fails, then specify a liveness probe, and specify a restartPolicy of Always or OnFailure.

参考:https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#when-should-you-use-a-liveness-probe

If you'd like to start sending traffic to a Pod only when a probe succeeds, specify a readiness probe. In this case, the readiness probe might be the same as the liveness probe, but the existence of the readiness probe in the spec means that the Pod will start without receiving any traffic and only start receiving traffic after the probe starts succeeding. If your container needs to work on loading large data, configuration files, or migrations during startup, specify a readiness probe.

参考:https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#when-should-you-use-a-readiness-probe

因此,您可以根据需要使用健康检查。但是在kubernetes doc中,他们给出了一个健康检查的例子作为liveliness probe。

参考:https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-http-request

当您在浏览器或其他典型客户端之外发送请求时,最好使用 Content-Type。我相信使用 Content-Type: application/json 将解决问题,如果其他事情在服务器端正常进行的话。