I have created .NET microservices pods in Kubernetes,and want to connect these pods to the external SQL database present on-premises. I have made all the possible changes to the connection string, added TrustServerCertficate=True
and Encrypt=False
, but still no luck.
I have added Hostalises, property in deployment file, with IP address and and the corresponding hostname.
Currently I am working on master-api pod,below the connection string details,
{
"ConnectionStrings": {
"con": "data source=DB_name; database=admin_table; user id=admin; pwd=admin; Pooling=true;Max Pool Size=500;timeout=40000; TrustServerCertificate=True; Encrypt=False"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Kubectl get svc
svc for this microservice is master-service
This is the deployment file with service
apiVersion: apps/v1
kind: Deployment
metadata:
name: master-api
labels:
app: master-api
type: back-end
spec:
template:
metadata:
name: master-api
labels:
app: master-api
type: back-end
spec:
containers:
- name: masterapi
image: repo/mpsaps-masters:v1.14
env:
- name: HTTP_PROXY
value: http://proxy-details
- name: HTTPS_PROXY
value: http://proxy-detail
hostAliases:
- ip: "hostip"
hostnames:
- "hostname"
replicas: 1
selector:
matchLabels:
type: back-end
---
apiVersion: v1
kind: Service
metadata:
name: master-service
spec:
selector:
app: master-api
type: NodePort
ports:
- protocol: TCP
targetPort: 80
port: 3040
nodePort: 31902
This is the docker-compose file which I am using.
version: '3.5'
services:
MasterApi:
image: repo/mpsaps-masters:v1.14
container_name: mpsaps-master
build:
context: .
dockerfile: Mpsaps.Masters/Dockerfile
environment:
- HTTP_PROXY=http://proxy
- HTTPS_PROXY=http://proxy
ports:
- "443:443"
- "1433:1433"
- "42016:80"
When I run the curl command to fetch the data from DB, the following error occurs all the time:
curl 'http://192.168.100.1:31902/PublicService/GetServiceByDepartment?Dep_Code=%2201%22'
{"response":{"response_code":"0","response_message":"A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)","result":null}}
Please any help regarding this issue would be appreciated.
2
Answers
these are the logs
fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HMUEBFQB5I9F", Request id "0HMUEBFQB5I9F:00000002": An unhandled exception was thrown by the application. System.NullReferenceException: Object reference not set to an instance of an object. at Mpsaps.Masters.Controllers.PublicServiceController.GetkuberTest() in /src/Mpsaps.Masters/Controllers/PublicServiceController.cs:line 63 at lambda_method2(Closure , Object , Object[] ) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
Ok, so i have got the issue resolved, it was happening because the sql server version on which i am creating connection is not supported by kubernetes, so i have updated the version and now its works.
Thanks