[英]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.