I have GKE cluster created with following command:
gcloud container clusters create stage1 \
--enable-ip-alias \
--release-channel stable \
--zone us-central1 \
--node-locations us-central1-a,us-central1-b
Now I wanted to connect my PHP application to cloud SQL. To authorize access to the cloud SQL from the PHP application running in the pod, i have done following steps
- Created a secret
kubectl create secret generic stage-cloudsql-secret \
--from-literal=db_host=<YOUR-PRIVATE-IP-ADDRESS>
- Updated this secret my pod in container section as follows:
env:
- name: DB_HOST
valueFrom:
secretKeyRef:
name: stage-cloudsql-secret
key: db_host
I have updated CloudSQL private ip (along with DB name, username, and password) in my PHP file(env.php), built my docker image , created the pod in GKE cluster. When pod is created i am getting following error from container (failed container):
SQLSTATE[HY000] [2002] Operation timed out
Note 1: This is working application in hosted environment and we are migrating to Google cloud
Note 2: GKE and Cloud SQL is in same VPC (default)
Note 3: Enabled IP aliasing in cluster
Note 4: I have a a container which creates data in database when started
Update 1
I have followed the steps mentioned in google cloud documentation. Link
I have SSH into the container and tried to reach (Ping) into cloud SQL using private IP. But I couldnt
Update 2
After followed above links, I have changed the the way in which I create secret (Just the private ip this time). I also updated my env.php as below
array (
'table_prefix' => '',
'connection' =>
array (
'default' =>
array (
'host' => getenv('DB_HOST'),
Previously 'host' => [Private IP of Cloud SQL]
This time when the pod is created it shows following error
SQLSTATE[HY000] [2002] No such file or directory
Update 3
I have redone all the steps again and its working