繁体   English   中英

Kubernetes 服务的快速网关配置

[英]Express-gateway config for Kubernetes services

我正在尝试为我的微服务研究配置 api-gateway。 我创建了一个 pod 作为该 pod 的 auth-depl 和 auth-src 服务。 我还有另一个 pod&service 作为 links-depl 和 links-serv。 我想为它制作一个 api-gateway。 这些服务。

kubeectl get pods”的 output :

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

kubectl get services ”的 output:

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

我的 express-gateway 配置文件是这样的:

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

我只是尝试使用 api-gateway 访问身份验证服务,但我不能这样做。 为此,我发送此请求:

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

我得到“无法发布/用户/注册错误

但是当我向GET http://localhost:30624/ip发送请求时,我可以收到响应。

如何配置此 gateway.config.yaml 文件来解决我的问题。

在 Express Gateway 中,您需要为每个 ApiEndpoint 定义一个管道。 您有一个将(面向外部的)“api”端点映射到服务端点“httpbin”的管道,但是您缺少一个到 map 的“用户”端点到您的注册端点。

您需要为此添加一个管道到您的“管道”部分:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM