Closed kshitizJ closed 1 year ago
My guess is that the mysql credentials aren't configured correctly.
My mysql credentials are correct. I am able to login using mysql credentials.
I'm talking about the env vars that are being used by the application. can you check or show me the output of env | grep MYSQL
in the container that is connecting to mysql?
Ok, so you are sure user root
and password Kshitiz@123
are the correct credentials?
Can you show your init.sql
Ok, so you are sure user
root
and passwordKshitiz@123
are the correct credentials?
Yes
seems you removed the line CREATE USER 'auth_user'@'localhost' IDENTIFIED BY 'Auth123';
You shouldn't remove this you should just replace the values with your creds.
Actually can you drop the db and then create it again using the init.sql
from this repo.. you can change the insert line but leave the password and user.. then use those creds in your secrets file and see if it will connect?
Sure I will give this a try.
I have a doubt. This new user which we are creating, is being created in our local mysql right? My local mysql already have a user name - 'root' and password - 'Kshitiz@123' then does it make any difference if we use the existing user i.e 'root' than creating a new user?
I have no way of knowing how your user is configured and what dbs it has access to. I do know that in that init.sql I explicitly give access to the user being created in the script. So if we can't connect even when using that user, we know that the problem is something else. Basically, the fastest way to figure out the problem is through process of elimination.
You also removed the line GRANT ALL PRIVILEGES ON auth.* TO 'auth_user'@'localhost';
These are important
I have no way of knowing how your user is configured and what dbs it has access to. I do know that in that init.sql I explicitly give access to the user being created in the script. So if we can't connect even when using that user, we know that the problem is something else. Basically, the fastest way to figure out the problem is through process of elimination.
Ok, Thank you. I will create a new user and give you an update.
Update:
I am getting an error
Init.sql file:
So I added '@' in the password and the user got created.
Still i get the same error:
can you docker exec
into the container and try to manually connect to mysql from within the container's shell?
Will you please assist me on this using google meet as I am new to docker and kubernetes.
I can share you the meeting link.
for example sudo docker exec –it container-name /bin/bash
that command will get you into the container. Then once in the container try to connect using your usual mysql
command that you use on your local but this time use the host host.minikube.internal
Do I need to do this eval $(minikube docker-env)
before getting into the container?
huh why?
Nope just do what I mentioned above. Also I can't get on a call. It's late for me and I have work tomorrow
also, you will need to install a mysql client in the container
I will check on this tomorrow. Let me know the results.
Ok I will do as you said and I will update you.
How to install mysql client inside the container?
I think its apt-get install mysql-client
. This is the underlying os of the container. https://github.com/docker-library/python/blob/7ee840478eed1fd8d36dbe9ab7bd4706085468e5/3.12-rc/slim-bullseye/Dockerfile
You can see how they are installing things in the script
Ok got it. I will update you by tomorrow. Thank you so much for the help.
can you
docker exec
into the container and try to manually connect to mysql from within the container's shell?
Are you sure you have mysql server installed on your local? What os are you using?
Yes, I am sure.
OS: Ubuntu 22 LTS
Mysql version:
run this and show me the output please sudo apt-get install mysql-server
on my local machine?
yes
Hello sir, will you please suggest me next steps so that I can complete this tutorial. Your teaching is very good. I got to know each and every concepts clearly. I just got stuck because of mysql.
did you change the port from "3306" to '3306' in the yaml file?
If its still not working just connect to a remote mysql database either on aws or azure. That should work fine
apiVersion: v1 kind: ConfigMap metadata: name: auth-configmap data: MYSQL_HOST: host.minikube.internal MYSQL_USER: root MYSQL_DB: auth MYSQL_PORT: '3306'
kubectl port-forward auth-67f87b9dc6-s7jbg 5000:5000 &
curl -X POST 'http://127.0.0.1:5000/login' -u "trump@gmail.com:admin123"
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InRoZW9kb25kcmVAZ21haWwuY29tIiwiZXhwIjoxNjY5ODUxOTY2LCJpYXQiOjE2Njk3NjU1NjYsImFkbWluIjp0cnVlfQ.pOSQEACZrnni4NVP9WDr6pO1o6iK0ZWRPPYQWPdsQiI%
You can also try to spin up a mysql docker container and just connect to that although the data will be wiped once you stop the container. But still you will be able to finish the tutorial. I suspect there is some issue with your local mysql setup but I really have no way of knowing.
did you change the port from "3306" to '3306' in the yaml file?
No luck on this.
apiVersion: v1 kind: ConfigMap metadata: name: auth-configmap data: MYSQL_HOST: host.minikube.internal MYSQL_USER: root MYSQL_DB: auth MYSQL_PORT: '3306'
kubectl port-forward auth-67f87b9dc6-s7jbg 5000:5000 &
curl -X POST 'http://127.0.0.1:5000/login' -u "trump@gmail.com:admin123"
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InRoZW9kb25kcmVAZ21haWwuY29tIiwiZXhwIjoxNjY5ODUxOTY2LCJpYXQiOjE2Njk3NjU1NjYsImFkbWluIjp0cnVlfQ.pOSQEACZrnni4NVP9WDr6pO1o6iK0ZWRPPYQWPdsQiI%
No luck on this as well.
Error:
MySQLdb.OperationalError: (2002, "Can't connect to MySQL server on 'host.minikube.internal' (115)")
I think my pods inside the minikube node doesnot have the access of host.minikube.internal
.
Any idea on this?
Let's focus on one issue at a time. If you are having issues with minikube tunnel, it's better to create another issue.
I think my pods inside the minikube node doesnot have the access of host.minikube.internal
For this, please run the following commands and show me the output:
minikube ssh
nc -vz host.minikube.internal 3306
Let's focus on one issue at a time. If you are having issues with minikube tunnel, it's better to create another issue.
I think my pods inside the minikube node doesnot have the access of host.minikube.internal
For this, please run the following commands and show me the output:
minikube ssh
nc -vz host.minikube.internal 3306
can you show me the output of ping host.minikube.internals
as well... while in minikube ssh
Looking at this, it's possible there was a degradation introduced into the minikube code? I'm not sure I didn't read through it entirely, but what minikube version are you using?
minikube version
Might be worth it to downgrade to the version I used in the tutorial to see if that fixes the issue. In the tutorial I use v1.25.0
Let me know how it goes
can you show me the output of
ping host.minikube.internals
as well... while in minikube ssh
host.minikube.internals
didn't work so I used host.minikube.internal
:
minikube version:
Looking at this, it's possible there was a degradation introduced into the minikube code? I'm not sure I didn't read through it entirely, but what minikube version are you using?
minikube version
Might be worth it to downgrade to the version I used in the tutorial to see if that fixes the issue. In the tutorial I use
v1.25.0
Let me know how it goes
I read some the documentation where it says that if you are using minikube version greater than 1.10
than you can use host.minikube.internal
to access the service on your local machine.
Yeah I know that but look at the thread I linked. People with minikube v1.28.x seem to be experiencing the issue you are experiencing. So I'm guessing a bug was introduced at some point between v1.25 and v1.28.. So that's why I said you should try downgrading minikube to the version I used in the tutorial which is v1.25.0
Ok, I will downgrade and let you know.
Thank you!
Yeah I know that but look at the thread I linked. People with minikube v1.28.x seem to be experiencing the issue you are experiencing. So I'm guessing a bug was introduced at some point between v1.25 and v1.28.. So that's why I said you should try downgrading minikube to the version I used in the tutorial which is v1.25.0
I downgraded the minikube version and the problem still exists.
It says that MySQLdb.OperationalError: (2002, "Can't connect to MySQL server on 'host.minikube.internal' (115)")
Ok, so at this point I can't tell if this is an issue with your mysql or what so we are just going to have to do this a different way. Please do the following:
Create a directory structure in thesrc
dir that looks like this:
In the pod.yaml
file insert this:
apiVersion: v1
kind: Pod
metadata:
name: mysql
spec:
containers:
- name: mysql
image: mysql
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-initdb
mountPath: /docker-entrypoint-initdb.d
volumes:
- name: mysql-initdb
configMap:
name: mysql-initdb-config
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-initdb-config
data:
initdb.sql: |
CREATE USER 'auth_user'@'localhost' IDENTIFIED BY 'Aauth123';
CREATE DATABASE auth;
GRANT ALL PRIVILEGES ON auth.* TO 'auth_user'@'localhost';
USE auth;
CREATE TABLE user (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL);
INSERT INTO user (email, password) VALUES ('georgio@email.com', 'Admin123');
In auth/manifests/configmap.yaml
replace the contents with this:
apiVersion: v1
kind: ConfigMap
metadata:
name: auth-configmap
data:
MYSQL_HOST: mysql
MYSQL_USER: auth_user
MYSQL_DB: auth
MYSQL_PORT: "3306"
kubectl delete
EVERYTHING...
kubectl apply
EVERYTHING
Error Image:
My server file image:
My auth-deployment file image:
My auth-service file image:
My auth-configmap file image:
My Docker file for auth:
My all pods are running successfully:
I don't know what is the error. When id do
systemctl status mysql
it shows that my mysql is running successfully in my local device. My operating system is Ubuntu 22.04 LTS.Please help me to resolve the issue.