通过 Helm 在 GKE 中部署 Kong API 网关并使用 Google 托管证书

Deploy Kong API Gateway in GKE via Helm and use Google managed certificates

我们目前正在尝试在 GKE 集群中部署 Kong,目标是将证书管理委托给 Google 的负载均衡器(SSL 终止应在此处进行)。

我们面临的问题是,所有 Google 的文档都专注于部署某些服务并使用直接连接到声明的 Ingress 的专用负载均衡器。

当前可用的配置(没有 Kong)如下:

# values.yml (from Service X inside GKE, using Helm)
...
ingress:
  enabled: true
  hostname: example.com
  annotations:
    kubernetes.io/ingress.class: gce
    kubernetes.io/ingress.allow-http: "false"
    kubernetes.io/ingress.global-static-ip-name: example-static-ip
    ingress.gcp.kubernetes.io/pre-shared-cert: example-cert
...

但是,当我们将 konggce 更改为 ingress.class 时,所有其他注释都不会继续工作。这是意料之中的,因为现在 Kong 的代理是 负载均衡器 并且应该是告诉 Google 的 LB 如何生成自身的代理。

根据此documentation,将这些注释添加到 Kong 代理服务应该相当简单。

基于这一系列事件:

自定义LB的配置应该在Kong的服务中进行(据我了解):

# values.yml (Kong, using Helm)
...
proxy:
  type: LoadBalancer
  annotations: {} <-- Here
  http:
    ...
  tls:
    ...
...

但是对于GCP,按照docs,只有少数几个,none个达到了想要的效果(不能设置证书使用,定义创建哪种类型的LB,等等)

综合考虑,有没有办法实现我们的主要目标:

“通过 GKE 内部的 Helm 部署 Kong API 网关,并将 SSL 终止委托给自定义 Google 的 LB。”

TL;DR

不幸的是,无法将 Google 托管证书与 Kong Ingress 一起使用。

确切地说 Google GKE 中的托管证书 可用于:

  • 外部 HTTP(S) 负载平衡的入口

正如文档所指出的:

Note: This feature is only available with Ingress for External HTTP(S) Load Balancing.

-- Cloud.google.com: Kubernetes Engine: Docs: How to: Managed certs



说明

根据文档(稍作修改):

When you create an Ingress object with below class:

  • kubernetes.io/ingress.class: gce

the GKE Ingress controller creates a Google Cloud HTTP(S) Load Balancer and configures it according to the information in the Ingress and its associated Services.

-- Cloud.google.com: Kubernetes Engine: Ingress: Ingress for external and internal traffic

使用不同的 Ingress 控制器,例如(nginx-ingress、traefik、kong)需要您使用 Service 类型 LoadBalancer

GKE 中使用上述 Service 将自动创建指向您的 Ingress 控制器的 External TCP/UDP Network Load Balancer (L4)。从这一点开始,流量将根据 Ingress 资源和适当的 ingress.class.

重定向到特定服务

A tip!

You can see in the helm chart of Kong that it's using the same way!

  • helm install kong/kong kong-ingress --dry-run --debug

要在客户端和 kong 之间建立安全连接,您需要 :

Side note: In both ways the SSL termination will happen at the Ingress controller.


回答问题部分:

The configuration to customize the LB should be made inside Kong's service (as I understand):

# values.yml (Kong, using Helm)
...
proxy:
  type: LoadBalancer
  annotations: {} <-- Here
...

However, for GCP there are only a few according to the docs, and none of them have the desire effect (cannot set certificate to use, define which type of LB to create, etc.)

前面说过 Service of type LoadBalancer in GKE 会配置 L4 TCP/UDP LoadBalancer 不是设计来负责处理SSL 流量(SSL 终止)。


其他资源: