如何将RESTful localhost调用从一个特定的副本集路由/转发到另一个副本集,而不全局公开端口



基本上,我想做的是假设您有一个副本集。这个名为A的副本集包含"发布"到localhost:9000的pod,现在我有另一个副本集B,它的pod侦听localhost:8080。我想将对A上localhost:9000到副本集B的调用转移到端口8080。唯一需要注意的是,如果我有另一个副本集C,其pod也监听端口8080,则它们不应该接收流量。https://i.stack.imgur.com/tyU0M.png

只需为B定义一个服务即可。对于a,不发布到localhost,而是使用服务B的名称发布即可。C可以拥有使用相同端口的服务,但不会获得流量,因为a明确发布到服务B。

apiVersion: v1
kind: Service
metadata:
labels:
app: app-b
name: service-b  # <-- name of this service
spec:
type: ClusterIP
selector:
app: app-b
ports:
- name: http
port: 9000
protocol: TCP
targetPort: 8080

curl -XPOST http://service-b:9000<--无论是吊舱还是属于C的服务都不会得到这个请求

相关内容

最新更新