<p>Currently, I am getting the <code>ECONNREFUSED</code> where node can't connect to the database. I am not sure where the database host is supposed to end up. Should I be using <code>localhost:7474</code>, <code>127.0.0.1:7474</code>, <code>0.0.0.0:7474</code>, or am I supposed to use some host that gets generated when I get my Kubernetes pods up that I can somehow pass in? e.g. like <code>$(minikube ip) = 192.168.90.100:7474</code>, but for my database? Is there an ENV containing the database host that I am supposed to be pulling from somewhere?</p>

<pre><code>const neo4jDatabase = connect({
  server: 'http://&lt;what goes here!?&gt;:7474',
  user: process.env.DB_USER,
  pass: process.env.DB_PASS,
});
</code></pre>

<p>I seem to have gotten the pods running with the below .yml configs, but am not sure if the neo4j one is correct.</p>

<pre><code>NAME                     READY     STATUS    RESTARTS   AGE
neo4j-4166717986-8qbwq   1/1       Running   0          41m
node-481322091-g27md     1/1       Running   0          11m
</code></pre>

<p><strong>node.yml</strong></p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: node
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: node
        tier: backend
        track: stable
    spec:
      containers:
        - name: node
          image: "myapp"
          ports:
            - name: nodeport
              containerPort: 8080
          env:
           - name: DB_USER
             valueFrom:
               configMapKeyRef:
                 name: config
                 key: db_user
           - name: DB_PASS
             valueFrom:
               configMapKeyRef:
                 name: config
                 key: db_pass
---
apiVersion: v1
kind: Service
metadata:
  name: node
spec:
  selector:
    app: node
    tier: backend
  ports:
    - protocol: TCP
      port: 80
      targetPort:
  type: LoadBalancer
</code></pre>

<p><strong>neo4j.yml</strong></p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: neo4j
spec:
  template:
    metadata:
      labels:
        run: neo4j
    spec:
      containers:
        - name: neo4j
          image: "my-neo4j"
          ports:
            - containerPort: 7474
---
apiVersion: v1
kind: Service
metadata:
  name: neo4j
  labels:
    run: neo4j
spec:
  selector:
    run: neo4j
  ports:
    - port: 7474
      targetPort: 7474
      protocol: TCP
</code></pre>

<p>Perhaps a less known feature of Kubernetes is the fact that some <em>magic</em> environment variables are injected in the running pods.</p>

<p>In your particular case, pods have an environment variable for each service in the namespace. The format is the following:</p>

<pre><code>&lt;your service&gt;_SERVICE_HOST
&lt;your service name&gt;_SERVICE_PORT_EXPOSED_PORT
</code></pre>

<p>You can verify this is true by attaching to a running pod with <code>kubectl exec -ti &lt;your pod id&gt; sh</code> and issuing a <code>printenv</code> command.</p>

<p>Please note that if the service was created AFTER the pod, you have to delete the pod with <code>kubectl delete pod &lt;your pod id&gt;</code> to force recreation (and injection) of the environment variables.</p>

<p>In your case, the final code will look like this:</p>

<pre><code>const serviceHost = process.ENV.NEO4J_SERVICE_HOST;
const servicePort = process.ENV.NEO4J_SERVICE_PORT_EXPOSED_PORT;
const neo4jDatabase = connect({
  server: `http://${serviceHost}:${servicePort}`,
  user: process.env.DB_USER,
  pass: process.env.DB_PASS,
});
</code></pre>
