ElasticClient unable to connect to Elasticsearch server running on k8s

Hi
I have deployed Elasticsearch locally to Docker Desktop Kubernetes as following:
install operator:
kubectl create -f {linktoEck}/eck/2.11.1/crds.yaml
kubectl apply -f {linktoEck}/eck/2.11.1/operator.yaml

then I deployed my .Net service which have a connection line to ElasticClient in Program.cs:

var connSettings = new ConnectionSettings(new Uri("https://elasticlocal.com/"))
    .BasicAuthentication("elastic", "testPassword")
    .ThrowExceptions()
    .EnableApiVersioningHeader();

builder.Services.AddSingleton<IElasticClient>(new ElasticClient(connSettings));

but when running this code with ExceptionDispatchInfo:

 var bulkAllObservable = _elasticClient.BulkAll(personIndexes, b => b
 .Index("persons"));

I get an exception telling this:

Unsuccessful () low level call on GET: /
# Audit trail of this API call:
# OriginalException: System.Net.Http.HttpRequestException: Connection refused (elasticlocal.com:443)
 ---> System.Net.Sockets.SocketException (111): Connection refused
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|285_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem)
   at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Elasticsearch.Net.HttpConnection.RequestAsync[TResponse](RequestData requestData, CancellationToken cancellationToken)

Elasticsearch file:

apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: elastic-cluster
spec:
  version: 8.12.2
  nodeSets:
  - name: default
    count: 1
    config:
      node.store.allow_mmap: false
  http:
    tls:
      selfSignedCertificate:
        subjectAltNames:
        - ip: 0.0.0.0
        - dns: elasticlocal.com

elasticlocal.com is handled by Ingress and is working fine (I am able to connect via Postman - elasticlocal.com:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: elastic-cluster
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/backend-protocol: HTTPS
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - elasticlocal.com
    secretName: my-new-tls-secret
  rules:
  - host: elasticlocal.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: elastic-cluster-es-http
            port:
              number: 9200

I have tried disabling certificates and it worked fine via Postman requests and via curl
but from .Net service it still give the same error

Actually now I am able to connect with using this configuration in code

var connSettings = new ConnectionSettings(new Uri("https://elastic-cluster-es-http.default.svc.cluster.local:9200"))
    .BasicAuthentication("elastic", "testPassword")
    .ThrowExceptions()
    .EnableApiVersioningHeader()
    .ServerCertificateValidationCallback((o, certificate, chain, errors) => true)
    .ServerCertificateValidationCallback(CertificateValidations.AllowAll);

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.