How to access replicated databases in Kubernetes?

4/15/2020

I'm following the tutorial for setting up a replicated stateful application here, and I've come across a problem, as the tutorial mentions that making a headless services to access the pods is how you're going to connect to the master DB for writes. This is a problem since the service is headless it cannot be externally exposed (to my knowledge at least).

So my question: Should I make a dedicated service in my cluster to handle database connections, much like an API, that can act as a middle-ware between my application and my database? Or is there some other approach to hosting a replicated database in a cluster? I'm very new to Kubernetes so my question might seem trivial, though I have tried to find resources online on this topic to no help.

-- Neebz
database
kubernetes
mysql
replication

1 Answer

4/15/2020

A headless Service is a DNS resolver inside your cluster which resolves to all internal IP addresses of the pods the service is pointing on. So you can never expose it, because the IP adresses only work from inside your cluster.

The easiest way would to build an Api-layer to access the Database and expose this API.

-- Alex
Source: StackOverflow