简体   繁体   English

如何将流量转发到特定吊舱?

[英]How to forward Traffic to specific pod?

I have an app which using in memory database. 我有一个在内存数据库中使用的应用程序。 I created statefulset using the Pod with let's say 3 replica. 我使用带有3个副本的Pod创建了statefulset。 used PVC for storing the database related files. 用于存储数据库相关文件的PVC。

I used a Loabalancer to expose the statefulset. 我使用了Loabalancer来公开有状态集。

So when the traffic hits loadbalancer each time it's forwarded to different pods. 因此,当流量每次到达负载均衡器时都转发到不同的Pod。

Is there anyway I can control the loadbalacing to the Pod based on some condition ( like if Client IP is X go to pod Y) ? 无论如何,我是否可以根据某些条件控制到Pod的负载平衡(例如,如果客户端IP为X,则转到Pod Y)?

The very fact that you have a leader/follower topology, the ask to direct traffic to a said nome (master node) is flawed for a couple of reasons: 事实上,您具有领导者/从属者拓扑,将流量定向到所述nome(主节点)的要求存在缺陷,其原因有两个:

  1. What happens when the current leader fails over and there is a new election to select a new leader 当前领导者进行故障转移并且有新的选举来选择新领导者时会发生什么
  2. The fact that pods are ephemeral they should not have major roles to play in production, instead work with deployments and their replicas. Pod是临时性的,它们不应在生产中扮演主要角色,而应与部署及其副本一起使用。 What you are trying to achieve is an anti-pattern 您要实现的是反模式

In any case, if this is what you want, maybe you want to read about gateways in istio which can be found here 无论如何,如果这是您想要的,也许您想阅读有关gateways in istio中的gateways in istio ,可以在这里找到

You can use the K8s ingress resource to solve this case. 您可以使用K8s入口资源来解决这种情况。 I think what you're trying to do is host-based routing. 我认为您要尝试的是基于主机的路由。 Put your pods behind different services using labels. 使用标签将您的广告连播置于其他服务的后面。 In your case 1 - 100 behind service 1, 100 - 200 behind service 2 and so on. 在您的情况下,服务1落后1-100,服务2落后100-200,依此类推。 Then create an ingress resource to redirect incoming traffic to different services based on host or path, whatever you require. 然后创建一个入口资源,以根据主机或路径将传入流量重定向到其他服务,无论您需要什么。 You may have to use a proxy like Nginx to get this working in a public cloud platform. 您可能必须使用像Nginx这样的代理才能在公共云平台上正常工作。 The YAML manifest would be something like this: YAML清单将是这样的:

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: example-ingress annotations: kubernetes.io/ingress.class: nginx spec: rules: - host: host1.com http: paths: - path: /web1 backend: serviceName: service1 servicePort: 443 - path: /api/v1/a backend: serviceName: service2 servicePort: 80 - path: /api/v1/b backend: serviceName: service3 servicePort: 80 - host: host2.com http: paths: - path: /web2 backend: serviceName: service4 servicePort: 443 - path: /api/v2/a backend: serviceName: service5 servicePort: 80

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

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