简体   繁体   English

Kubernetes负载平衡

[英]Kubernetes load balancing

I'm studing Kubernetes (with no regard of a specific Cloud Provider) and it's not so clear if the most generic Service (not the Service of type Load-Balancer) works as an internal load balancer among the various replicas of a single microservice. 我正在研究Kubernetes(不考虑特定的Cloud Provider),并且不清楚最通用的服务(不是Load-Balancer类型的服务)是否在单个微服务的各个副本之间充当内部负载平衡器。

So how to implement internal load balancing among replicas without exposing the microservice to the outside traffic ? 那么, 如何在副本之间实现内部负载平衡而不将微服务暴露给外部流量呢?

You can use kubernetes service object which is top of the pod. 您可以使用Pod顶部的kubernetes服务对象。

Service object manage the connection and traffic it can be also used as internal load balancer. 服务对象管理连接和流量,它也可以用作内部负载平衡器。

You can create service with yaml file 您可以使用yaml文件创建服务

kind: Service
apiVersion: v1
metadata:
  name: myapp-service
spec:
  selector:
    app: Myapp
  ports:
  - port: 80
    targetPort: 9376

On the base of the same selector in pod metadata to divert the traffic to that pods. 在pod元数据中相同选择器的基础上,将流量转移到该pod。 Just use proper selector in specs section inside service and pods. 只需在service和pod内的specs部分中使用适当的选择器即可。

in order to create an internal load balancer , you will need to create a service based on selectors in order to find the correct pod to direct the traffic. 为了创建一个内部负载均衡器,您将需要基于选择器创建一个服务,以便找到正确的Pod来引导流量。

in order for the pod to be blocked for outside traffic it should be of type ClusterIP. 为了阻止Pod阻止外部流量,它的类型应该为ClusterIP。

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

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