I have tried every method mentioned even by creating the service but still no lock. I am stuck with same. So I have created a service without selector and then endpoint pointing to localhost mysql address still no luck. I have gone through this post https://stackoverflow.com/a/43477742/5821354 . All I want is a service connecting to local mysql database on mac and using the service to connect to frontend running as deployment by providing environment variables.
Asked
Active
Viewed 289 times
1 Answers
0
I've tried the same steps from the link you shared and it worked for me.
First, I installed mysq-server on my VM and created a database and the user app
with privileges to access the db.
Second, applied the service and endpoint yamls, and connected with simples pod as mentioned below.
Please note you can't use
127.0.0.1
to create the Endpoint, you need to use internal ip.
Here my yaml specs:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
ports:
- protocol: TCP
port: 1443
targetPort: 3306
---
apiVersion: v1
kind: Endpoints
metadata:
name: my-service
subsets:
- addresses:
- ip: 10.xx.xx.xx
ports:
- port: 3306
And a pod to test the connection:
kex alpine -- sh -c "apk update && apk add mysql-client"
NOTE: to connect from the pod, you need to use the IP displayed in the output of the command
kubectl get endpoint
$ kubectl exec alpine -- sh -c "mysql -h 10.xx.xx.xx -uapp -p123456"
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.1.45-MariaDB-0+deb9u1 Debian 9.12
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

Mr.KoopaKiller
- 3,665
- 10
- 21
-
I have created a deployment with 2 pods and set the environment variables used to connect to database inside the code with `kubectl get endpoints` url in deployment config object. Still same issue in connecting. – Himanshu Aug 14 '20 at 14:20
-
Did you tested with a simple pod as i mentioned in the answered? Check if you don't have any firewall blocking the request. – Mr.KoopaKiller Aug 14 '20 at 14:25
-
tried with test pod but when tried to connect to mysql get an error `Host is not allowed to connect to this MySQL server` – Himanshu Aug 14 '20 at 15:08
-
Hum seems you need to grant privileges in your database for the host, because this error is from mysql, that means your pod can reach the hoste. You can try Something like `grant all privileges on database.* to "user"@"%"` please let me know if it works. – Mr.KoopaKiller Aug 14 '20 at 22:16
-
Root user has all permissions. – Himanshu Aug 16 '20 at 05:54
-
Though I have created one more user but still no luck. – Himanshu Aug 16 '20 at 08:35
-
I've tested with root user, and it doesn't worked. Try to create another user and grant the permissions. `grant all privileges on app.* to "app"@"%" identified by '123456';` and `flush privileges;`. User this user to connect, it works. – Mr.KoopaKiller Aug 17 '20 at 07:55