go-grpc-client-lb

module
v0.0.0-...-d441da7 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2020 License: Apache-2.0

README

go-grpc-client-lb

Example of gRPC client-side load balancing in Golang

Services


Build

  1. Server

    make build-server
    # or
    go build -o grpc-server ./server
    
  2. Client

    make build-client
    # or
    go build -o grpc-client ./client
    

Run

  1. Run server

    make run-server
    # or
    ./grpc-server
    
  2. In another shell, run client

    make run-client
    # or
    ./grpc-client
    
From source
  1. Run server

    make run-server-src
    # or
    protoc --proto_path=./proto/ --go_out=plugins=grpc:domain ./proto/*
    GO111MODULE=on go run ./server/main.go
    
  2. In another shell, run client

    make run-client-src
    # or
    protoc --proto_path=./proto/ --go_out=plugins=grpc:domain ./proto/*
    GO111MODULE=on go run ./client/main.go
    

Docker

Build
  1. Server

    make container-build-server
    # or
    docker build -t grpc/grpc-server -f server.Dockerfile .
    
  2. Client

    make container-build-client
    # or
    docker build -t grpc/grpc-client -f client.Dockerfile .
    
Run
  1. Run server

    make container-run-server
    # or
    docker run -ti --rm --name server -p 50051:50051 grpc/grpc-server
    
  2. In another shell, run client

    make container-run-client
    # or
    docker run -ti --rm --name client grpc/grpc-client
    

Kubernetes

Import container images
Minikube
  1. Enable Minikube internal container registry

    eval $(minikube docker-env)
    
  2. Build container images normally as it would be locally

KinD
  1. Build container images normally as it would be locally

  2. Import in KinD

    make load-container-kind
    # or
    kind load docker-image grpc/grpc-server
    kind load docker-image grpc/grpc-client
    
Deploy
  1. Start Kubernetes locally

    • Minikube

      make start-minikube
      # or
      minikube start --cpus 4 --memory 8192 --disk-size=10g
      
    • Kind

      make start-kind
      # or
      kind create cluster --wait=60s
      
  2. Deploy server

    make deploy-server
    # or
    kubectl apply -k kube/server
    
  3. Deploy client

    make deploy-client
    # or
    kubectl apply -k kube/client
    
  4. Take a look of logs

    • Server
      make server-logs
      # or
      kubectl logs -l app=grpc-server -f
      
    • (In another shell) Client
      make client-logs
      # or
      kubectl logs -l app=grpc-client -f
      
Cleanup
Minikube
make stop-minikube
# or
minikube stop
minikube delete
KinD
make stop-kind
# or
kind delete cluster

Example

  1. Run server

    go run example/server/main.go
    
  2. In another shell, run client

    go run example/client/main.go
    

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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