Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a health check for XRAY Daemon Task

Tags:

I'm trying to implement XRAY for our AWS ECS spring boot application. To do so I'm creating a new task with a separate docker file just for the docker daemon as suggested by the AWS documentation and suggested when I asked another question on the Daemon setup.

However, when I try to deploy this to AWS, a health check endpoint is required for the load balancer is required to be able to determine that the service has been deployed successfully.

There is no health check functionality in the daemon itself. There's a thread on the AWS forums as well as an issue on the github repo related to this.

My initial idea is to create an application (probably spring-boot) that is able to determine if the daemon is running and expose a URL that the elb can hit to do a health check on the daemon. I can then deploy it along with the daemon.

Is there a better way to go about doing this? I worry about the need of creating a separate application just for creating a health check. There may be some hackiness required in order to run two entrypoint commands in the docker file as well.

Any ideas on a better way to accomplish this?

like image 461
greenJavaDev Avatar asked Jan 09 '19 23:01

greenJavaDev


1 Answers

You don't need to use Load Balancer at all for X-Ray Docker Container Daemon since traffic is coming from cluster EC2 containers only. Healthcheck for X-Ray container can be done using AWS ECS Healthcheck itself.

Based on the forum answer, you can configure netstat on container healthcheck which will make sure if udp port is not opened by daemon container then ECS Agent will restart container.

Below is HealthCheck command you provide in ECS Task definition.

CMD-SHELL, netstat -aun | grep 2000 > /dev/null; if [ 0 != $? ]; then exit 1; fi;

Here is the setup and result.

Task Def

Healthy

Note--

If you are building X-Ray Docker image, please make sure you include netstat utility in Dockerfile otherwise health command will fail.

Example - if you are using Dockerfile gave in this documentation then you need to add net-tools package to your X-Ray container image.

Following is my updated Dockerfile which adds net-tools to image.

FROM ubuntu:16.04
RUN apt-get update && apt-get install -y --force-yes --no-install-recommends apt-transport-https curl ca-certificates wget net-tools && apt-get clean && apt-get autoremove && rm -rf /var/lib/apt/lists/*
RUN wget https://s3.dualstack.us-east-2.amazonaws.com/aws-xray-assets.us-east-2/xray-daemon/aws-xray-daemon-3.x.deb
RUN dpkg -i aws-xray-daemon-3.x.deb
CMD ["/usr/bin/xray", "--bind=0.0.0.0:2000"]
EXPOSE 2000/udp
like image 195
Imran Avatar answered Nov 12 '22 13:11

Imran