Launch a custom site
When you are ready to launch your site to external traffic, there are many tasks you will need to perform, including:
- Configure your Cloud Service to serve external traffic, over SSL. GCP offers many options for this; see Mapping custom domains.
- Optionally, restrict access to your service; see Custom audiences (services).
- Optionally, add a caching layer to improve performance. We have provided specific procedures to set up a Redis Memorystore in Improve database performance.
Improve database performance
We recommend that you use a caching layer to improve the performance of your database. We recommend Google Cloud Redis Memorystore, a fully managed solution, which will boost the performance of both natural-language searches and regular database lookups in your site. Redis Memorystore runs as a standalone instance in a Google-managed virtual private cloud (VPC), and connects to your VPC network (“default” or otherwise) via direct peering. Your Cloud Run service connects to the instance using a VPC connector.
In the following procedures, we show you how to create a Redis instance that connects to your project’s “default” VPC network.
Step 1: Create the Redis instance
The following is a sample configuration that you can tune as needed. For additional information, see Create and manage Redis instances.
- Go to https://console.cloud.google.com/memorystore/redis/instances for your project.
- Select the Redis tab and click Create Instance.
- If prompted to enable the Redis API server, accept.
- Name your instance.
- Under Tier Selection, select Basic.
- Set the Capacity field to 2 GB.
- Under Region and zonal availability, set the region to be the same as your Cloud SQL database.
- Under Set up connection > Network, select default as the network.
- Click Create.
Step 2: Set the environment variable
- When the Redis instance is created above, go to the Instances > Redis tab, look up your instance and note the Primary Endpoint IP address.
- In
custom_dc/cloudsql_env.list
, set the value of theREDIS_HOST
option to the IP address.
Step 3: Create the VPC connector
- Go to https://console.cloud.google.com/networking/connectors/list for your instance.
- If you are prompted to enable the VPC Access API, accept.
- In the Serverless VPC Access screen, click Create Connector.
- Name the connector.
- Under Region, select the region you specified for Redis instance in the first step.
- In the Network field, select default.
- Under Subnet, select Custom IP Range.
- In the IP Range field, enter a valid IP range; for example,
10.9.0.0
. - Click Create.
For additional information, see Serverless VPC Access.
Step 4: Configure your Cloud Run service to connect to the VPC
- In the Cloud Console, go to the Cloud Run service from which you are serving your app.
- Click Edit & Deploy New Revision.
- Click the Networking tab and enable Connect to a VPC for outbound traffic.
- Enable Use Serverless VPC Access connectors.
- From the Network field, select the connector you created in step 3.
- Click Deploy.
Step 5: Verify that everything is working
To verify that your Cloud Run service is using the connector:
- Go to the Service details page for your service
- Click the Networking tab. Under VPC, you should see your connector listed.
To verify that traffic is hitting the cache:
- Run some queries against your running Cloud Run service.
- In the Cloud Console, go to the Memorystore page and select Redis instance.
- Under Instance Functions, click Monitoring.
- Scroll to the Cache Hit Ratio graph. You should see a significant percentage of your traffic hitting the cache.