<p>I am trying to set up a conventional web app with a database in Kubernetes. I have accomplished it by configuring 2 services and 2 deployments - one for the app and one for the database. Now I would like to make my database accessible only from the app pods, ie not expose it to outside world like a service. Is it possible using only Kubernetes configuration? </p>

<p>There are following ways to expose the pods.  </p>

<p>purpose is inter-service communication</p>

<p><strong>Internally expose</strong>  </p>

<ul>
<li>service <code>type=clusterIP</code>  </li>
<li><strong>Headless-service</strong> <code>clusterIP: None</code> is used for database pods </li>
</ul>

<blockquote>
  <p>Sometimes you don’t need or want load-balancing and a single service IP. <a href="https://kubernetes.io/docs/concepts/services-networking/service/#headless-services" rel="nofollow noreferrer">headless-services</a></p>
</blockquote>

<p><strong>Externally expose</strong><br>
 Exposing service to the customers.  </p>

<ul>
<li>service <code>type=NodePort</code>  or <code>type=LoadBalancer</code></li>
</ul>
