dsgwdigu84950 2019-04-10 12:20
浏览 921

部署Rest + gRPC服务器通过入口部署到k8s

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.

  • 写回答

1条回答

  • dsy6639 2019-05-13 12:32
    关注

    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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题