Use Case : Let’s say we have deployed our application, in Staging environment (Different GCloud Project) and we want to access database hosted in different environment (Let’s say, Dev environment, another GCloud Project)

We can achieve above use case by below configurations :

1. Configure Database access point, below snippet demonstrates the access of database using Spring Datasource  :

As we are going to set cloud proxy hence our database will be available for our project locally.

2. Configure Cloud Proxy in kube/deployment/<application_name>.yaml of Staging environment because we want to access the Dev Database from Staging Environment using Sidecar container we can achieve this.

 

-credential_file : This is the location where we configure the different environment access file. This will allow us to access the database resources.

<service_account_key> : This  is Service Account Key generated from GCloud, which provides the access to certain resources (Database in our case).

3. Create secret in Staging environment

Above command will create a secret which will look like below

Below command can describe the kube secret

 

Happy Coding !