<p>Is there anything wrong with how I am trying to configure my Minikube cluster in a way the pods can access the PostgreSQL instance within the same machine?</p>
<p>I've access the <code>/etc/hosts</code> within the Minikube cluster via <code>minikube ssh</code> and returns:</p>
<pre><code>127.0.0.1       localhost
127.0.1.1       minikube
192.168.99.1    host.minikube.internal
192.168.99.110  control-plane.minikube.internal
</code></pre>
<p><strong>database-service.yaml</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: service-database
spec:
  type: ExternalName
  externalName: host.minikube.internal
  ports:
    - port: 5432
      targetPort: 5432
</code></pre>
<p><strong>pod-deployment.yaml</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
spec:
  ...
  template:
    ...
    spec:
      containers:
        - name: &lt;container_alias&gt;
          image: &lt;container_name&gt;
          env:
            - name: DB_URL
              value: &quot;jdbc:postgresql://service-database/&lt;database_name&gt;&quot;
          ports:
            - containerPort: 8080
</code></pre>
<p><em>Note</em>: <code>DB_URL</code> environment variable points to the <code>spring.datasource.url</code> in the <code>application.properties</code> in SpringBoot.</p>
<p>Then when I tried to get the logs printed, I am getting this exception:</p>
<pre><code>Caused by: java.net.UnknownHostException: service-database
</code></pre>

David B
<blockquote>
<p>I've access the /etc/hosts within the Minikube cluster via minikube ssh and returns</p>
</blockquote>
<p>That may be true, but for the same reason kubernetes does not expose the <code>/etc/hosts</code> of its Nodes, nor will minikube do the same thing. Kubernetes has its own DNS resolver, and thus its own idea of what should be in <code>/etc/hosts</code> (docker does the same thing -- it similarly does not just expose the host's <code>/etc</code> but rather allows the user to customize that behavior on container launch)</p>
<p>There is a formal mechanism to tell kubernetes that you wish to manage the DNS resolution <em>endpoints</em> manually -- that's what <a href="https://kubernetes.io/docs/concepts/services-networking/service/#headless-services" rel="nofollow noreferrer">a Headless Service</a> does, although usually the &quot;manually&quot; part is done by the <code>StatefulSet</code> controller, but there's nothing stopping other mechanisms from grooming that list:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: service-database
spec:
  type: ClusterIP
  # yes, literally the word &quot;None&quot;
  clusterIP: None
  ports:
    - name: 5432-5432
      port: 5432
      targetPort: 5432
---
apiVersion: v1
kind: Endpoints
metadata:
  name: service-database
subsets:
- addresses:
  - ip: 192.168.99.1
  ports:
  - name: 5432-5432
    port: 5432
    protocol: TCP
</code></pre>
<p>and now the internal DNS will resolve <code>service-database</code> to be the answers <code>192.168.99.1</code> and also populate the SRV records just like normal</p>
