Connect to gRPC service from k8s

125 Views Asked by At

I have a grpc service written in java deployed on kubernetes.

> kubectl get svc -n data                                         
NAME                      TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)             AGE
rds-grpc     ClusterIP   10.90.8.137    <none>        8088/TCP,6543/TCP   285d

I have port forwarded to this service to access it locally

> kubectl port-forward svc/rds-grpc -n data 6543:6543             
Forwarding from 127.0.0.1:6543 -> 6543
Forwarding from [::1]:6543 -> 6543

However when I try to call these gRPC APIs from Postman. It gives me back this error

Status code: 1 CANCELLED

If I try bloomRPC then it gives me back

{
  "error": "2 UNKNOWN: Stream removed"
}

How can I correctly port forward and call the gRPC Api ?

1

There are 1 best solutions below

0
Ron Etch On

You may want to check the correct port exposed from the docker image you created, as well as if it requires any sort of authentication.

You can check this following example from ingress-nginx on how to expose gRPC app on the ingress so you may not need to port-forward it locally

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/backend-protocol: "GRPC"
  name: fortune-ingress
  namespace: default
spec:
  ingressClassName: nginx
  rules:
  - host: grpctest.dev.mydomain.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: go-grpc-greeter-server
            port:
              number: 80
  tls:
  # This secret must exist beforehand
  # The cert must also contain the subj-name grpctest.dev.mydomain.com
  # https://github.com/kubernetes/ingress-nginx/blob/master/docs/examples/PREREQUISITES.md#tls-certificates
  - secretName: wildcard.dev.mydomain.com
    hosts:
      - grpctest.dev.mydomain.com