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

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

我想使用Ingress将其部署到kubernetes。 </ p>

下面是我的配置文件。</ p>

service.yaml </ strong>-作为NodePort </ p>

< pre> apiVersion:v1
kind:Service
metadata:
名称:grpc-scratch
标签:
运行:grpc-scratch
注释:
service.alpha.kubernetes.io/app-protocols :'{“ grpc”:“ HTTP2”}'
spec:
类型:NodePort
端口:
-名称:grpc
端口:50051
协议:TCP
targetPort:50051
选择器:\ n运行:example-grpc
</ code> </ pre>

ingress.yaml </ strong> </ p>

  apiVersion:扩展 / v1beta1 
kind:Ingress
metadata:
名称:grpc-ingress
注释:
nginx.org/grpc-services:“grpc”
kubernetes.io/ingress.class:“nginx”
kubernetes。 io / tls-acme:true
spec:
tls:
-主机:
-xyz.com
secretName:grpc-secret
规则:
-主机:xyz.com
http:
路径:
-路径:/ grpc
后端:
serviceName:grpc
servicePort:50051
</ code> </ pre>

我无法 o使用URL xyz.com/grpc </ code>向服务器发出gRPC请求。 收到错误</ p>

  {
“错误”:“ 14无法使用:名称解析失败”
}
</ code> </ pre>

< p>如果我向 xyz.com </ code>发出请求,则错误为</ p>

  {
“错误”:“ 14无法使用:尝试连接http1 .x服务器“
}
</ code> </ pre>

任何帮助将不胜感激。</ p>
</ div>

展开原文

原文

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.

doubiaokai4998
doubiaokai4998 那么为什么要使用kubernetes.io/ingress.class:“nginx”注释?
一年多之前 回复
douhuigang9550
douhuigang9550 我正在用它做gke。
一年多之前 回复
donglian8407
donglian8407 您正在使用什么作为入口控制器?GKE?nginx的?至少有什么?
一年多之前 回复
dongxing8766
dongxing8766 github.com/kubernetes/ingress-nginx/issues/2497
一年多之前 回复
dsimib1625
dsimib1625 您还可以共享您的部署清单吗?
一年多之前 回复
douzhi9939
douzhi9939 更新服务。这是指向不同端口的不同服务。
一年多之前 回复
donglu1913
donglu1913 您的服务定义了端口8081,但是您的入口要使用端口50051。为什么?
一年多之前 回复

1个回答



入口对象的后端是服务名和端口名的组合</ p>

您将 serviceName:grpc </ code>作为后端,而服务的实际名称是 name:grpc-scratch </ code> </ p>

  apiVersion:扩展 / v1beta1 
kind:Ingress
metadata:
名称:grpc-ingress
注释:
nginx.org/grpc-services:“grpc”
kubernetes.io/ingress.class:“nginx”
kubernetes。 io / tls-acme:true
spec:
tls:
-主机:
-xyz.com
secretName:grpc-secret
规则:
-主机:xyz.com
http:
路径:
-路径:/ grpc
后端:
serviceName:grpc-scratch
servicePort:grpc
</ code> </ pre>
</ div>

展开原文

原文

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问