GCP GKE不能访问Redis Memorystore。

问题描述 投票:1回答:1

我在GCP(GKE)中的Kubernetes集群,无法连接到Memorystore(Redis)。

所有与项目相关的资源都在专用网络中。

网络模块中。

resource "google_compute_network" "my_project" {
  name = "my_project"
  auto_create_subnetworks = true
}

output "my_project_network_self_link" {
  value = google_compute_network.my_project_network.self_link
}

我在GKE集群中使用的网络(network = "${var.network_link}"):

resource "google_container_cluster" "my_project" {
  name     = "my_project-cluster"
  location = "us-central1"
  node_locations = ["us-central1-a", "us-central1-b"]

  network = "${var.network_link}"

  # We can't create a cluster with no node pool defined, but we want to only use
  # separately managed node pools. So we create the smallest possible default
  # node pool and immediately delete it.
  remove_default_node_pool = true
  initial_node_count       = 1

  master_auth {
    username = ""
    password = ""

    client_certificate_config {
      issue_client_certificate = false
    }
  }
}

节点池省略。

而我将网络设置为 authorized_network 在memoryystore配置中。

resource "google_redis_instance" "cache" {
  name           = "my_project-redis"
  tier           = "STANDARD_HA"
  memory_size_gb = 1
  authorized_network = "${var.network_link}"

  # location_id             = "us-central1-a"

  redis_version     = "REDIS_4_0"
  display_name      = "my_project Redis cache"
}

variable "network_link" {
  description = "The link of the network instance is in"
  type        = string
}

我想问题应该是出在网络上 因为之前使用默认的网络是可以正常工作的

目前GKE节点在 us-central1-aus-central1-b(在TF脚本中指定),内存存储在 us-central1-c. 所以集群和Redis在同一个VPC里,但是在不同的子网里。会不会是这个问题?

networking google-cloud-platform terraform vpc
1个回答
0
投票

我不得不在terraform中的集群模块中添加以下部分。

  ip_allocation_policy {
    cluster_ipv4_cidr_block = ""
    services_ipv4_cidr_block = ""
  }

这似乎可以使 VPC-native (alias IP) 簇的属性。

© www.soinside.com 2019 - 2024. All rights reserved.