Deploy Rest + gRPC server deploy to k8s with ingress

4/10/2019

I have used a sample gRPC HelloWorld application https://github.com/grpc/grpc-go/tree/master/examples/helloworld. This example is running smoothly in local system.

I want to deploy it to kubernetes with use of Ingress.

Below are my config files.

service.yaml - as NodePort

apiVersion: v1
kind: Service
metadata:
  name: grpc-scratch
  labels:
    run: grpc-scratch
  annotations:
    service.alpha.kubernetes.io/app-protocols: '{"grpc":"HTTP2"}'
spec:
  type: NodePort
  ports:
  - name: grpc
    port: 50051
    protocol: TCP
    targetPort: 50051
  selector:
    run: example-grpc

ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: grpc-ingress
  annotations:
    nginx.org/grpc-services: "grpc"
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: true
spec:
  tls:
    - hosts:
        - xyz.com
      secretName: grpc-secret
  rules:
    - host: xyz.com
      http:
        paths:
          - path: /grpc
            backend:
              serviceName: grpc
              servicePort: 50051

I am unable to make gRPC request to the server with url xyz.com/grpc. Getting the error

{
  "error": "14 UNAVAILABLE: Name resolution failure"
}

If I make request to xyz.com the error is

{
  "error": "14 UNAVAILABLE: Trying to connect an http1.x server"
}

Any help would be appreciated.

-- Tushar Sheth
go
grpc
grpc-go
http2
kubernetes-ingress

1 Answer

5/13/2019

A backend of the ingress object is a combination of service and port names

In your case you have serviceName: grpc as a backend while your service's actual name is name: grpc-scratch

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: grpc-ingress
  annotations:
    nginx.org/grpc-services: "grpc"
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: true
spec:
  tls:
    - hosts:
        - xyz.com
      secretName: grpc-secret
  rules:
    - host: xyz.com
      http:
        paths:
          - path: /grpc
            backend:
              serviceName: grpc-scratch
              servicePort: grpc
-- A_Suh
Source: StackOverflow