Score:0

Unable to connect GCP SQL Instance from GKE cluster

cn flag

I have created a vpc-native cluster and I am trying to connect from a pod inside the cluster to a postgres SQL instance with a private IP.

I am testing using a basic telnet 5432 command.

The connection works fine when I try it from a GCE instance that is in the same VPC. All connectivity tests in GCP are giving me green light so it seems to be a k8s issue.

Here is my cluster:

gcloud container clusters create alex-test \                                                            
    --network=factory-vpc \
    --region=europe-west1 \
    --enable-ip-alias \
    --subnetwork=europe-west1-factory-subnet \
    --cluster-ipv4-cidr="/16" \
    --services-ipv4-cidr="/20"

Here is how I am testing the connectivity:

kubectl run -it --rm --restart=Never busybox --image=gcr.io/google-containers/busybox sh
telnet <private ip> 5432

Here is my network config in terraform:

resource "google_compute_network" "factory" {
  name                    = "factory-vpc"
  auto_create_subnetworks = false

  depends_on = [google_project_service.compute]
}

resource "google_compute_subnetwork" "factory_subnet" {
  name                     = "${var.region}-factory-subnet"
  ip_cidr_range            = "10.0.0.0/16"
  region                   = var.region
  network                  = google_compute_network.factory.self_link
  private_ip_google_access = true

  secondary_ip_range {
    ip_cidr_range = "10.2.0.0/16"
    range_name    = "pods"
  }

  secondary_ip_range {
    ip_cidr_range = "10.3.0.0/16"
    range_name    = "services"
  }
}

resource "google_compute_global_address" "gitlab_google_private_peering" {
  provider      = google-beta
  name          = "gitlab-gcp-private"
  address_type  = "INTERNAL"
  purpose       = "VPC_PEERING"
  network       = google_compute_network.factory.self_link
  prefix_length = 16
}

resource "google_service_networking_connection" "gitlab_google_private_peering" {
  provider                = google-beta
  network                 = google_compute_network.factory.self_link
  service                 = "servicenetworking.googleapis.com"
  reserved_peering_ranges = [google_compute_global_address.gitlab_google_private_peering.name]
}

I have already checked the following documentation and articles, but nothing helps:

Any help is greatly appreciated !

Score:1
us flag

Please make sure and check if you can communicate with your instance, hostname and declared IP address. If you are ok with that make sure also that you are in the same region.

I found this link this might help you. Here is also how to set up a cluster with shared VPC.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.