使用 kubernetes 进行动态负载平衡

Dynamic load balancing with kubernetes

我是 kubernetes 的新手。

我们有 50 个 IP 地址,IP 地址有请求限制。该限制是保存在数据库中的一个值。我们希望负载均衡器根据数据库中限制最多的那个来选择它。 Kubernetes 可以做到吗?

首先,我建议您阅读有关 Kubernetes 网络的官方文档 - 您可以在这里找到它:kubernetes-networking. Especially read about services。 Kubernetes 中的原始负载均衡器从不检查特定于应用程序的数据库。

An abstract way to expose an application running on a set of Pods as a network service. With Kubernetes you don't need to modify your application to use an unfamiliar service discovery mechanism. Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods, and can load-balance across them.

服务类型示例 clusterIP

Kubernetes assigns a stable, reliable IP address to each newly-created Service (the ClusterIP) from the cluster's pool of available Service IP addresses. Kubernetes also assigns a hostname to the ClusterIP, by adding a DNS entry. The ClusterIP and hostname are unique within the cluster and do not change throughout the lifecycle of the Service. Kubernetes only releases the ClusterIP and hostname if the Service is deleted from the cluster's configuration. You can reach a healthy Pod running your application using either the ClusterIP or the hostname of the Service.

看看它在 GKE 中的样子:GKE-IP-allocation

You can specify also your own cluster IP address as part of a Service creation request - set the .spec.clusterIP field.

The IP address that you choose must be a valid IPv4 or IPv6 address from within the service-cluster-ip-range CIDR range that is configured for the API server. If you try to create a Service with an invalid clusterIP address value, the API server will return a 422 HTTP status code to indicate that there's a problem.

总结一下。 Kubernetes 负载均衡器永远不会深入研究您的应用程序。要连接到您的应用程序,您需要创建服务。 Kubernetes 为每个新创建的服务分配一个稳定、可靠的 IP 地址,您可以从该地址在集群内部或外部访问您的应用程序。您还可以为每个服务手动分配 IP。