<p>I am deploying a simple web application. I divided it into 3 pods:front end, back end, and postgres db. I successfully deployed my front end and back end to google kubernetes service and they works as expected. But for my postgresql db server, I used the following yamls. The postgres image is created by me using standard postgres images from dockerhub. I created some tables, and inserted some data and pushed to DockerHub. My backend is not able to make connection to my db. I think I might need to change my Java connection code.Not sure on using localhost. It works without any issue on my local Eclipse Jee and Tomcat. </p>

<pre><code>//my pod.yaml
apiVersion: v1
kind: Pod
metadata:
   name: postgres-app-pod
   labels:
      name: postgres-app-pod
      app: demo-geo-app
spec:
   containers:
   - name: postgres
     image: myrepo/example:v1
     ports:
     - containerPort: 5432

//my service.yaml
apiVersion: v1
kind: Service
metadata:
   name: db
   labels:
      name: db-service
      app: demo-geo-app
spec:
   ports:
   - port: 5432
     targetPort: 5432
   selector:
      name: postgres-pod
      app: demo-geo-app 

   //from my java backend, I access my db server this way.
String dbURL = "jdbc:postgresql://localhost:5432/Location?user=postgres&amp;password=mysecretpassword";
</code></pre>

ENGLISH TEACHER
<p>there are two issues to be fixed.</p>

<ol>
<li>the service selector key:value should match with pod labels</li>
<li>replace localhost with postgresql service dns</li>
</ol>
