gpt4 book ai didi

kubernetes - 如何通过Kubernetes服务(如网关API)路由到特定的Pod

转载 作者:行者123 更新时间:2023-12-04 01:18:59 25 4
gpt4 key购买 nike

我在Windows的“Docker table 面”上运行Kubernetes。

我有一个具有3个副本的部署的LoadBalancer服务。
我想通过某种方式(例如通过URL路径: :8090/pod1)访问SPECIFIC pod。

有什么办法可以实现这个用例?

deployment.yaml:

apiVersion: v1
kind: Service
metadata:
name: my-service1
labels:
app: stream
spec:
ports:
- port: 8090
targetPort: 8090
name: port8090
selector:
app: stream
# clusterIP: None
type: LoadBalancer
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: stream-deployment
labels:
app: stream
spec:
replicas: 3
selector:
matchLabels:
app: stream
strategy:
type: Recreate
template:
metadata:
labels:
app: stream
spec:
containers:
- image: stream-server-mock:latest
name: stream-server-mock
imagePullPolicy: Never
env:
- name: STREAMER_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: STREAMER_ADDRESS
value: stream-server-mock:8090
ports:
- containerPort: 8090


我的最终目标是实现 pods 的水平自动缩放。

应用程序的设计和工作方式(无kubernetes):

There are 3 components : REST-Server, Stream-Server (3 instances locally on different JVM on different ports), and RabbitMQ.


1 - The client sends a request to "REST-Server" for a stream url.
2 - The REST-Server puts in the RabbitMQ queue.
3 - One of the Stream-Server picks it up and populates its IP and sends back to REST-Server through RabbitMQ.
4 - The client receives the IP and establishes a direct WS connection using the IP.

我面临的问题是:
1 - When the client requests for a stream IP, one of the pods (lets say POD1) picks it up and sends its URL (which is service URL, comes through LoadBalancer Service).
2 - Next time when the client tries to connect (WebSocket Connection) using the Service IP, it wont be the same pod which accepted the request.

它应该是接受请求的同一pod,并且必须可由客户端访问。

最佳答案

如果不需要使用部署,则可以使用StatefulSets

对于副本3,您将有3个名为

  • 流部署-0
  • 流部署1
  • 流部署2

  • 您可以通过 $(podname).$(service name).$(namespace).svc.cluster.local访问每个 pods

    有关详细信息,请检查 this

    您可能还需要设置一个入口,以从集群外部指向每个 pods 。

    关于kubernetes - 如何通过Kubernetes服务(如网关API)路由到特定的Pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58007073/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com