我正在使用节点js尝试在kubernetes集群环境中运行grpc。没有kubernetes的localy可以正常工作。服务器端正在监听'0.0.0.0:80'
,客户端尝试通过http://recommended-upgrades-qa-int连接。在kuberenets中,我得到以下错误:
ERROR failed to get via grpc the getRecommended Error: 14 UNAVAILABLE: Connect Failed endpoint:http://<K8S_SERVICE_NAME>
ERROR: Recommendations fetch error: Error: 14 UNAVAILABLE: Connect Failed severity=error, message=failed to get via grpc the getRecommended Error: 14 UNAVAILABLE: Connect Failed endpoint:http://<K8S_SERVICE_NAME>
服务器端:
const connectionHost = this.listenHost + ':' + this.listenPort;
server.bind(connectionHost, grpc.ServerCredentials.createInsecure());
logger.info(`Server running at ${connectionHost}`);
server.start();
客户端:
RecommendedService = grpc.load(__dirname + '/../../node_modules/@zerto/lib-service-clients/Output/sources/recommendedClient.proto').RecommendedService;
} catch (error){
console.log(error);
}
this.client = RecommendedService && new RecommendedService(grpcAddress, grpc.credentials.createInsecure());
制造者档案:
apiVersion: apps/v1
kind: Deployment
metadata:
name: server-side-deployment
namespace: default
spec:
selector:
matchLabels:
app: server-side-deployment
replicas: 1
template:
metadata:
labels:
app: server-side-deployment
spec:
containers:
- name: server-side-deployment
image: (DOCKER_IMAGE_PATH)
imagePullPolicy: Always
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: recommended-upgrades-qa-int
namespace: default
spec:
selector:
app: server-side-deployment
ports:
- protocol: TCP
port: 80
targetPort: 80
name: http
apiVersion: apps/v1
kind: Deployment
metadata:
name: client-side-deployment
namespace: default
spec:
selector:
matchLabels:
app: client-side-deployment
replicas: 1
template:
metadata:
labels:
app: client-side-deployment
spec:
containers:
- name: client-side-deployment
image: (DOCKER_IMAGE_PATH)
imagePullPolicy: Always
env:
- name: RECOMANDED_SERVICE
value: http://recommended-upgrades-qa-int
ports:
- containerPort: 80
答案 0 :(得分:1)
来自docs:
为“普通”(非无头)服务分配了DNS A记录,该记录的格式为my-svc.my-namespace.svc.cluster.local。这将解析为服务的群集IP。
您的问题可能是在服务位于另一个命名空间中时发出的<service name>
。尝试使用:
<service name>.<service namespace>.svc.cluster.local
答案 1 :(得分:1)
看来我们知道了。首先,URL必须包含端口80,而且服务器服务中存在内部未捕获的异常,这可能导致其无法正常工作。 谢谢大家