kubernetes stateful set connection

1/5/2017

I start experiencing with statefulsets, and I'm following this link on kubernetes website

http://kubernetes.io/docs/tutorials/stateful-application/run-replicated-stateful-application/

How can I connect my java application to the mysql database statefulset (they are all in same kubernetes cluster node and namesapce)? what service should I connect to ? which address should I use ? I tried mysql-read.default.svc.cluster.local:3306 didn't work !!!

-- montatich
docker
google-kubernetes-engine
java
kubernetes
mysql

2 Answers

1/5/2017

This question was cross-posted to the Vitess mailing list and was solved there. It turns out this happened because the user modified the tutorial setup to add a password for the root user. As a result, readiness probes that expected password-less login to work were failing, and the mysql-read service was left with no valid endpoints.

-- Anthony Yeh
Source: StackOverflow

5/23/2018

You would need to alter the services as below,

Headless service for stable DNS entries of StatefulSet members.

apiVersion: v1 kind: Service metadata: name: mysql labels: app: mysql spec: ports: - name: mysql port: 3306 selector: app: mysql

type: LoadBalancer

Client service for connecting to any MySQL instance for reads.

For writes, you must instead connect to the master: mysql-0.mysql.

apiVersion: v1 kind: Service metadata: name: mysql-read labels: app: mysql spec: ports: - name: mysql port: 3306 selector: app: mysql type: LoadBalancer

Hence, you will be having the external ip to connect your mysql master /slave

in command prompt : mysql -uroot -h30.12.11.21 -P3306 (replace host with your loadbalancer ip)

-- Ramesh N
Source: StackOverflow