Skip to content

Latest commit

 

History

History
48 lines (35 loc) · 1.33 KB

README.md

File metadata and controls

48 lines (35 loc) · 1.33 KB

go-grpc-k8s-resolver

GRPC resolver for Kubernetes service endpoints

PkgGoDev Go Report Card

Overview

Based off the DNS resolver, rather than making DNS queries, the k8s resolver queries the Kubernetes API for service endpoints matching the service name.

Using a headless service can be slow to update and the reverse proxies in service meshes may increase latency. By using the endpoints Kubernetes, updating the client with new or removing old server endpoints can be much faster.

overview

Example

package main

import (
	"log"
	pb "github.com/your-username/your-project/protos"
	_ "github.com/tcfw/go-grpc-k8s-resolver"
)

func main() {
	resolver := "dns"

	if os.Getenv("KUBERNETES_SERVICE_HOST") != "" {
		resolver = "k8s"
	}

	resolver.SetDefaultScheme(resolver)

	conn, err := grpc.Dial("my-service-name")
	if err != nil {
		panic(err)
	}
	defer conn.Close()

	client := pb.NewRouteGuideClient(conn)

	feature, err := client.GetFeature(context.Background(), &pb.Point{409146138, -746188906})
	if err != nil {
		panic(err)
	}

	log.Println(feature)
}