Skip to content

Commit e481e21

Browse files
committed
Use github.com/sercand/kuberesolver for grpc forwarding in kubernetes
1 parent ebf9218 commit e481e21

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

cmd/veneur/main.go

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"github.com/getsentry/raven-go"
9+
"github.com/sercand/kuberesolver"
910
"github.com/sirupsen/logrus"
1011
"github.com/stripe/veneur"
1112
"github.com/stripe/veneur/ssf"
@@ -47,6 +48,10 @@ func main() {
4748
}
4849

4950
logger := logrus.StandardLogger()
51+
// This is safe outside of a cluster althouth attempting to use a
52+
// kubernetes:// url will cause a failure.
53+
kuberesolver.RegisterInCluster()
54+
5055
server, err := veneur.NewFromConfig(logger, conf)
5156
veneur.SetLogger(logger)
5257
if err != nil {

example.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ tls_authority_certificate: ""
4040
# Use a static host for forwarding
4141
#forward_address: "http://veneur.example.com"
4242
# Do not add a prefix when setting the forward address for gRPC.
43+
# If using grpc in a kubernetes cluster, you may use urls compatible with
44+
# https://github.com/sercand/kuberesolver to get better native load balancing
45+
# behavior than the connection-based load balancing provided by kubernetes
46+
# services.
4347
#forward_address: "veneur.example.com"
4448
forward_address: ""
4549

server.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/zenazn/goji/bind"
3333
"github.com/zenazn/goji/graceful"
3434
"google.golang.org/grpc"
35+
"google.golang.org/grpc/balancer/roundrobin"
3536

3637
"github.com/pkg/profile"
3738

@@ -842,7 +843,8 @@ func (s *Server) Start() {
842843
// Initialize a gRPC connection for forwarding
843844
if s.forwardUseGRPC {
844845
var err error
845-
s.grpcForwardConn, err = grpc.Dial(s.ForwardAddr, grpc.WithInsecure())
846+
s.grpcForwardConn, err = grpc.Dial(s.ForwardAddr, grpc.WithInsecure(),
847+
grpc.WithBalancerName(roundrobin.Name))
846848
if err != nil {
847849
log.WithError(err).WithFields(logrus.Fields{
848850
"forwardAddr": s.ForwardAddr,

0 commit comments

Comments
 (0)