我使用了示例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
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
我无法使用URL xyz.com/grpc
向服务器发出gRPC请求。得到错误
{
"error": "14 UNAVAILABLE: Name resolution failure"
}
如果我向xyz.com
发出请求,则错误为
{
"error": "14 UNAVAILABLE: Trying to connect an http1.x server"
}
任何帮助将不胜感激。
答案 0 :(得分:0)
入口对象的后端是服务和端口名称的组合
在您的情况下,您将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