TL;DR. Faragate Platform Version 1.4.0 을 쓰지 말고 1.3.0 을 써보면 문제가 해결될 수 있다.
사내에다가 정리해놓은 문서가 있고, 모든 내용을 다 옮기기엔 가려야할 내용도 많고 번거로워서 결론만 간추려서 작성함
----
container health check 방법을 `CMD-SHELL,echo hello` 로 해도 container health check failed 의 이유로 task 가 container 들에게 sigterm 을 보내서 컨테이너가 종료되고, ELB 는 종료된 컨테이너로 계속 트래픽을 보내고 있어서 client 에게는 502 Bad Gateway 응답이 나가는 상황이 간헐적으로 발생하고 있었음. 이 때만 해도 문제를 쉽게 해결할 수 있을 거라 생각했음.
힌트를 얻은 링크들
https://github.com/aws/containers-roadmap/issues/898
[Fargate] [bug/regression]: Container health checks not working anymore with 1.4.0 · Issue #898 · aws/containers-roadmap
We already opened a support ticket, but just for visibility to gauge if this is a feature that has been used a lot or not. With Fargate 1.4.0 container health checks do not work anymore.
github.com
결론적으로 heatlth check method 를
CMD-SHELL, curl -s -f http://localhost/health 2>/dev/null || exit 1
로 변경하고 Fargate Platform Version 을 1.3.0 으로 다운그레이드하여 적용하니 문제가 싹 사라졌다.
STDERR 을 /dev/null 로 리다이렉션하는 것도 반드시 있어야만 하는 것인지는 확실하지 않다.
http 응답이 non-success 라면 curl 명령어가 non-zero code 로 exit 하는 것은 확인하였다.
이 문제에 대해 AWS 에 문의를 보내놓은 상태이지만, 명쾌한 답변이 며칠동안 오지 않는다.