Chirag Nayyar
Chirag Nayyar

Reputation: 3

CloudSql with Autoscaler access

I am stuck at one thing regarding CloudSQL.

I have my WordPress app running on GCE and I create Instance Group so I will utilise the AutoScaler.

for Db, I am using CloudSQL.

Now point where is stuck is the "Authorise network" in CloudSQL as it accepts only IPV4 Public IP.

How do I know when autoscaling happen what IP will attach to Instance so my instance will know where the DB is?

I can hard code the CloudSQL IP as a CNAME but from CloudSQL Side I am not able to figure it out how to provide access. I can make my DB access all open

If you can let me know what will be the point which I am missing.

I used cloudsql proxy also but that doesn't come with Service in Linux ... I hope you can understand my situation. Let me know if any idea you like to share on this.

Thank you

Upvotes: 0

Views: 106

Answers (1)

Irina
Irina

Reputation: 31

The recommended way is to use the second generation instances and Cloud SQL Proxy, you’ll need to configure the Proxy on Linux and start it by using service account credentials as outlined at the provided link.

Another way is to use startup script in your GCE instance template, so you can get your new instance’s external IP address and add it to a Cloud SQL instance’s authorized networks by using gcloud sql instance patch command. The IP can be removed from the authorized networks in the same way by using shutdown script. The external IP address of GCE VM instance can be retrieved from metadata by running:

$ curl "http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip" -H "Metadata-Flavor: Google".

Upvotes: 2

Related Questions