mehere
mehere

Reputation: 1556

Cant connect to Cloud SQL from Cloud Composer

I am trying to retrieve data from Cloud SQL via Cloud Composer DAG to GCS.

  1. I tried giving the public/private ip of the cloud sql instance in the airflow mysql_conn connection.

MySQLdb._exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'xx.xxx.xx.x' (110)")

  1. Tried installing cloud proxy and changed airflow connection host to 127.0.0.1

MySQLdb._exceptions.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (111)") 3. Enabled the Private IP & selected the network the same as cloud composer network. still same issue.

ping has no response to Private IP in cloud shell. ping has response to Public IP in cloud shell.

Can anyone help on the same? like what should be done for a composer dag to access the tables in cloud sql?

Cloud Composer network: enter image description here

Cloud SQL: enter image description here

Upvotes: 0

Views: 540

Answers (1)

Sandeep Mohanty
Sandeep Mohanty

Reputation: 1552

In order to connect Cloud Composer to Cloud SQL via private IP, please enable Export custom routes in the VPC peering between your VPC network and Cloud SQL's VPC network.

Once the exporting of custom routes is enabled, the VPC network of the Cloud SQL instance knows where to route the pod traffic and connection can be successfully established

You can achieve this by following these steps:

Cloud Console Main Menu > VPC Network > VPC network peering > servicenetworking-googleapis-com > edit > enable the export custom route.

You can refer to this doc for more information.

Upvotes: 0

Related Questions