Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to register External Service (Non MSA) On Eureka Discovery registry

I am using Kibna inside Docker.

I am running the Kibana using docker-compose

Below is My docker-compose.yml

  version: '2'
    services:
      elasticsearch:
        image: elasticsearch
        expose:
          - 9200
        ports:
          - "9200:9200"
        networks:
          - cloud      
      
      
      fluentd:
        build: ./fluentd
        volumes:
          - ./fluentd/conf:/fluentd/etc
        links:
          - "elasticsearch"
        ports:
          - "24224:24224"
          - "24224:24224/udp"
        networks:
          - cloud  
      
    
      kibana:
        image: kibana
        links:
          - "elasticsearch"
        ports:
          - "9201:5601"
        networks:
          - cloud
    
    networks:
      cloud:
       driver: bridge

I want to enroll this Kibana application on Eureka discovery registry

so that I can call this using API-gateway

Below Is the sample the way I enroll My API-gateway on Eureka

eureka:
  client:
    serviceUrl:
      defaultZone: http://eureka-server:8761/eureka/
    registry-fetch-interval-seconds: 60
  instance:
    hostname: api-gateway
    prefer-ip-address: false
    lease-renewal-interval-in-seconds: 5000
    lease-expiration-duration-in-seconds: 5000

API-gateway is a spring-boot application so it's straightforward.

I am running kibana using docker (Image). How can I achieve the same for this

Any help will be appreciable.

Thanks In advance

like image 461
Tukaram Patil Pune Avatar asked Apr 03 '18 07:04

Tukaram Patil Pune


People also ask

How do I register a service with Eureka server?

Hit the URL http://localhost:8761/ in your web browser and you can see the Eureka Client application is registered with Eureka Server. Now hit the URL http://localhost:8080/ in your web browser and see the Rest Endpoint output.

How do I put service in defaultZone?

defaultZone URLs has credentials embedded in it (curl style, as follows: http://user:password@localhost:8761/eureka ). For more complex needs, you can create a @Bean of type DiscoveryClientOptionalArgs and inject ClientFilter instances into it, all of which is applied to the calls from the client to the server.

How do I configure service discovery in spring boot?

Registering Microservices As Spring Boot finds the library in the classpath, it registers automatically to the Eureka Server. Step 2: Add src/main/resources/bootstrap. properties and the property as below. The discovery server will register the service with this name(id).


Video Answer


1 Answers

Registering a java application with Eureka is not a big deal, because Netflix supplies a java Eureka client that is included in your classpath when using the spring-cloud-starter-netflix-eureka-client dependency. And Spring Boot will configure this client from your application properties.

Registering and application from outside the application code is different situation. You can certainly still do this.

I will just mention a little theory here, and then get to a suggested solution.

Theory

The basic way to do this, is to use the Eureka REST operations. This is an API where you can manually register/unregister service instances, and supply a regular heartbeat for Eureka to consider the service instance available.

It's really not a very large API, and with your current knownledge of Eureka client configuration you would probably have an easy time.

Solution with spring-cloud-netflix-sidecar

Spring Cloud already has your usecase covered! The approach here is that you will create a companion container for kibana, a sidecar. And the application in this container will be responsible for registering your service with Euerka. This type of application is very small, it will be quick to implement with Java and Spring Cloud.

Here's the documentation from Spring Cloud: Polyglot support with Sidecar

Here's a tutorial on it: Spring Cloud Netflix Sidecar Tutorial

And here's a repository that does this in a very simple way: Spring-Cloud-Sidecar_Tutorial

There is almost no code in the sidecar application, only this application class (taken from the repository above):

package com.craftcodecrew.lumen.service.sidecar;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.sidecar.EnableSidecar;

@SpringBootApplication
@EnableSidecar
public class LumenServiceSidecarApplication {

    public static void main(String[] args) {
        SpringApplication.run(LumenServiceSidecarApplication.class, args);
    }
}

This configuration:

server:
  port: 5678

spring:
  application:
    name: lumen-service

eureka:
  client:
    serviceUrl:
      defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
  instance:
    preferIpAddress: true

sidecar:
  port: ${SIDECAR_PORT:8000}
  health-uri: ${SIDECAR_HEALTH_URI:http://localhost:8000/health}
  home-page-uri: ${SIDECAR_HOMEPAGE_URI:http://localhost:8000/}

And a very simple pom.xml.

As you can see, the sidecar library takes some configuration that you need to point to your kibana instance. So, they need to be on the same network. And also on the same network as Eureka.

Provided that your kibana container name is 'kibana', your config would look like this:

server:
  port: 5678

spring:
  application:
    name: kibana

eureka:
  client:
    serviceUrl:
      defaultZone: ${EUREKA_URI:http://eureka:8761/eureka}
  instance:
    preferIpAddress: true

sidecar:
  port: ${SIDECAR_PORT:5601}
  health-uri: ${SIDECAR_HEALTH_URI:http://kibana:5601/status}
  home-page-uri: ${SIDECAR_HOMEPAGE_URI:http://kibana:5601/}

You could also control those values in environment variables configured in the docker-compose definition. Like so:

  kibana-sidecar:
    image: kibana-sidecar
    links:
      - "kibana"
    ports:
      - "5678:5678"
    environment:
      - EUREKA_URI=<your_eureka_instance_uri>
      - SIDECAR_PORT=5601
      - SIDECAR_HEALTH_URI=http://kibana:5601/status
      - SIDECAR_HOMEPAGE_URI=http://kibana:5601/
    networks:
      - cloud
like image 124
Andreas Lorenzen Avatar answered Sep 30 '22 00:09

Andreas Lorenzen