title: How to connect PostgresSQL pod to Ruby on Rails pod in Kubernetes
body: <p>I have 3 pods in total.</p>
  <ol>
  <li>Ruby on Rails APP-1</li>
  <li>Ruby on Rails APP-2</li>
  <li>PostgreSQL database</li>
  </ol>
  <p>APP-1 and the postgreSQL database in the same namespace but different nodes
  APP-2 is in its own namespace and is on the same node as APP-1</p>
  <p>I have 3 nodes in total.
  I want my Ruby on Rails app(s) to connect to the PostgreSQL database.</p>
  <p>But currently this is failing with the error msg:</p>
  <pre><code>ActiveRecord::ConnectionNotEstablished (could not translate host name &quot;myteam-demodb-0&quot; to address: Name or service not known
  ):
  </code></pre>
  <p>database.yml:</p>
  <pre><code>development:
    adapter: postgresql
    encoding: utf8
    database: demodb
    username: myowner
    password: &lt;%= ENV[&quot;db_secret&quot;] %&gt;
    host: myteam-demodb
    port: 5432
  </code></pre>
  <p>This is my <code>kubectl get services</code> output -</p>
  <p>Namespace 1:</p>
  <pre><code>NAME                     TYPE       CLUSTER-IP     EXTERNAL-IP       PORT(S) 
  APP-1                  ClusterIP   172.20.19.234    &lt;none&gt;          80/TCP    126m
  myteam-demodb          ClusterIP   172.20.147.0     &lt;none&gt;        5432/TCP   126m
  </code></pre>
  <p>Namespace 2:</p>
  <pre><code>&gt; NAME     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S) 
  &gt; APP-2   ClusterIP   172.20.234.194        &lt;none&gt;    80/TCP    94m
  </code></pre>
  <p><code>kubectl describe service myteam-demodb</code> output:</p>
  <pre><code>Name:              myteam-demodb
  Namespace:         jx-staging
  Labels:            application=spilo
                     cluster-name=myteam-demodb
                     spilo-role=master
                     team=myteam
  Annotations:       &lt;none&gt;
  Selector:          &lt;none&gt;
  Type:              ClusterIP
  IP Family Policy:  SingleStack
  IP Families:       IPv4
  IP:                172.20.147.0
  IPs:               172.20.147.0
  Port:              postgresql  5432/TCP
  TargetPort:        5432/TCP
  Endpoints:         10.0.3.194:5432
  Session Affinity:  None
  Events:            &lt;none&gt;
  </code></pre>
  <p>postgreSQL.yaml:</p>
  <pre><code>apiVersion: &quot;acid.zalan.do/v1&quot;
  kind: postgresql
  metadata:
    name: &quot;myteam-demodb&quot;
    annotations:
      meta.helm.sh/release-name: 'election-web-app'
    namespace: jx-staging
    labels:
      gitops.jenkins-x.io/pipeline: 'namespaces'
  spec:
    teamId: &quot;myteam&quot;
    volume:
      size: 1Gi
    numberOfInstances: 2
    users:
      myowner: # database owner
        - superuser
        - createdb
      foo_user: [] # role for application foo
    databases:
      demodb: myowner # dbname: owner
    preparedDatabases:
      bar: {}
    postgresql:
      version: &quot;13&quot;
  </code></pre>
  <hr />
  <p>Edit:
  <code>kubectl get service kube-dns -n kube-system</code> output:</p>
  <pre><code>NAME     TYPE      CLUSTER-IP    EXTERNAL-IP   PORT(S)        
  kube-dns ClusterIP 172.20.0.10   &lt;none&gt;    53/UDP,53/TCP   
  </code></pre>