<p>My Kubernetes cluster setup has n-tier web application running in dev and test environments on AWS. For the production environment, postgres RDS was chosen, to ensure periodic backup. While creating a postgres RDS instance, kubernetes-vpc was selected for db-subnet to keep networking stuff simple during pilot run.
Also, security group selected is the same as kubernetes-minions.</p>

<p>Following is the service and endpoint yaml:</p>

<pre><code>apiVersion: v1
kind: Service
metadata: 
  labels: 
    name: pgsql-rds
  name: pgsql-rds
spec: 
  ports: 
    - port: 5432
      protocol: TCP
      targetPort: 5432
</code></pre>

<p>--</p>

<pre><code>apiVersion: v1
kind: Endpoints
metadata:
  name: pgsql-rds
subsets:
- addresses:
  - ip: 52.123.44.55
  ports:
  - port: 5432
    name: pgsql-rds
    protocol: TCP
</code></pre>

<p>When web-app service and deployment is created, it's unable to connect to RDS instance.
The log is as follows:</p>

<p><em>java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: Connection to pgsql-rds:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.</em></p>

<p>What am I missing? any pointers to resolve the issue appreciated.</p>

<p>This has to do with DNS resolving. When you use the RDS dns name INSIDE the same VPC it will be resolved to a private ip. When you use the same dns name on the internet or another VPC you will get the public ip of the RDS instance.</p>

<p>This is a problem because from another VPC you can not make use of the load balancing feature unless you expose the RDS instance to the public internet.</p>
