Use HAProxy for Mysql master-master in Kubernetes

I’m trying to setup high-availability MySQL master-master cluster using HAProxy in Kubernetes.
Looks ok to me, the HAProxy stats show it connects MySQLs well and no error logs from pods of HAProxy. However, I can’t connect MySQL thru HAProxy and have the error below. Any clue?

I have no name!@mysql1-client:/$ mysql -hhaproxy.mysql.svc.cluster.local -uroot -p_____ -P3306
mysql: Can't get stat of '/opt/bitnami/mysql/conf/bitnami/my_custom.cnf' (OS errno 2 - No such file or directory)
mysql: [ERROR] Stopped processing the 'include' directive in file /opt/bitnami/mysql/conf/my.cnf at line 30.
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on 'haproxy.mysql.svc.cluster.local:3306' (111)

  global
    log stdout format raw local0
    maxconn 4096

  defaults
    log global
    retries 2
    balance roundrobin
    timeout client 60s
    timeout connect 60s
    timeout server 60s

  listen mysql
    mode tcp
    bind *:3306
    balance roundrobin
    option tcpka
    option mysql-check user haproxy_check
    server mysql-primary 10.245.11.43:3306 check
    server mysql-secondary 10.245.98.225:3306 check

  listen stats 
    bind *:1936
    mode http
    stats enable
    stats hide-version
    stats realm Haproxy\ Statistics
    stats uri /
    stats auth Username:Password
1 Like

Looks like a very basic connectivity problem: from your client, port 3306 on haproxy.mysql.svc.cluster.local is unreachable.

i was using ip address (cluster ip) of the HAProxy service but the same issue…

NAME              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                         AGE
haproxy           ClusterIP   10.245.209.28    <none>        3306/TCP                        28h

Use 127.0.0.1 from the same box to check.

This is Kubernetes environment. Can’t run MySql client within HAProxy pod…

Then there is nothing else to do here. None of this has anything to do with haproxy.

ok… thank you for the confirmation. It means I can’t use HAProxy as LB for MySQL in Kubernetes…

Yes, you need to be able to troubleshoot basic Kubernetes networking issues. Maybe Kubernetes folks can help.