To deploy go gRPC services, I’m using Kubernetes managed by google alias GKE, but I will write in a few weeks an article for AW EKS and Azure AKS.

This is very easy to deploy gRPC services with GKE. But there are some limitations due to the youth of HTTP2 protocol support. For example, Nginx does not yet support gRPC proxying (WIP planned for April 2018).

For now, there are different ways to deploy gRPC services on GKE :

With a TCP LoadBalancer

With ingress controller(for example traefik, nginx soon)

Soon With a layer 7 LoadBalancer (Alpha state)

On Google Cloud Platform, you can also expose gRPC services with Cloud Endpoints, if you don’t know Cloud Endpoints, you can check the article below.

Step 1: build a docker image

First, we need something to deploy! gRPC go providers some examples, let’s use helloworld example

We are going to deploy the greeter_server who listen on port 50051. In this example, the server do not use TLS encryption, this is an insecure version just for testing purpose. I will propose later an article with TLS config and let’s encrypt certificates.

I’m using a docker image based on scratch for my golang gRPC service.

I wrote few weeks ago, a great article how to create a secured golang docker image.

You have to adapt the dockerfile for your usage

$ docker build -f Dockerfile -t gcr.io/chemidy-cloud/k8s/backend-grpc-greeter .

You can now push image to Container Registry a private docker registry.

$ gcloud docker — push gcr.io/chemidy-cloud/k8s/backend-grpc-greeter

Step 2: Deploy the gRPC service to be exposed

$ kubectl create -f grpc-greeter-deployment.yaml

You can now check the deployment is created :

$ kubectl get deploy

NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE grpc-greeter-deployment 2 2 2 2 2s

You can check on Google Cloud Platform console

Step 3: Creating the external LoadBalancer

Kubernetes provides service of kind LoadBalancer, this is an external TCP LoadBalancer .

With google cloud platform, you can setup an external static IP address for your LoadBalancer (this IP needs to be Regional). You can do that from the console.

Note : Static IP addresses not attached to a load balancer are billed.

$ kubectl create -f loadbalancer-grpc-greeter.yaml

You can now check the service is created :

$ kubectl get svc

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

greeter LoadBalancer 10.118.218.0 35.118.218.0 80:30277/TCP 2s

You can check on Google Cloud Platform console

Now you can test your gRPC service 😐

If you want to access to your service with a DNS, you have to register this IP address in your favorite registar console / tool.

Step 4: More info about Cloud Endpoints

Cloud Endpoints is very useful because you can add somes features easily :

monitoring

authentication

tracing

translating RESTful JSON over HTTP into gRPC

…

If you are interested in deploying endpoints you can check the doc

That’s it, you have now a gRPC service deployed with GKE 🙏