3

I want to deploy a gRPC service to Azure Kubernetes Service. I have already depoyed RESTful services using Helm charts but gRPC service is throwing "connection timed out" error.

I have already tried everything said in the NGINX and HELM documentation but nothing worked. The certificate is self signed. I have tried all permutation and combination of annotations :p

Service.yaml

apiVersion: v1
kind: Service
metadata:
  name: {{ template "fullname" . }}
  labels:
    app: {{ template "fullname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
spec:
  ports:
  - port: 50051
    protocol: TCP
    targetPort: 50051
    name: grpc
  selector:
    app: {{ template "fullname" . }}
  type: NodePort

ingress.yaml

{{ if .Values.ingress.enabled }}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ template "fullname" . }} 
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/grpc-backend: "true"
    nginx.org/grpc-services: {{ template "fullname" . }}
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  tls:
    secretName: aks-ingress-tls
  rules:
  - http:
      proto: h2
      paths:
      - backend:
          serviceName: {{ template "fullname" . }}
          servicePort: grpc
          proto: h2
        path: /{servicename}-grpc(/|$)(.*)
{{ end }}

Tried this also- still not working-

{{ if .Values.ingress.enabled }}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ template "fullname" . }} 
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/backend-protocol: "GRPC"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  tls:
  - secretName: aks-ingress-tls
  rules:
  - http:
      paths:
      - backend:
          serviceName: {{ template "fullname" . }}
          servicePort: 50051
        path: /servicename-grpc(/|$)(.*)
{{ end }}

1 Answers1

1

It looks like you are missing an annotation on your ingress.

ingress.yaml - snippet

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    # This annotation matters!
    nginx.ingress.kubernetes.io/backend-protocol: "GRPC"

According to this snippet from the official Kubernetes nginx ingress documentation:

Backend Protocol

Using backend-protocol annotations is possible to indicate how NGINX should communicate with the backend service. (Replaces secure-backends in older versions) Valid Values: HTTP, HTTPS, GRPC, GRPCS and AJP

By default NGINX uses HTTP.

Example:

nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"

As an aside, there's a chance you might need to specify GRPCS instead of GRPC since it appears you are using SSL.

Another thing to call out is that the docs mention that this annotation replaces 'secure-backends' in older versions, which could be where you found the grpc-backend annotation you are currently using.

Bwvolleyball
  • 2,593
  • 2
  • 19
  • 31
  • I tried with backend-protocol also. Even that was not working. Previously, I was not using any SSL certificate so I had put GRPC only. I will try with GRPCS now. – Aniket Prashar Aug 16 '19 at 05:07
  • Are other annotations fine? Can u please suggest a sample ingress file. I have tried everything that is there on the net. Nothing is working. – Aniket Prashar Aug 16 '19 at 05:09
  • This looks like an example from the kubernetes project for grpc: https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/grpc – Bwvolleyball Aug 16 '19 at 05:28
  • I tried with GRPCS now, It says the site can't be reached. – Aniket Prashar Aug 16 '19 at 05:39
  • The github link u shared is also not working. I have added the modified ingress in the question section. – Aniket Prashar Aug 16 '19 at 05:49
  • What version is your nginx ingress? According to the github repo: must be at least quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.13.0 for grpc support. – Bwvolleyball Aug 16 '19 at 13:36
  • Ho to find ingress version? – Aniket Prashar Aug 20 '19 at 13:59
  • You'll need to describe the deployment that is your nginx ingress - essentially, if you can see the kubernetes yaml that described it's creation, you can see what version of the ngnix image was used. Another option is to exec into the pod / container running nginx and run `nginx -v` as described by this post: https://stackoverflow.com/questions/34187178/find-nginx-version – Bwvolleyball Aug 20 '19 at 14:25
  • Thanks a lot! nginx version is 1.15.8.1 – Aniket Prashar Aug 21 '19 at 05:42
  • I'd assume the other thing you'll want to figure out is what version of this project you're using: https://github.com/kubernetes/ingress-nginx Because I'm assuming the gap we're missing is that this project handles mapping annotations down to nginx configuration, so I'd assume if you can version up your kubernetes nginx ingress to the latest my answer would work for you. – Bwvolleyball Aug 21 '19 at 17:53