<p>I'm trying to build a Neo4j Learning Tool for some of our Trainings. I want to use Kubernetes to spin up a Neo4j Pod for each participant to use. Currently I struggle exposing the bolt endpoint using an Ingress and I don't know why.
Here are my deployment configs:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: neo4j
  namespace: learn
  labels:
    app: neo-manager
    type: database
spec:
  replicas: 1
  selector:
    matchLabels:
      app: neo-manager
      type: database
  template:
    metadata:
      labels:
        app: neo-manager
        type: database
    spec:
      containers:
        - name: neo4j
          imagePullPolicy: IfNotPresent
          image: neo4j:3.5.6
          ports:
            - containerPort: 7474
            - containerPort: 7687
              protocol: TCP
---
kind: Service
apiVersion: v1
metadata:
  name: neo4j-service
  namespace: learn
  labels:
    app: neo-manager
    type: database
spec:
  selector:
    app: neo-manager
    type: database
  ports:
    - port: 7687
      targetPort: 7687
      name: bolt
      protocol: TCP
    - port: 7474
      targetPort: 7474
      name: client
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: neo4j-ingress
  namespace: learn
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - host: learn.neo4j.com
      http:
        paths:
          - path: /
            backend:
              serviceName: neo4j-service
              servicePort: 7474
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: tcp-services
  namespace: learn
data:
  7687: "learn/neo4j-service:7687"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-ingress-controller
  namespace: learn
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ingress-nginx
  template:
    metadata:
      labels:
        app: ingress-nginx
    spec:
      containers:
        - name: nginx-ingress-controller
          image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.9.0-beta.16
          args:
            - /nginx-ingress-controller
            - --tcp-services-configmap=${POD_NAMESPACE}/tcp-services
          env:
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
</code></pre>

<p>The client gets exposed nicely and it reachable under <code>learn.neo4j.com</code> but I don't know where to point it to to connect to the DB using bolt. Whatever I try, it fails saying <code>ServiceUnavailable: Websocket Connection failure</code> (<code>WebSocket network error: The operation couldn’t be completed. Connection refused</code> in the console).
What am I missing?</p>

<p>The <code>nginx-ingress-controller</code> by default creates http(s) proxies only.</p>

<p>In your case you're trying to use a different protocol (bolt) so you need to configure your ingress controller in order for it to make a TCP proxy.</p>

<p>In order to do so, you need to create a configmap (in the nginx-ingress-controller namespace) similar to the following:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-services
  namespace: ingress-nginx
data:
  7687: "&lt;your neo4j namespace&gt;/neo4j-service:7687"
</code></pre>

<p>Then, make sure your ingress controller has the following flag in its command:</p>

<pre><code>--tcp-services-configmap tcp-services
</code></pre>

<p>This will make your nginx-ingress controller listen to port 7687 with a TCP proxy.</p>

<p>You can delete the <code>neo4j-bolt-ingress</code> Ingress, that's not going to be used.</p>

<p>Of course you have to ensure that the ingress controller correctly exposes the 7687 port the same way it does with ports 80 and 443, and possibly you'll have to adjust the settings of any firewall and load balancer you might have.</p>

<p>Source: <a href="https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/</a></p>
