百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
K

kuberesolver

> 云原生
开源

Grpc 有 Kubernetes 解析器的负载平衡器

638 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

Grpc 有 Kubernetes 解析器的负载平衡器

kuberesolver

A Grpc name resolver by using kubernetes API. It comes with a small ~250 LOC kubernetes client to find service endpoints. Therefore it won't bloat your binaries.

USAGE

go

// Import the module
import "github.com/sercand/kuberesolver/v6"
	
// Register kuberesolver to grpc before calling grpc.NewClient
kuberesolver.RegisterInCluster()

// it is same as
resolver.Register(kuberesolver.NewBuilder(nil /*custom kubernetes client*/ , "kubernetes"))

// if schema is 'kubernetes' then grpc will use kuberesolver to resolve addresses
cc, err := grpc.NewClient("kubernetes:///service.namespace:portname", opts...)

An url can be one of the following, grpc naming docs

kubernetes:///service-name:8080
kubernetes:///service-name:portname
kubernetes:///service-name.namespace:8080
kubernetes:///service-name.namespace.svc.cluster_name
kubernetes:///service-name.namespace.svc.cluster_name:8080

kubernetes://namespace/service-name:8080
kubernetes://service-name:8080/
kubernetes://service-name.namespace:8080/
kubernetes://service-name.namespace.svc.cluster_name
kubernetes://service-name.namespace.svc.cluster_name:8080

* Please note that the cluster_name is not used in resolving the endpoints of a Service. It is only there to support fully qualified service names, e.g. test.default.svc.cluster.local.

Using alternative Schema

Use RegisterInClusterWithSchema(schema) instead of RegisterInCluster on start.

Client Side Load Balancing

You need to pass loadBalancingPolicy option to grpc when setting up a new client:

go
grpc.NewClient(
    "kubernetes:///service:grpc", 
    grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`),
    grpc.WithTransportCredentials(insecure.NewCredentials()),
)

This will create subconnections for each available service endpoints.

How is this different from dialing to service.namespace:8080

Connecting to a service by dialing to service.namespace:8080 uses DNS and it returns service stable IP. Therefore, gRPC doesn't know the endpoint IP addresses and it fails to reconnect to target services in case of failure.

Kuberesolver uses kubernetes API to get and watch service endpoint IP addresses. Since it provides and updates all available service endpoints, together with a client-side balancer you can achive zero downtime deployments.

RBAC

You need give GET and WATCH access to the endpointslices if you are using RBAC in your cluster.

Using With TLS

You need to a certificate with name service-name.namespace in order to connect with TLS to your services.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gogrpckubernetesresolver

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类云原生
定价开源

> 相关工具

K
Kubernetes
容器编排事实标准
H
Helm
Kubernetes 包管理器
S
seaweedfs
SeaweedFS is a distributed storage system for object storage (S3), file systems, and Iceberg tables,