简体   繁体   English

部署 Rest + gRPC server 部署到 k8s with ingress

[英]Deploy Rest + gRPC server deploy to k8s with ingress

I have used a sample gRPC HelloWorld applicationhttps://github.com/grpc/grpc-go/tree/master/examples/helloworld .我使用了一个示例 gRPC HelloWorld 应用程序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.我想使用 Ingress 将它部署到 kubernetes。

Below are my config files.下面是我的配置文件。

service.yaml - as NodePort 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

ingress.yaml入口.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 .我无法使用 url xyz.com/grpc向服务器发出 gRPC 请求。 Getting the error得到错误

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

If I make request to xyz.com the error is如果我向xyz.com提出请求,则错误是

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

Any help would be appreciated.任何帮助,将不胜感激。

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在您的情况下,您将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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM