是否可以将流量路由到特定的Pod? [英] Is it possible to route traffic to a specific Pod?

查看:183
本文介绍了是否可以将流量路由到特定的Pod?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我正在GKE中运行我的应用程序,这是一个多租户应用程序.

Say I am running my app in GKE, and this is a multi-tenant application.

我创建了多个托管应用程序的Pod.

I create multiple Pods that hosts my application.

现在我要: 客户1-1000使用Pod1 客户1001-2000使用Pod2 等

Now I want: Customers 1-1000 to use Pod1 Customers 1001-2000 to use Pod2 etc.

如果我有一个指向我的集群的gcloud全局IP,是否可以根据传入的ipaddress/域将请求路由到包含客户数据的正确Pod?

If I have a gcloud global IP that points to my cluster, is it possible to route a request based on the incoming ipaddress/domain to the correct Pod that contains the customers data?

推荐答案

您可以保证与服务的会话亲和性,但不能保证您所描述的.因此,您的客户1-1000不会使用pod-1,但是他们会使用所有pod(因为一项服务使负载平衡变得简单),但是每位客户在回到使用您的服务时都将被重定向到同一荚.

You can guarantee session affinity with services, but not as you are describing. So, your customers 1-1000 won't use pod-1, but they will use all the pods (as a service makes a simple load balancing), but each customer, when gets back to hit your service, will be redirected to the same pod.

注意:始终在(默认值10800)中指定的时间之内:

Note: always within time specified in (default 10800):

service.spec.sessionAffinityConfig.clientIP.timeoutSeconds

这将是该服务的yaml文件:

This would be the yaml file of the service:

kind: Service
apiVersion: v1
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
  sessionAffinity: ClientIP

如果您还想指定时间,则需要添加以下内容:

If you want to specify time, as well, this is what needs to be added:

  sessionAffinityConfig:
    clientIP:
      timeoutSeconds: 10


请注意,上面的示例可以直接与ClusterIP类型的服务(很少见)或与Loadbalancer类型的服务进行交互,但不能与NodePort类型的服务后面的Ingress配合使用.这是因为对于Ingress,请求来自许多随机选择的源IP地址.


Note that the example above would work hitting ClusterIP type service directly (which is quite uncommon) or with Loadbalancer type service, but won't with an Ingress behind NodePort type service. This is because with an Ingress, the requests come from many, randomly chosen source IP addresses.

这篇关于是否可以将流量路由到特定的Pod?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆