项目作者: takama

项目描述 :
gRPC client, service and CLI utility to provide/check load balancing and connection stability
高级语言: Go
项目地址: git://github.com/takama/grpc.git
创建时间: 2019-01-10T08:30:56Z
项目社区:https://github.com/takama/grpc

开源协议:MIT License

下载


gRPC Go client with advanced settings

gRPC client, service and CLI utility to provide/check load balancing and connection stability

Using gRPC Go client

  1. import "github.com/takama/grpc/client"
  2. ...
  3. c, err := client.New(cfg, log)
  4. if err != nil {
  5. log.Fatal(err)
  6. }
  7. ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
  8. defer cancel()
  9. e := echo.NewEchoClient(c.Connection())
  10. response, err := e.Ping(
  11. // This is important to pass trough c.Context(ctx)
  12. // when we use Envoy balancer for any retries
  13. c.Context(ctx),
  14. &echo.Request{
  15. Content: "Some content",
  16. },
  17. )
  18. if err != nil {
  19. log.Print(err)
  20. }
  21. fmt.Print("Response:", response.Content)

Prepare service environment and configuration

  • Create a new project and GKE cluster in Google Cloud
  • Setup Contour balancer according to example
  • Note somewhere the IP of Load balancer
  • Change default GKE values in Makefile on your own
  1. GKE_PROJECT_ID ?= your-project-id
  2. GKE_PROJECT_ZONE ?= europe-west1-b
  3. GKE_CLUSTER_NAME ?= your-cluster-name
  • Choose domain host name for the service and point your DNS record on GKE Contour balancer using IP above
  • Make the certificates for the domain name (Let’s encrypt as option)
  • Test to create in dry run grpc-service-tls in corresponded Kubernetes environment (ex: test)
  1. kubectl create secret tls grpc-service-tls --key key.pem --cert cert.pem --dry-run -o yaml
  • Create grpc-service-tls in corresponded Kubernetes environment (ex: test)
  1. kubectl create secret tls grpc-service-tls --key key.pem --cert cert.pem
  • Change domain name in .helm/values-test.yaml or any other values-name.yaml to your own
  1. ## Ingress route hosts
  2. ##
  3. hosts:
  4. ## gRPC service host
  5. - name: grpc
  6. host: grpc.your-test-domain.net
  7. ...
  8. ## Client connection to the service
  9. ##
  10. client:
  11. host: grpc.your-test-domain.net
  • Change default namespace in Makefile
  1. # Namespace: dev, prod, username ...
  2. NAMESPACE ?= test

Build the service

  1. make build

Deploy the service

  1. make deploy

Build CLI utility on Linux

  1. make compile

Build CLI utility on Mac OS

  1. GOOS=darwin make compile

Run the utility with simple ping

  1. ./bin/darwin-amd64/grpc client ping --count 600 --config config/test.conf

Run the utility with reverse ping

  1. ./bin/darwin-amd64/grpc client reverse --count 600 --config config/test.conf

Scale services

During the ping process scale services from 1 to N and see how it is going

  1. kubectl scale --replicas 3 -n test deploy/grpc
  2. kubectl scale --replicas 6 -n test deploy/grpc
  3. kubectl scale --replicas 1 -n test deploy/grpc
  4. ...

Other make commands

  • all - run default complete set of commands (build the service)
  • vendor - import all vendors (using dep)
  • compile - build the service binary
  • certs - download latests certs from an alpine image and prepare it for service container
  • build - build container image
  • push - push an image in docker registry
  • run - build and run the service
  • logs - show service logs from container
  • deploy - deployment of the service into Kubernetes environment
  • charts - validate helm templates (charts)
  • test - run unit tests
  • cover - show testing coverage for packages
  • fmt - format Go packages with go fmt
  • lint - use set of linters ( ~ 20) to check the service code
  • stop - stop running container
  • start - start existing container (if it was stopped before)
  • rm - remove stopped container
  • version - add next major/minor/patch version
  • clean - remove binary and running container
  • bootstrap - check and setup if something from utilities is not exist

Versioned changes

All changes in the project described in changelog

Generated using (Caldera boilerplate)