Azure / Bridge-To-Kubernetes

Bridge To Kubernetes (B2K) is development tool to debug microservices, pods which redirects traffic to your local development machine and vice versa.
https://learn.microsoft.com/en-us/visualstudio/bridge/overview-bridge-to-kubernetes
Other
204 stars 57 forks source link

Cannot access redis in cluster from visual studio #488

Open step42 opened 7 months ago

step42 commented 7 months ago

My services has a redis connection string configured like redis-headless.infra.svc.cluster.local:6379,password=xyz. I added

The code throws socket exceptions Exception thrown: 'System.Net.Sockets.SocketException' in Pipelines.Sockets.Unofficial.dll Exception thrown: 'StackExchange.Redis.RedisConnectionException' in StackExchange.Redis.dll Exception thrown: 'System.Net.Sockets.SocketException' in System.Net.Sockets.dll Exception thrown: 'StackExchange.Redis.RedisConnectionException' in System.Private.CoreLib.dll

kubectl get services -n infra NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ... redis-headless ClusterIP None 6379/TCP 5d1h redis-master ClusterIP 10.43.186.44 6379/TCP 5d1h redis-metrics ClusterIP 10.43.118.255 9121/TCP 5d1h

settings_passed failed_to_connect_ex

I am using Visual Studio 2022

hsubramanianaks commented 7 months ago

@step42 Can you share the logs from the following location please ? C:\Users\youruserid\AppData\Local\Temp\Bridge To Kubernetes, please send all the logs from this location after getting this error. ex: bridge-*.txt files. Thank you.

step42 commented 4 months ago

bridge-logs.zip Sorry for the late respone. Attached the logs. Please let me know if you need anything else

I can connect to redis if I change the connection string from redis-headless.infra:6379 to redis-master.infra:6379

step42 commented 4 months ago

@hsubramanianaks can you please update the state. I provided my response and would like to know how to proceed. Thanks

hsubramanianaks commented 3 months ago

@step42 can you check your k8s cluster for pod you are deubgging , it would be running image lpkremoteagent-* and see if you grab the logs for it? I feel the remote agent pod running in your k8s cluster which communicates k8s cluster --> local ane vice versa is not coming up. I can see error in the logs

024-05-09T20:51:05.9930533Z | Library | ERROR | Logging handled exception: System.Net.Http.HttpRequestException: {"StatusCode":null,"Message":"An error occurred while sending the request.","Data":{},"InnerException":{"Message":"The response ended prematurely.","Data":{},"InnerException":null,"HelpLink":null,"Source":"System.Net.Http","HResult":-2146232800,"StackTrace":"   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)"},"HelpLink":null,"Source":"System.Net.Http","HResult":-2146232800,"StackTrace":"   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)\r\n   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)\r\n   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Http.Connections.Client.Internal.AccessTokenHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Http.Connections.Client.Internal.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at System.Net.Http.HttpClient.\u003CSendAsync\u003Eg__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)\r\n   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.NegotiateAsync(Uri url, HttpClient httpClient, ILogger logger, CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.GetNegotiationResponseAsync(Uri uri, CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.SelectAndStartTransport(TransferFormat transferFormat, CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.StartAsyncCore(TransferFormat transferFormat, CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.StartAsync(TransferFormat transferFormat, CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionFactory.ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionFactory.ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsyncCore(CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsyncInner(CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsync(CancellationToken cancellationToken)\r\n   at Microsoft.BridgeToKubernetes.Common.DevHostAgent.DevHostAgentExecutorClient._ConnectAsync(CancellationToken cancellationToken)\r\n   at Microsoft.BridgeToKubernetes.Common.DevHostAgent.DevHostAgentExecutorClient._GetConnectionAsync(CancellationToken cancellationToken)\r\n   at Microsoft.BridgeToKubernetes.Common.DevHostAgent.DevHostAgentExecutorClient.PingAsync(Int32 timeoutMs, Int32 retry, CancellationToken cancellationToken)"}
step42 commented 3 months ago

I can see that the pod I am debugging got replaced with bridgetokubernetes.azurecr.io/lpkremoteagent:1.3.4 Here are the logs of the pod sysconfig.log I also attached the bridge logs files again from the same session

Bridge To Kubernetes.zip

hsubramanianaks commented 3 months ago

@step42 seems like connection between your local machine and k8s cluster is not happening, port forwarding is failing due to network issues. do you have any VPN/firewall that is blocking connections or is this some kind of private cluster only people with right access can port forward?

2024-06-04T22:46:03.9423360Z | Library | ERROR | Logging handled exception: System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: {"Message":"No connection could be made because the target machine actively refused it. [::ffff:127.0.0.1]:5000","SocketErrorCode":10061,"ErrorCode":10061,"NativeErrorCode":10061,"Data":{},"InnerException":null,"HelpLink":null,"Source":"System.Net.Sockets","HResult":-2147467259,"StackTrace":"   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)\r\n   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)\r\n   at System.Net.Sockets.TcpClient.Connect(IPEndPoint remoteEP)\r\n   at Microsoft.BridgeToKubernetes.Common.PortForward.ReversePortForwardManager.ReversePortForwardInstance.\u003C\u003Ec__DisplayClass9_0.\u003COnDataReceived\u003Eb__0(Int32 _)\r\n   at System.Collections.Concurrent.ConcurrentDictionary\u00602.GetOrAdd(TKey key, Func\u00602 valueFactory)\r\n   at Microsoft.BridgeToKubernetes.Common.PortForward.ReversePortForwardManager.ReversePortForwardInstance.OnDataReceived(Int32 streamId, Byte[] data)\r\n   at Microsoft.BridgeToKubernetes.Common.DevHostAgent.DevHostAgentExecutorClient.ReversePortForwardStartAsync(PortForwardStartInfo port, Func\u00603 dataHandler, Action\u00601 closedHandler, CancellationToken cancellationToken)"}

can you try normal port forward without bridge from your local machine to see if it works please ?

step42 commented 3 months ago

Port Forwarding works. It also works if I connect to redis-master instead of redis-headless service through the bridge. The only difference I can see there is that redis-master has an IP and redis-headless has no IP

redis-headless                            ClusterIP      None            <none>           6379/TCP                     6d22h
redis-master                              ClusterIP      10.43.60.181    <none>           6379/TCP                     6d22h

Do you want any log files when connecting to redis-master through b2k?