<p>I'm following the tutorial for setting up a replicated stateful application <a href="https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/" rel="nofollow noreferrer">here</a>, 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).</p>

<p>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.</p>

Neebz
<p>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.</p>

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