k8sresolver

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2022 License: MIT Imports: 17 Imported by: 0

README

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)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBuilder

func NewBuilder() resolver.Builder

NewBuilder creates a k8sBuilder which is used to factory K8S service resolvers.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL