Loadbalancing the fleet server

Hi everyone,

I have Elastic ECE up and running successfully. However, due to network restrictions, my Elastic Agents cannot communicate directly with Fleet Server. To address this, I have deployed a separate VM and configured HAProxy as an application load balancer/proxy in front of Fleet Server.

The HAProxy configuration appears to work correctly when tested manually using curl through the load balancer. However, Elastic Agents are experiencing intermittent Fleet check-in issues. Policies are eventually pushed, but sometimes with delays, and agents temporarily appear offline in Fleet.

Below is my current HAProxy configuration:

global
    log /dev/log local0
    log /dev/log local1 notice
    maxconn 2000
    daemon

defaults
    log global
    mode http
    option httplog
    option dontlognull

    # Connection and long-polling timeouts
    timeout connect 15s
    timeout client 10m
    timeout server 10m
    timeout http-request 30s
    timeout http-keep-alive 2m
    timeout tunnel 1h

frontend fleet_test_frontend
    bind *:<LISTENER_PORT> ssl crt /etc/haproxy/certs/fleet.pem
    mode http

    # Forward client information
    option forwardfor
    http-request set-header X-Forwarded-Proto https

    default_backend fleet_cloud_backend

backend fleet_cloud_backend
    mode http

    # Diagnostic: disable backend connection reuse
    option http-server-close

    # Preserve Elastic Cloud Fleet hostname
    http-request set-header Host <FLEET_SERVER_HOSTNAME>

    # Backend HTTPS connection with SNI
    server fleet_cloud <FLEET_SERVER_HOSTNAME>:<FLEET_SERVER_PORT> ssl verify none sni str(<FLEET_SERVER_HOSTNAME>) check inter 5s fall 3 rise 2

Has anyone experienced similar issues when placing Fleet Server behind HAProxy, particularly with intermittent check-in failures despite successful manual connectivity tests?

I would appreciate any insights or recommendations on troubleshooting this further.

Thanks!

Did you check the agent logs? What do you have in the logs when you have a check-in fail?

What hosts are configured on the fleet side? You need to have the host of your proxy configured there as well and enroll the agents using that host.

I've had a similar scenario in the past with a self-hosted fleet where I had a public url and an internal one pointing to an haproxy, both URLs were configured in Fleet.

Agents that only could connect internally were enrolled using the internal URL, also, I didn't make any changes to the headers.

Hi Leandro,

The output configuration has been verified, and the agents are successfully sending data to Elasticsearch through the correct output.

The only issue is with Fleet check-ins, which are intermittently failing. The agent logs show the following error:

Failed to check in: 502 Bad Gateway

So, data ingestion is working as expected; the problem appears to be isolated to communication between Elastic Agent and Fleet Server.

Dear Norris,

It's not just HAProxy; I've also tried NGINX and Apache, but all three exhibit similar issues.

The only reliable approach I've found so far is to use a network-level load balancer, which is not the solution I was initially looking for.

I encountered a similar situation around two years ago and contacted Elastic Support. At that time, I was informed that application-level load balancing for Fleet Server was not supported, and they recommended deploying a dedicated Fleet Server for each zone, particularly because connectivity between the different zones was restricted.

I'm curious about the official documentation, which suggests increasing the proxy timeout values to resolve these issues. However, despite following that recommendation and testing multiple reverse proxies (HAProxy, NGINX, and Apache), I'm still experiencing the same problem.

Could you clarify whether application-level load balancing or reverse proxying for Fleet Server is officially supported? Also, is there any specific configuration or recommended approach that could address these issues?

Best regards,

Please share the full error logs you have as they provide more information.

I'd suggest that you restart an agent and get the logs it generates when communicating with the fleet server.

Yeah, but the output of data does not seem to be your issue here, the fleet checkin and the output of data are independent from each other.

What I asked was about the hosts for the Fleet Server.

When you go in the Fleet Server UI > Settings, there is the Fleet Server Hosts configuration.

How many hosts you have there? Can you share a screenshot redacting sensitive information?

I would also increase this timeout connect 15s and remove any changes you are doing on the headers, I don't think this is needed or if this can impact.

Some things to compare against your HAProxy config, in addition to the earlier suggestion to check the agent logs and to make sure the proxy host is configured in Fleet and used at enrollment:

  1. Agents long-poll Fleet Server on check-in, so the connection is idle for a long time by design. Your timeouts (10m client/server) are generous, but any other device between the agents and HAProxy (firewall, NAT, a second proxy) that drops idle connections sooner will show up as intermittent check-in failures and agents flipping to offline. Check that nothing else in the path has a shorter idle timeout, and consider TCP keepalives on the HAProxy frontend and backend (option clitcpka / srvtcpka).
  2. You are terminating TLS on HAProxy and re-encrypting to Fleet Server with verify none. If the agents enrolled against the Fleet Server URL, they may be verifying a certificate or CA that does not match what HAProxy presents. Compare the CA and fingerprint the agents were enrolled with against the certificate in /etc/haproxy/certs/fleet.pem. The agent log will say if it is a TLS error.
  3. option http-server-close forces a new backend connection for every request. That works for testing, but it adds TLS handshakes to the backend for every check-in. If you only need the proxy to forward traffic, mode tcp (TLS passthrough) is simpler and avoids rewriting headers.
  4. When it fails, compare the timestamps in HAProxy's log (termination flags such as sD, cD or sH) with the agent's "checkin failed" lines. The termination flags tell you whether the client, the server or a timeout ended the connection.

Posting the agent log lines around one failed check-in and the HAProxy log lines for the same second would let people narrow it down quickly.

Hi leandro and cinn Thank you both for your suggestions.

I've applied the recommended changes to my HAProxy configuration:

  • Increased timeout connect from 1s to 15s.

  • Removed option http-server-close to avoid unnecessary backend connection closures.

  • Enabled option clitcpka and option srvtcpka for TCP keepalives.

  • Kept the existing HTTP-mode architecture and long client/server timeouts.

I'm monitoring the behavior after these changes.

However, I'm still observing intermittent 502 errors during Fleet check-ins. Below is a sanitized HAProxy log from one of the failures:

Dec 03 12:37:23 [PROXY_HOST] haproxy[PID]:
[CLIENT_IP]:[CLIENT_PORT] [03/Dec/2026:12:36:32.929]
fleet_test_frontend~ fleet_cloud_backend/[BACKEND_SERVER]
0/0/46/-1/50299 502 209 - - SH--
6/6/2/2/0 0/0
"POST /api/fleet/agents/[AGENT_ID]/checkin? HTTP/1.1"

The corresponding Elastic Agent error is:

Could not decode the response, raw response:

<html>
<body>
<h1>502 Bad Gateway</h1>
The server returned an invalid or incomplete response.
</body>
</html>

The agents are still able to send data to Elasticsearch, but Fleet check-ins intermittently fail, causing agents to temporarily appear offline. Policies are eventually received, sometimes with delays.

Could you help interpret the SH-- termination flags and the timing values in this HAProxy log? In particular, I'd like to understand whether the backend Fleet Server is closing the connection unexpectedly or whether HAProxy is encountering an issue while processing the response.

I would appreciate any further recommendations on troubleshooting this behavior.

Thanks!