2 回答

TA貢獻1802條經(jīng)驗 獲得超10個贊
執(zhí)行此操作的一種方法是使用 ,這樣您就不必向服務添加證書,因為 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 用于本地部署等,則只需使用配置選項即可指定此內(nèi)容,例如:
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 關(guān)注
- 151 瀏覽
添加回答
舉報