<p>I deployed an image on Cloud Run where I need to make http calls to a service that is inside a Kubernetes cluster.</p>
<p>This service can be only accessed from a private network.</p>
<p>I read on that <a href="https://ahmet.im/blog/cloud-run-vpc-to-kubernetes/" rel="nofollow noreferrer">article</a> 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.</p>
<p>Did I understand it right ?</p>
<p>Then, how could I assign a hostname to that external ip ? I would need to update the dns that cloud run uses I guess ?</p>

Dimitri Danilov
<p>Assuming you are using Cloud Run and GKE, you'd need to take the following steps:</p>
<p>Create a <a href="https://cloud.google.com/run/docs/configuring/connecting-vpc" rel="noreferrer">Serverless VPC connector</a> to connect Cloud Run to the VPC where your GKE cluster is deployed:</p>
<pre><code> gcloud services enable vpcaccess.googleapis.com
    gcloud compute networks vpc-access connectors create $CONNECTOR_NAME \
    --network $VPC_NETWORK \
    --region $REGION \
    --range $IP_RANGE
</code></pre>
<p><a href="https://cloud.google.com/compute/docs/ip-addresses/reserve-static-internal-ip-address" rel="noreferrer">Reserve a static internal IP address</a>:</p>
<pre><code>gcloud compute addresses create $ADDRESS_NAME \
    --region $REGION --subnet $SUBNETWORK
</code></pre>
<p>Create a LoadBalancer for your GKE service and assign the static IP:</p>
<pre><code>gcloud compute addresses describe $ADDRESS_NAME --region $REGION
</code></pre>
<p>The above command will show you the static IP you created</p>
<p>Create a load balancer service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: helloweb
  annotations:
    networking.gke.io/load-balancer-type: &quot;Internal&quot;
  labels:
    app: hello
spec:
  selector:
    app: hello
    tier: web
  ports:
  - port: 80
    targetPort: 8080
  type: LoadBalancer
  loadBalancerIP: &quot;YOUR.IP.ADDRESS.HERE&quot;
</code></pre>
<p>You can use the IP address directly from Cloud Run, but you could also create a DNS name using Cloud DNS as well.</p>
