Expose GRPC server through Ingress on Google Cloud

Viewed 810

I'm trying to expose a GRPC Java service thought an Ingress to outside world from my GKE cluster.

The problem is that GKE's default implementation creates a health check that expect 200 response code on curling "/". It is expected and documented here.

Unfortunately this seems not to work with grpc-java implementation since it's not handling "/" GET requests.

GRPC itself defines a health checking protocol. But it's not supported either.

I wonder if there is a similar secret annotation like "kubernetes.io/ingress.global-static-ip-name" but for disabling health checks at least(ideally overriding them).

2 Answers

The health check can be changed by defining custom liveness/readiness probes. In this way, you can define custom endpoints to hit for the health check. Here's a sample from the documentation:

 livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
    httpHeaders:
    - name: X-Custom-Header
      value: Awesome
  initialDelaySeconds: 3
  periodSeconds: 3

If you need something more powerful than a simple HTTP check, you can construct a probe with 'exec' instead of 'httpGet'. With exec, you can use Linux commands or a custom CLI script in your container to query your API or otherwise verify the state of your system. If the command/script returns 0, the pod is seen as healthy. This sample will view the pod as alive if a file exists at /tmp/healthy:

livenessProbe:
  exec:
    command:
    - cat
    - /tmp/healthy
  initialDelaySeconds: 5
  periodSeconds: 5
Related