keijack / python-eureka-client

A eureka client written in python. Support registering your python component to Eureka Server, as well as calling remote services by pulling the the Eureka registry.
MIT License
184 stars 43 forks source link

Sanic + Uvicorn app is not registering to Eureka #28

Closed TheGlobalist closed 4 years ago

TheGlobalist commented 4 years ago

Hi, this is a similar issue to #27 but, since it was closed, I preferred to open a new one. I am trying to deploy a Python Microservice built on Sanic (and served on Uvicorn) that can attach itself to Eureka. Both Eureka and the microservices are inside a docker container (each for one of them). Currently, I'm using this

if __name__ == "__main__":
    import py_eureka_client.eureka_client as eureka_client

    # The flowing code will register your server to eureka server and also start to send heartbeat every 30 seconds
    eureka_client.init(eureka_server="http://<server ip>:8761/eureka/",
                       app_name="user-service",
                       instance_port=8071)
    run_app(sanic_app)

With Uvicorn, I'm not able to see any logs. So, if I try to remove it, and deploy only via Sanic, I'm getting the same error of #27 . If I try to http://:8761/ on my browser, I can reach Eureka. If I try to curl -f http://<server ip>:8761/, I get the HTML of Eureka's page. If I try to do either of these options followed by /eureka, I get a 404 in both cases. I've also tried to deploy a Docker image of Eureka made by Mr. @dinuta but that didn't seem to work.

If I also try to write the previous lines of code on a Python shell, Eureka correctly receives everything and registers the "fake" service.

Can anyone point me in the right direction?

dinuta commented 4 years ago

if it is dockerized:

if you are using docker compose:

if you are using only host apps:

if you are using a hybrid solution host/docker:

dinuta commented 4 years ago

Example docker-compose: https://github.com/dinuta/estuary-agent/blob/master/docker-compose.yml Another example with a microservice which discovers all eureka apps: https://github.com/dinuta/estuary-discovery/blob/master/docker-compose.yml

Example in docker with ports fwded on host: estuary-stack

TheGlobalist commented 4 years ago

if it is dockerized:

  • make sure you point to eureka host ip:port like I do.
  • dont forget to open the port from eureka on the host if dockerized.
  • your app/microservice must listen on 0.0.0.0:your_app_port to attach to all interfaces.

if you are using docker compose:

  • this is easier since every service has its DNS entry in docker world.

if you are using only host apps:

  • debug them with curl/telnet /etc

if you are using a hybrid solution host/docker:

  • make sure you always work on host net (this means your docker containers must bind on all interfaces 0.0.0.0 and all the ports are fwded to the host )

Yes, it is dockerized and also exploits docker-compose.

This is Eureka's Dockerfile:

FROM openjdk:14
COPY ./ServiceDiscovery/eureka-service-0.0.1-SNAPSHOT.jar .
EXPOSE 8761
CMD ["java", "-jar", "eureka-service-0.0.1-SNAPSHOT.jar"]

while this is the fragment of the docker-compose.yml that is related to Eureka:

  eureka-service:
    container_name: eureka-service
    hostname: eurekaservice
    build:
      context: .
      dockerfile: ./ServiceDiscovery/Dockerfile
    image: eureka-service:latest
    environment:
      VIRTUAL_HOST: eureka.dataex.software
    expose:
      - 8761
    ports:
      - 8761:8761

Also: the microservices are instantiated to host 0.0.0.0 already

dinuta commented 4 years ago

Man, I don;t understand from where your service connects, to where eureka is. In general keep it simple, either on host, either in docker world.

My eureka is proven to work, with tests: https://github.com/dinuta/netflixoss-eureka/blob/master/Dockerfile

And one more thing: your Dockerfile is strange. Who is eureka-service-0.0.1-SNAPSHOT.jar file? 👎

I might guess that eureka server does not bind to 0.0.0.0 ...

dinuta commented 4 years ago

Any luck, @TheGlobalist ?

dinuta commented 4 years ago

@keijack please close the issue since no response was sent back

keijack commented 4 years ago

response was sent back