GCP 上的 Terraform:如何将我的集群节点列入 RDS 白名单

Terraform on GCP: How to whitelist my cluster nodes for RDS

我有一个 kubernetes 集群和一个以 terraform 配置的 RDS,现在我想将 RDS 的节点 IP 列入白名单。有没有办法以某种方式从集群配置访问节点池实例?我基本上想要的 RDS 配置类似于

    ip_configuration {

      dynamic "authorized_networks" {
        for_each = google_container_cluster.data_lake.network
        iterator = node
        content {
          name = node.network.ip
          value = node.network.ip
        }
      }
    }

但据我所知,似乎无法获得 nodes/the-IPs 的列表。 我试过了

    ip_configuration {
      authorized_networks {
        value = google_container_cluster.my_cluster.cluster_ipv4_cidr
      }
    }

结果是 Non-routable or private authorized network (10.80.0.0/14).., invalid 所以看起来这只适用于 public IP。或者我必须为此设置一个单独的 VPC?

我建议您先在 GKE 前面设置 NAT 网关 以便您可以管理所有传出流量从单个 出口 点。

您可以使用此地形来创建和设置 NAT 网关:https://registry.terraform.io/modules/GoogleCloudPlatform/nat-gateway/google/latest/examples/gke-nat-gateway

模块源代码:https://github.com/GoogleCloudPlatform/terraform-google-nat-gateway/tree/v1.2.3/examples/gke-nat-gateway

使用 NAT 网关,您的所有节点流量都将流出单个 IP,您可以将此 single IP 列入白名单 RDS

由于 RDSAWS 服务中,如果使用 GCP SQL 则 VPC 对等是不可能的还有一种选择。