i'm implementing an API Gateway on openshift with spring cloud gateway and spring cloud kubernetes discovery.
I started from the project https://github.com/salaboy/s1p_gateway.
My gateway configuration is:
cloud:
gateway:
discovery:
locator:
enabled: true
url-expression: "'http://'+serviceId+':'+port"
kubernetes:
reload:
enabled: true
mode: polling
period: 5000
discovery:
service-labels:
type: "java-api"
When i view my /actuator/gateway/routes i can see services discovered:
{
"predicate":"Paths: [/common/**], match trailing slash: true",
"route_id":"ReactiveCompositeDiscoveryClient_common",
"filters":[
"[[RewritePath /common/(?<remaining>.*) = '/${remaining}'], order = 1]"
],
"uri":"http://common:8085",
"order":0
}
The problem is that 8085 is the targetPort (i.e. pod port) and not the service port:
kind: Service
apiVersion: v1
metadata:
name: common
namespace: p4p
selfLink: /api/v1/namespaces/myspace/services/common
uid: 1851a76f-4764-11ea-a02c-000d3aa9b693
resourceVersion: '28657990'
creationTimestamp: '2020-02-04T15:36:21Z'
labels:
app: common
type: java-api
spec:
ports:
- protocol: TCP
port: 8080
targetPort: 8085
selector:
app: common
deploymentconfig: common
clusterIP: 172.30.7.24
type: ClusterIP
sessionAffinity: None
status:
loadBalancer: {}
In order to get API gateway to work i MUST to align pod port and service port, but it sounds quite strange.