0

I'm trying to connect my node.js backend to a Cloud SQL on the same project, following many tutorials and documentation, but without success.

Here my service and endpoint config:

kind: Service
apiVersion: v1
metadata:
  name: mysql-service
spec:
  type: ClusterIP
  ports:
  - protocol: TCP
    port: 3306
    targetPort: 3306
---
kind: Endpoints
apiVersion: v1
metadata:
  name: mysql-service
subsets:
  - addresses:
    - ip: 10.78.176.3
    ports:
    - port: 3306

I got on my node.js side:

process.DB_HOST 10.78.176.3
process.DB_DATABASE marketplace_test
MySQL Connection pool error
connect ETIMEDOUT

I already tried to connect over the public and the private IP, over the 'mysql-service' name, but nothing worked.

Could it be some relation I'm missing, like a matchLabels? Should I match the service+endpoint+deployment? How? Must I use a proxy for that?

What I'm missing?

Thanks for all help!

5
  • are you sure that the ip is public for your cluster? I think that the best approach for you is to exec into one of the deployments and try to curl the ip (direct) and then try the same for the service. share your results Commented May 21, 2019 at 14:18
  • @Amityo I'm confused now, because a curl -v 10.78.176.3:3306 show that it can connect. It connected. Running from instance ssh.. what can happen? Commented May 21, 2019 at 14:35
  • Ssh from k8s or your computer? What about curling the service Commented May 21, 2019 at 15:07
  • @Amityo From the instance on GCP. The curling the internal ip connected. The public IP and the service name don't connect. Then, the instance has access to internal ip and port... why the pod is not connecting? Commented May 21, 2019 at 17:09
  • can you write the output of kubectl describe mysql-service? Commented May 21, 2019 at 21:10

1 Answer 1

1

If you are connecting via Private IP, you need to make sure you meet the environment requirements on your GKE cluster. This means that it needs to be a VPC-native cluster. If it's not, you'll need to use public IP.

If you are using a Public IP, you need to authenticate your connection. There are 3 main ways to do this:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.