Grpc连接到服务器

时间:2020-04-01 11:22:12

标签: python grpc microk8s

我正在使用microk8s将客户端连接到服务器,它在microk8s之外运行代码。但是在microk8s中,我遇到了以下错误:

grpc._channel._MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
    status = StatusCode.UNAVAILABLE
    details = "DNS resolution failed"
    debug_error_string = "{"created":"@1585739838.378038594","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3941,"referenced_errors":[{"created":"@1585739838.378032454","description":"Resolver transient failure","file":"src/core/ext/filters/client_channel/resolving_lb_policy.cc","file_line":262,"referenced_errors":[{"created":"@1585739838.378031228","description":"DNS resolution failed","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc","file_line":370,"grpc_status":14,"referenced_errors":[{"created":"@1585739838.377997913","description":"C-ares status is not ARES_SUCCESS: Domain name not found","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc","file_line":244,"referenced_errors":[{"created":"@1585739838.377829266","description":"C-ares status is not ARES_SUCCESS: Domain name not found","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc","file_line":244}]}]}]}]}"

客户代码:

while True:
        with grpc.insecure_channel('greeter_server:50051') as channel:
            stub = helloworld_pb2_grpc.GreeterStub(channel)
            total_length = 0
            for response in stub.SayHello(helloworld_pb2.HelloRequest(name='no')):
                total_length += len(response.message)

连接:

  greeter-server   ClusterIP   10.152.183.249   <none>        50051/TCP        37m

服务器中的代码段:

def serve():
        server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
        helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
        server.add_insecure_port('[::]:50051')
        server.start()
        server.wait_for_termination()

0 个答案:

没有答案