kubernetesapi-gatewayexpress-gateway

Express-gateway config for Kubernetes services


Im trying to configure api-gateway for my micro service study. I created a pod as a auth-depl and auth-src service for this pod. Also I have another pod&service as links-depl and links-serv. And I want to make a api-gateway for. these services.

The output for "kubeectl get pods":

NAME                                READY   STATUS    RESTARTS   AGE
api-gateway-depl-88b4c8b77-zdgjw    1/1     Running   0          10m
auth-depl-7cb78c4dcf-wxrwd          1/1     Running   0          10m
links-depl-69d749955d-5xf9b         1/1     Running   0          6m3s

The output for "kubectl get services":

NAME              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
api-gateway-srv   NodePort    10.98.213.62     <none>        8080:30623/TCP   12m
auth-srv          ClusterIP   10.98.214.62     <none>        3000/TCP         12m
kubernetes        ClusterIP   10.96.0.1        <none>        443/TCP          25h
links-srv         ClusterIP   10.99.37.46      <none>        3001/TCP         12m

And my express-gateway config file like that:

http:
  port: 8080
admin:
  port: 9876
  host: localhost
apiEndpoints:
  api:
    host: localhost
    paths: '/ip'
  user:
    host: localhost
    paths: '/user/signup'
serviceEndpoints:
  httpbin:
    url: 'https://httpbin.org'
  usersrv:
    url: 'http://auth-srv:3000/user/signup'
policies:
  - basic-auth
  - cors
  - expression
  - key-auth
  - log
  - oauth2
  - proxy
  - rate-limit
pipelines:
  default:
    apiEndpoints:
      - api
    policies:
      - proxy:
          - action:
              serviceEndpoint: httpbin 
              changeOrigin: true

I just tried to reach auth service with api-gateway, but I cannot do this. For this, I send this request:

POST http://localhost:30623/user/signup

and I get "Cannot POST /user/signup error

but when I send a request to GET http://localhost:30624/ip I can receive the response.

How can I configure this gateway.config.yaml file for solving my issue.


Solution

  • In Express Gateway, you need to have a pipeline defined for each of your ApiEndpoints. You have a pipeline which maps the (outside-facing) "api" endpoint to the service endpoint "httpbin", but you are missing one to map the "user" endpoint to your signup endpoint.

    You need to add a pipeline for this to your "pipelines" section:

    pipelines:
      # Existing "default" pipeline
     user:
        apiEndpoints:
          - user
        policies:
          - proxy:
              - action:
                  serviceEndpoint: usersrv 
                  changeOrigin: true