last day (15 days later) » 

1:46 PM
1
A: Can't connect to MariaDB by hostname within a Kubernetes cluster

KoopaKillerSince you are using Kubernetes Deployment, the name of your pods will be generated dinamically based on the name you gave in spec file, in your example, the pods will be create with the name db-xxxxxxxxxx-xxxxx. In order to make a 'fixed' hostname, you need to create a service for reach your po...

 
I forgot to include my service declaration - have now updated the question with that. As can be seen in the host command example, hostname db is declared and points to a local IP: The problem is that connections to that host name or IP are refused on port 3306. Please not that the examples shown are in a shell within the database container.
 
Your service resolution is pointing to db.my-namspace.svc.cluster.local but your yamls was not created in my-namespace. Could you please update the question with the outputs of the commands: kubectl get svc -n default and kubectl get pods -n default -owide ?
 
Yes, updated the question.
 
Your service IP doesn't match with the output of the command host db (10.152.183.124) in yout post. Check in your /etc/hosts, the line must be 10.152.183.246 db db.my-namespace.cluster.local, is it correct ?
 
That's actually because I had recreated the container in the meantime, so the IPs from the host command in a shell within the container, and from kubectl get svc ... issued from outside the container, do in fact match, but /etc/hosts actually contains a different IP: 10.1.48.118 db-77cbcf87b6-l44lm and I can telnet to that IP. How can that IP be different from the k8s svc cluster IP ?
 
1:46 PM
You need to use the service ip, and not conteiner ip to connect, also, you are only point db-77cbcf87b6-l44l for this ip, it means you are not able to reach only db. Try to add in yout /etc/hosts this 10.152.183.246 db db.my-namespace.cluster.local it will permit resolve db and db.my-namespace.cluster.local to service ip 10.152.183.246.
 
That doesn't work, as the cluster IP results in connection refused on port 3306, while the container IP works. I guess the main question here is, why doesn't the database accept connections on for the cluster IP? The database is configured with bind-address = * which should set it to listen all interfaces, for both IPv4 and IPv6.
 
I've tested here with the deployment yaml you posted, and with the service yaml in my answer and worked for me. Check if your service selector is matching the pod, based in your deployment yaml, selector in service must be name: db.
Hello! Let's make it work =)
 
Hi :) Thanks!
 
So based in what you said, the point is service... so let's concentrate our efforts in it... to service work, the selector must match with your deployment... the yaml in my answer was based in you deployment yaml, I've tried in my lab cluster and it worked
 
Yes, it must be the service not properly pointing to the deployment, but I can't see anything off. I'll try copy / pasting your service declaration...
Your service declaration works! Now I'll diff those two to try to spot what was off in mine...
 
2:02 PM
good to hear that =) probably the selector field...
 
actually it seems to be the "- protocol: TCP" part under "ports:"

previously there was
`ports: - name: "3306"`
and just changing it to
`ports: -protocol: TCP`
does the trick.
Thank you so very much for the help :)
 
Nice! If the answer helped you don't forget to accept and up voted to help the other ;)
 
Will do and summarise this finding in the comments, in a bit...

Thanks again :)
 

last day (15 days later) »