<p>I'm trying to use Spring Gateway to route requests to some Spring Boot pods exposing REST APIs.</p>

<p>I have a search service deployed like this:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: search
  name: search
spec:
  replicas: 1
  selector:
    matchLabels:
      app: search
  strategy:
    type: Recreate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: search
    spec:
      containers:
      - image: &lt;ommited&gt;
        name: search-service
        imagePullPolicy: Always
        resources: {}
      imagePullSecrets:
        - name: &lt;ommited&gt;
status: {}
---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: search
  name: search
spec:
  ports:
  - name: stage
    port: 8080
    protocol: TCP
  selector:
    app: search
  type: ClusterIP
</code></pre>

<p>It deploys fine and is accessible if I use an ngnix ingress deployment.
I want to use Spring Gateway as an entry point however so I deploy it in another pod like so:</p>

<pre><code>&lt;ommiting deployment&gt;
---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: gateway
  name: gateway
spec:
  ports:
  - name: stage
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: gateway
  type: LoadBalancer
</code></pre>

<p>With a defined route:</p>

<pre><code>.route("search", r -&gt; r.path("/search")
                        .uri("http://search:8080/search"))
</code></pre>

<p>It also deploys fine and is accessible externally.</p>

<p>When the gateway pod tries to route the request to the search pod however it gets an explicit "connection refused".</p>

<pre><code>{
  "timestamp": "...",
  "path": "/search",
  "status": 500,
  "error": "Internal Server Error",
  "message": "finishConnect(..) failed: Connection refused: search/10.100.130.149:8080",
  "requestId": "a3af8165-1"
}
</code></pre>

<p>Hostname is resolved properly.</p>

<p>Also tried with connecting from gateway to search <code>nc</code>:</p>

<pre><code>kubectl exec -it gateway-7798cb658-ffzvb -- nc -z search 8080
command terminated with exit code 1
</code></pre>

<p>Again host is properly resolved, so expect I have misconfigured ports somewhere.
I have verified that the search Spring Boot app listens on 8080 and 8080 is exposed via the docker container and the search pod.</p>

<p>Any help appreciated, thanks!</p>

Simeon
<p>Check the description of the <code>search</code> service using command <code>kubectl describe svc search</code> and verify that <code>port</code> is matching with the port (<code>containerPort</code>) the pod is listening on. Also you can define a <code>targetPort</code> in the service to explicitly point to the port(<code>containerPort</code>) the container is listening on.</p>
