1

我使用了一个示例 gRPC HelloWorld 应用程序https://github.com/grpc/grpc-go/tree/master/examples/helloworld。这个例子在本地系统中运行顺利。

我想使用 Ingress 将其部署到 Kubernetes。

以下是我的配置文件。

service.yaml - 作为 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

入口.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

我无法使用 url 向服务器发出 gRPC 请求xyz.com/grpc。得到错误

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

xyz.com如果我对错误提出请求是

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

任何帮助,将不胜感激。

4

1 回答 1

1

入口对象的后端是服务和端口名称的组合

在您的情况下,您有serviceName: grpc一个后端,而您的服务的实际名称是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
于 2019-05-13T12:32:06.540 回答