Connecting to Google cloud mysql instance from GKE cluster using cloudsqlproxy












1















I have two projects in GCP viz. project1 and project2



I have setup mysql instance in project1.



I have also setup cloudsqlproxy (pod) and mypod in a GKE cluster in project2.
I want to access mysql instance from
mypodthroughcloudsqlproxy`.



I have the following code for cloudmysqlproxy



apiVersion: v1
kind: Service
metadata:
name: cloudsqlproxy-service-mainnet
namespace: dev
spec:
ports:
- port: 3306
targetPort: port-mainnet
selector:
app: cloudsqlproxy

---

apiVersion: apps/v1
kind: Deployment
metadata:
name: cloudsqlproxy
namespace: dev
spec:
replicas: 1
selector:
matchLabels:
app: cloudsqlproxy
template:
metadata:
labels:
app: cloudsqlproxy
spec:
containers:
# Make sure to specify image tag in production
# Check out the newest version in release page
# https://github.com/GoogleCloudPlatform/cloudsql-proxy/releases
- name: cloudsqlproxy
image: b.gcr.io/cloudsql-docker/gce-proxy:latest
# 'Always' if imageTag is 'latest', else set to 'IfNotPresent'
imagePullPolicy: Always
name: cloudsqlproxy
command:
- /cloud_sql_proxy
- -dir=/cloudsql
- -instances=project1:asia-east1:development=tcp:0.0.0.0:3306
- -credential_file=/credentials/credentials.json
ports:
- name: port-mainnet
containerPort: 3306
volumeMounts:
- mountPath: /cloudsql
name: cloudsql
- mountPath: /credentials
name: cloud-sql-client-account-token
volumes:
- name: cloudsql
emptyDir:
- name: cloud-sql-client-account-token
secret:
secretName: cloud-sql-client-account-token


I have setup cloud-sql-client-account-token in the following manner:



kubectl create secret cloud-sql-client-account-token --from-file=credentials.json=$HOME/credentials.json


Where I downloaded the credentials.json file from a service account in project1.



When I try to access the mysql instance from my pod, I get the folløwing error:



mysql --host=cloudsqlproxy-service-mainnet.dev.svc.cluster.local --port=3306
ERROR 1045 (28000): Access denied for user 'root'@'cloudsqlproxy~35.187.201.86' (using password: NO)


And the cloud-proxy logs, I get the following:



2018/11/25 00:35:31 Instance project1:asia-east1:development closed connection


Is it necessary to launch a mysql instance in the same project (project2) as the pod? What am I missing?



EDIT



I can access the proxy on my local machine by setting up like this



/cloud_sql_proxy -instances=project1:asia-east1:development=tcp:3306


and then connecting to the proxy using a mysql client.










share|improve this question





























    1















    I have two projects in GCP viz. project1 and project2



    I have setup mysql instance in project1.



    I have also setup cloudsqlproxy (pod) and mypod in a GKE cluster in project2.
    I want to access mysql instance from
    mypodthroughcloudsqlproxy`.



    I have the following code for cloudmysqlproxy



    apiVersion: v1
    kind: Service
    metadata:
    name: cloudsqlproxy-service-mainnet
    namespace: dev
    spec:
    ports:
    - port: 3306
    targetPort: port-mainnet
    selector:
    app: cloudsqlproxy

    ---

    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: cloudsqlproxy
    namespace: dev
    spec:
    replicas: 1
    selector:
    matchLabels:
    app: cloudsqlproxy
    template:
    metadata:
    labels:
    app: cloudsqlproxy
    spec:
    containers:
    # Make sure to specify image tag in production
    # Check out the newest version in release page
    # https://github.com/GoogleCloudPlatform/cloudsql-proxy/releases
    - name: cloudsqlproxy
    image: b.gcr.io/cloudsql-docker/gce-proxy:latest
    # 'Always' if imageTag is 'latest', else set to 'IfNotPresent'
    imagePullPolicy: Always
    name: cloudsqlproxy
    command:
    - /cloud_sql_proxy
    - -dir=/cloudsql
    - -instances=project1:asia-east1:development=tcp:0.0.0.0:3306
    - -credential_file=/credentials/credentials.json
    ports:
    - name: port-mainnet
    containerPort: 3306
    volumeMounts:
    - mountPath: /cloudsql
    name: cloudsql
    - mountPath: /credentials
    name: cloud-sql-client-account-token
    volumes:
    - name: cloudsql
    emptyDir:
    - name: cloud-sql-client-account-token
    secret:
    secretName: cloud-sql-client-account-token


    I have setup cloud-sql-client-account-token in the following manner:



    kubectl create secret cloud-sql-client-account-token --from-file=credentials.json=$HOME/credentials.json


    Where I downloaded the credentials.json file from a service account in project1.



    When I try to access the mysql instance from my pod, I get the folløwing error:



    mysql --host=cloudsqlproxy-service-mainnet.dev.svc.cluster.local --port=3306
    ERROR 1045 (28000): Access denied for user 'root'@'cloudsqlproxy~35.187.201.86' (using password: NO)


    And the cloud-proxy logs, I get the following:



    2018/11/25 00:35:31 Instance project1:asia-east1:development closed connection


    Is it necessary to launch a mysql instance in the same project (project2) as the pod? What am I missing?



    EDIT



    I can access the proxy on my local machine by setting up like this



    /cloud_sql_proxy -instances=project1:asia-east1:development=tcp:3306


    and then connecting to the proxy using a mysql client.










    share|improve this question



























      1












      1








      1


      1






      I have two projects in GCP viz. project1 and project2



      I have setup mysql instance in project1.



      I have also setup cloudsqlproxy (pod) and mypod in a GKE cluster in project2.
      I want to access mysql instance from
      mypodthroughcloudsqlproxy`.



      I have the following code for cloudmysqlproxy



      apiVersion: v1
      kind: Service
      metadata:
      name: cloudsqlproxy-service-mainnet
      namespace: dev
      spec:
      ports:
      - port: 3306
      targetPort: port-mainnet
      selector:
      app: cloudsqlproxy

      ---

      apiVersion: apps/v1
      kind: Deployment
      metadata:
      name: cloudsqlproxy
      namespace: dev
      spec:
      replicas: 1
      selector:
      matchLabels:
      app: cloudsqlproxy
      template:
      metadata:
      labels:
      app: cloudsqlproxy
      spec:
      containers:
      # Make sure to specify image tag in production
      # Check out the newest version in release page
      # https://github.com/GoogleCloudPlatform/cloudsql-proxy/releases
      - name: cloudsqlproxy
      image: b.gcr.io/cloudsql-docker/gce-proxy:latest
      # 'Always' if imageTag is 'latest', else set to 'IfNotPresent'
      imagePullPolicy: Always
      name: cloudsqlproxy
      command:
      - /cloud_sql_proxy
      - -dir=/cloudsql
      - -instances=project1:asia-east1:development=tcp:0.0.0.0:3306
      - -credential_file=/credentials/credentials.json
      ports:
      - name: port-mainnet
      containerPort: 3306
      volumeMounts:
      - mountPath: /cloudsql
      name: cloudsql
      - mountPath: /credentials
      name: cloud-sql-client-account-token
      volumes:
      - name: cloudsql
      emptyDir:
      - name: cloud-sql-client-account-token
      secret:
      secretName: cloud-sql-client-account-token


      I have setup cloud-sql-client-account-token in the following manner:



      kubectl create secret cloud-sql-client-account-token --from-file=credentials.json=$HOME/credentials.json


      Where I downloaded the credentials.json file from a service account in project1.



      When I try to access the mysql instance from my pod, I get the folløwing error:



      mysql --host=cloudsqlproxy-service-mainnet.dev.svc.cluster.local --port=3306
      ERROR 1045 (28000): Access denied for user 'root'@'cloudsqlproxy~35.187.201.86' (using password: NO)


      And the cloud-proxy logs, I get the following:



      2018/11/25 00:35:31 Instance project1:asia-east1:development closed connection


      Is it necessary to launch a mysql instance in the same project (project2) as the pod? What am I missing?



      EDIT



      I can access the proxy on my local machine by setting up like this



      /cloud_sql_proxy -instances=project1:asia-east1:development=tcp:3306


      and then connecting to the proxy using a mysql client.










      share|improve this question
















      I have two projects in GCP viz. project1 and project2



      I have setup mysql instance in project1.



      I have also setup cloudsqlproxy (pod) and mypod in a GKE cluster in project2.
      I want to access mysql instance from
      mypodthroughcloudsqlproxy`.



      I have the following code for cloudmysqlproxy



      apiVersion: v1
      kind: Service
      metadata:
      name: cloudsqlproxy-service-mainnet
      namespace: dev
      spec:
      ports:
      - port: 3306
      targetPort: port-mainnet
      selector:
      app: cloudsqlproxy

      ---

      apiVersion: apps/v1
      kind: Deployment
      metadata:
      name: cloudsqlproxy
      namespace: dev
      spec:
      replicas: 1
      selector:
      matchLabels:
      app: cloudsqlproxy
      template:
      metadata:
      labels:
      app: cloudsqlproxy
      spec:
      containers:
      # Make sure to specify image tag in production
      # Check out the newest version in release page
      # https://github.com/GoogleCloudPlatform/cloudsql-proxy/releases
      - name: cloudsqlproxy
      image: b.gcr.io/cloudsql-docker/gce-proxy:latest
      # 'Always' if imageTag is 'latest', else set to 'IfNotPresent'
      imagePullPolicy: Always
      name: cloudsqlproxy
      command:
      - /cloud_sql_proxy
      - -dir=/cloudsql
      - -instances=project1:asia-east1:development=tcp:0.0.0.0:3306
      - -credential_file=/credentials/credentials.json
      ports:
      - name: port-mainnet
      containerPort: 3306
      volumeMounts:
      - mountPath: /cloudsql
      name: cloudsql
      - mountPath: /credentials
      name: cloud-sql-client-account-token
      volumes:
      - name: cloudsql
      emptyDir:
      - name: cloud-sql-client-account-token
      secret:
      secretName: cloud-sql-client-account-token


      I have setup cloud-sql-client-account-token in the following manner:



      kubectl create secret cloud-sql-client-account-token --from-file=credentials.json=$HOME/credentials.json


      Where I downloaded the credentials.json file from a service account in project1.



      When I try to access the mysql instance from my pod, I get the folløwing error:



      mysql --host=cloudsqlproxy-service-mainnet.dev.svc.cluster.local --port=3306
      ERROR 1045 (28000): Access denied for user 'root'@'cloudsqlproxy~35.187.201.86' (using password: NO)


      And the cloud-proxy logs, I get the following:



      2018/11/25 00:35:31 Instance project1:asia-east1:development closed connection


      Is it necessary to launch a mysql instance in the same project (project2) as the pod? What am I missing?



      EDIT



      I can access the proxy on my local machine by setting up like this



      /cloud_sql_proxy -instances=project1:asia-east1:development=tcp:3306


      and then connecting to the proxy using a mysql client.







      google-cloud-platform google-cloud-sql gke cloud-sql-proxy






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 17 '18 at 10:24









      Maxim

      1,533210




      1,533210










      asked Nov 25 '18 at 0:45









      user3288346user3288346

      1,12762746




      1,12762746
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463734%2fconnecting-to-google-cloud-mysql-instance-from-gke-cluster-using-cloudsqlproxy%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463734%2fconnecting-to-google-cloud-mysql-instance-from-gke-cluster-using-cloudsqlproxy%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Ottavio Pratesi

          Tricia Helfer

          15 giugno