title: GKE private cluster and cloud sql proxy connection
body: <p>I have 2 GKE cluster both private and public and using cloudproxy as sidecar container for gke app to access cloudsql instance.</p>
  
  <p><strong>public cluster setup for development/testing</strong></p>
  
  <p>Cloud SQL is enabled with both private and public IP.
  GKE app is using cloudproxy with default option of ip types (public,private) as below
  Cloud SQL doesn't have any authorized network.</p>
  
  <p>In this case, my app is able to connect CloudSQL and works smoothly. As far as I understand, here connection to cloudsql should be happening with private becuase there is no authorised network configured.</p>
  
  <p><strong>private cluster setup for production</strong></p>
  
  <p>Cloud SQL is enabled with both private and public IP.
  GKE app is using cloudproxy with default option of ip types (public,private)</p>
  
  <p>cloudsql-proxy setting in deployment file </p>
  
  <pre><code>  - name: cloudsql-proxy
      image: gcr.io/cloudsql-docker/gce-proxy:1.11
      command: ["/cloud_sql_proxy"]
      args: ["-instances=$(REAL_DB_HOST)=tcp:$(REAL_DB_PORT)","-credential_file=/secrets/cloudsql/credentials.json"]
  </code></pre>
  
  <p><strong>case 1</strong>
  Cloud SQL doesn't have any authorized network.
  Result: Application is not able to connect with Cloud SQL</p>
  
  <p><strong>case 2</strong>
  Cloud SQL have private GKE NAT gateway as authorized network
  Result: Application is not able to connect with Cloud SQL</p>
  
  <p>May be removing cloudproxy from application will work (I am yet to test) but it discourages the usage of proxy during dev env as it will need changes in deployment file during production deployment.</p>
  
  <p>I am not able to understand what is causing the connection failure with cloudproxy in gke private cluster. Should we not use cloudproxy in private cluster?</p>
  
  <p><strong>Update</strong>
  The reason due to which cloud proxy not able to connect cloud sql was disabled Cloud SQL Admin API. I have updated my answer in answer section.</p>