2 回答

TA贡献1802条经验 获得超10个赞
执行此操作的一种方法是使用 ,这样您就不必向服务添加证书,因为 Pod 中的容器将 TLS 终止任何传入连接。grpc.WithInsecure()istio-proxy
客户端:
conn, _ := grpc.Dial("localhost:50051", grpc.WithInsecure())
服务器端:
s := grpc.NewServer()
lis, _ := net.Listen("tcp", "localhost:50051")
// error handling omitted
s.Serve(lis)
如果仍需要将 TLS 用于本地部署等,则只需使用配置选项即可指定此内容,例如:
var conn *grpc.ClientConn
var err error
// error handling omitted do not copy paste
if ( config.IstioEnabled ) {
conn, err = grpc.Dial("localhost:50051", grpc.WithInsecure())
} else {
creds, _ := credentials.NewClientTLSFromFile(certFile, "")
conn, err = grpc.Dial("localhost:50051", grpc.WithTransportCredentials(creds))
}
- 2 回答
- 0 关注
- 159 浏览
添加回答
举报