TCP socket health check instead of HTTP health check on EC2 target group?

12/29/2021

I have a TCP service. I created a TCP readiness probe for my service which appears to be working just fine.

Unfortunately, my EC2 target group wants to perform an HTTP health check on my instance. My service doesn't respond to HTTP requests, so my target group is considering my instance unhealthy.

Is there a way to change my target group's health check from "does it return an HTTP success response?" to "can a TCP socket be opened to it?"

(I'm also open to other ways of solving the problem if what I suggested above isn't possible or doesn't make sense.)

-- Jason Swett
amazon-ec2
kubernetes
load-balancing

1 Answer

12/29/2021

TCP is a valid protocol for health checks in 2 cases:

  1. the classic flavor of the ELB, see docs
  2. The network load balancer, see docs

in case you're stuck with the Application Load Balancer - the only idea that comes to mind is to add a sidecar container that will respond to HTTP/HTTPS based on your TCP status. You could easily do this with nginx, although it would probably be quite an overkill.

-- andrzejwp
Source: StackOverflow