How to use Serverless VPC access for Cloud functions

4/20/2019

I have created a Kubernetes clusters with sample Spring Boot application and it works well from public ip. Now I want to access the end point of Spring boot in Kubernetes clusters. I have already followed the tutorial from Google for Configuring Serverless VPC Access. (https://cloud.google.com/vpc/docs/configure-serverless-vpc-access?hl=bg). I have created the Serverless VPC access and used in one of cloud function.

Now my problem is, how can I connect the internal ip of Kubernetes clusters from my cloud function?. I have written code in Go.

package p

import (
    "fmt"
    "io/ioutil"
    "net/http"
)

func HelloWorld(w http.ResponseWriter, r *http.Request) {
    fmt.Println("Starting the application...")

    response, err := http.Get("http://10.59.247.177:47002/")
    if err != nil {
        fmt.Fprint(w, "The HTTP request failed with error %s\n", err)
    } else {
        data, _ := ioutil.ReadAll(response.Body)
        fmt.Fprint(w, string(data))
    }
}

But I am getting error: The HTTP request failed with error %s Get http://10.59.247.177:47002/: dial tcp 10.59.247.177:47002: i/o timeout

-- iOSLover
google-cloud-functions
google-cloud-platform
kubernetes
serverless

1 Answer

4/20/2019

By default Kubernetes services are internal to Kubernetes cluster. You have to expose services so that applications from outside of Kubernetes can connect to it.

There are 3 main ways to expose service in Kubernetes:

  1. Public load balancer. Service is exposed to Internet.
  2. Internal load balancer. Service is exposed internally within VPC and region.
  3. NodePort. Service is exposed on Kube nodes IP addresses on some high number port. This makes service visible internally and between regions within VPC.

Read more here https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types and here https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer

-- Vasily Angapov
Source: StackOverflow