Code Monkey home page Code Monkey logo

grpc-gke-nlb-tutorial's Introduction

Using Envoy to load-balance gRPC services on GKE

This repository contains the code used in the tutorial Using Envoy Proxy to load-balance gRPC services on GKE.

The tutorial demonstrates how to expose multiple gRPC services deployed on Google Kubernetes Engine (GKE) via a single external IP address using External TCP/UDP Network Load Balancing and Envoy Proxy. The tutorial uses Envoy Proxy to highlight some of the advanced features it provides for gRPC.

Quick start

  1. Create a self-signed TLS certificate and private key:

    openssl req -x509 -newkey rsa:4096 -nodes -sha256 -days 365 \
        -keyout privkey.pem -out cert.pem -extensions san \
        -config \
        <(echo "[req]";
          echo distinguished_name=req;
          echo "[san]";
          echo subjectAltName=DNS:grpc.example.com
         ) \
        -subj '/CN=grpc.example.com'
  2. Create a Kubernetes Secret called envoy-certs that contains the self-signed TLS certificate and private key:

    kubectl create secret tls envoy-certs --key=privkey.pem --cert=cert.pem \
        --dry-run=client --output=yaml | kubectl apply --filename -
  3. Build the container images for the sample apps echo-grpc and reverse-grpc, push them to a registry, and deploy them to a Kubernetes cluster, using Skaffold:

    skaffold run \
        --default-repo=gcr.io/$(gcloud config get-value core/project) \
        --module=echo-grpc,reverse-grpc \
        --skip-tests
  4. Deploy Envoy to the Kubernetes cluster:

    skaffold run \
        --digest-source=none \
        --module=envoy \
        --skip-tests

Test the solution

  1. Install grpcurl:

    go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest

    If you don't have the Go distribution installed, you can instead download a binary release.

  2. Get the external IP address of the envoy Kubernetes Service and store it in an environment variable:

    EXTERNAL_IP=$(kubectl get service envoy \
        --output=jsonpath='{.status.loadBalancer.ingress[0].ip}')
  3. Send a request to the echo-grpc sample app:

    grpcurl -d '{"content": "echo"}' -proto echo-grpc/api/echo.proto \
        -authority grpc.example.com -cacert cert.pem -v \
        $EXTERNAL_IP:443 api.Echo/Echo
  4. Send a request to the reverse-grpc sample app:

    grpcurl -d '{"content": "reverse"}' -proto reverse-grpc/api/reverse.proto \
        -authority grpc.example.com -cacert cert.pem -v \
        $EXTERNAL_IP:443 api.Reverse/Reverse

Cleaning up

  1. Delete the Kubernetes resources:

    skaffold delete
    
    kubectl delete secret tls envoy-certs
  2. Delete the container images from Container Registry:

    gcloud container images list-tags gcr.io/$(gcloud config get-value core/project)/echo-grpc \
        --format 'value(digest)' | xargs -I {} gcloud container images delete \
        --force-delete-tags --quiet gcr.io/$(gcloud config get-value core/project)/echo-grpc@sha256:{}
    
    gcloud container images list-tags gcr.io/$(gcloud config get-value core/project)/reverse-grpc \
        --format 'value(digest)' | xargs -I {} gcloud container images delete \
        --force-delete-tags --quiet gcr.io/$(gcloud config get-value core/project)/reverse-grpc@sha256:{}

Disclaimer

This is not an officially supported Google product.

grpc-gke-nlb-tutorial's People

Contributors

b-yng avatar dependabot[bot] avatar halvards avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grpc-gke-nlb-tutorial's Issues

skaffold command fails to deploy envoy

When following the tutorial and running the following command on a mac

skaffold run \
    --digest-source=none \
    --module=envoy \
    --skip-tests

getting the below error

running [kubectl kustomize /Users/nikhilkishore/Projects/cloud/envoyTutorial/grpc-gke-nlb-tutorial/envoy/k8s]
 - stdout: ""
 - stderr: "Error: json: unknown field \"metadata\"\n"
 - cause: exit status 1

Dockerfiles have go build error

# github.com/GoogleCloudPlatform/grpc-gke-nlb-tutorial/echo-grpc/api
api/echo.pb.go:240:11: undefined: grpc.SupportPackageIsVersion6
api/echo.pb.go:250:5: undefined: grpc.ClientConnInterface
The command '/bin/sh -c apk add --no-cache git protobuf &&     go get github.com/golang/protobuf/protoc-gen-go &&     protoc --proto_path=api --go_out=plugins=grpc:api api/*.proto &&     GOPATH="/go" GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install -installsuffix "static" &&     echo 'nobody:x:65534:' > /src/group.nobody &&     echo 'nobody:x:65534:65534::/:' > /src/passwd.nobody &&     GRPC_HEALTH_PROBE_VERSION=v0.2.2 &&     wget -q -O /bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 &&     chmod +x /bin/grpc_health_probe' returned a non-zero code: 2

all SubConns are in TransientFailure

grpcurl -d '{"content": "frank"}' -proto echo-grpc/api/echo.proto -insecure -v 35.204.67.35:443 api.Echo/Echo

Work

package main

import (
	"golang.org/x/net/context"
	"google.golang.org/grpc"
	"google.golang.org/grpc/keepalive"
	"log"
	"test_grpc_connect/api"
	"time"
)

func main() {


	var conn *grpc.ClientConn
	conn, err := grpc.Dial("35.204.67.35:443", grpc.WithInsecure(),
		grpc.WithKeepaliveParams(keepalive.ClientParameters{
			Time:                30 * time.Second,
			Timeout:             20 * time.Second,
			PermitWithoutStream: true,
		}))
	if err != nil {
		log.Fatalf("did not connect: %s", err)
	}

	defer conn.Close()

	c := api.NewEchoClient(conn)

	ctx, cancel := context.WithTimeout(context.Background(), time.Duration(5*time.Second))
	defer cancel()
	r, err := c.Echo(ctx, &api.EchoRequest{Content:"Frank"})
	if err != nil {
		log.Fatalf("could not echo: %v", err)
	}
	log.Printf("Echo: %s", r.Content)
}

Doesn't work.

I try a lot.

I could not find the right solution yet. Maybe you are faster.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.