I deployed an image on Cloud Run where I need to make http calls to a service that is inside a Kubernetes cluster.
This service can be only accessed from a private network.
I read on that article that I need to connect the cloud run instance to my private VPC, then I need to create a load balancer that will be mapped to one of my k8s service. That will get me a external ip that will not change and I could use in Cloud Run.
Did I understand it right ?
Then, how could I assign a hostname to that external ip ? I would need to update the dns that cloud run uses I guess ?
CodePudding user response:
Assuming you are using Cloud Run and GKE, you'd need to take the following steps:
Create a Serverless VPC connector to connect Cloud Run to the VPC where your GKE cluster is deployed:
gcloud services enable vpcaccess.googleapis.com
gcloud compute networks vpc-access connectors create $CONNECTOR_NAME \
--network $VPC_NETWORK \
--region $REGION \
--range $IP_RANGE
Reserve a static internal IP address:
gcloud compute addresses create $ADDRESS_NAME \
--region $REGION --subnet $SUBNETWORK
Create a LoadBalancer for your GKE service and assign the static IP:
gcloud compute addresses describe $ADDRESS_NAME --region $REGION
The above command will show you the static IP you created
Create a load balancer service:
apiVersion: v1
kind: Service
metadata:
name: helloweb
annotations:
networking.gke.io/load-balancer-type: "Internal"
labels:
app: hello
spec:
selector:
app: hello
tier: web
ports:
- port: 80
targetPort: 8080
type: LoadBalancer
loadBalancerIP: "YOUR.IP.ADDRESS.HERE"
You can use the IP address directly from Cloud Run, but you could also create a DNS name using Cloud DNS as well.