spring-boot-admin icon indicating copy to clipboard operation
spring-boot-admin copied to clipboard

Spring boot admin server – client running on multiple instances in AWS

Open PBondugula opened this issue 9 years ago • 9 comments

I have developed spring boot admin server application and spring boot application which is client. I deployed spring boot admin and spring boot application on to the AWS. Able to see the application registering to spring admin from the admin URL. But I have 2 instances in AWS ELB but spring admin not showing multiple instances which should be with + symbol for that application including all the instances. I tried increasing the instances in AWS, once they are up spring admin is not shows the instances. Can you please provide the steps to see all the running instances to show in spring admin.

Thanks.

PBondugula avatar Mar 23 '17 14:03 PBondugula

The applications are identified by their health-url. You need to make sure that both applications have unique ones. They must not reqister with their load-balanced address.

joshiste avatar Mar 23 '17 17:03 joshiste

Do you have any findings or further questions?

joshiste avatar Mar 24 '17 18:03 joshiste

Hi, I have spring boot admin server running on one aws instance. Spring boot client application running other instances which are registered with load balancer. Can you please refer me some correct example with required configurations for both spring admin server side and client side.

PBondugula avatar Mar 24 '17 18:03 PBondugula

Sorry, but I can't provide you an AWS example since I don't use it. Do you understand the described prerequisites from my earlier post? You need do register every instance with a non-load-balanced address.

joshiste avatar Mar 24 '17 18:03 joshiste

Yes, I understood. I will try and let you know. Thanks.

PBondugula avatar Mar 24 '17 18:03 PBondugula

@PBondugula I have the same problem, do you solve it, can give me a reference program?

Damon-LiuZhiJun avatar Aug 16 '17 06:08 Damon-LiuZhiJun

from our gitter:

@snakey1980 If anyone is interested, I got an AWS ECS multi instance set up working with the new awsvpc network style for tasks https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-networking.html. On the SBA client side I had to use the prefer-ip setting and manually pass the IP address (i.e. -Dserver.address=) to the Java process, it couldn't figure out IP or hostname on its own. To be clear SBA works fine here, all these workarounds are for ECS

joshiste avatar Mar 13 '18 16:03 joshiste

Building on what @joshiste mentioned, to be able to register different instances, these instances need to register with different health URLs. The URL can be either the public or private IP or DNS of the individual instance but not the URL of the load balancer.

On AWS, information about the EC2 instance can be retrieved by the special URL http://169.254.169.254/latest/meta-data that's only accessible if you run it inside of an AWS EC2 instance. For example. to get the private (local) IP of the running instance, run (on that instance):

curl  http://169.254.169.254/latest/meta-data/local-ipv4

Assuming the SBA server can access the private IP of the SBA clients, you'd set the spring.boot.admin.client.instance.service-base-url to http://privateIp:port where privateIp is the address you get from the meta-data request and port is the instance port that forwards to the Docker container running your SBA client.

But, how can you set the privateId dynamically and differently on each instance? Here's one way (workaround?) of doing so in Java (which assumes the instance port is the default HTTP port; 80):

@Slf4j
@SpringBootApplication
public class SbaClientApplication {

	public static void main(String[] args) {
		SpringApplication application = new SpringApplication(SbaClientApplication.class);

		setSbaPropsOnAws(application);

		application.run(args);
    }

    private static void setSbaPropsOnAws(SpringApplication application) {

		RestTemplate restTemplate = new RestTemplateBuilder().setConnectTimeout(Duration.ofSeconds(5)).build();
		try {

			String awsPrivateIp =
			restTemplate.getForObject("http://169.254.169.254/latest/meta-data/local-ipv4", String.class);

			if (awsPrivateIp != null) {

				Properties properties = new Properties();
				properties.put("spring.boot.admin.client.instance.service-base-url", "http://" + awsPrivateIp);
				application.setDefaultProperties(properties);
			}

		} catch (ResourceAccessException e) {

			log.debug("Could not access http://169.254.169.254/latest/meta-data/local-ipv4. " +
					"Probably not running on AWS. SBA registration might not work as expected.");
		}
	}
}

sayadi avatar Jun 13 '20 20:06 sayadi

I configured the spring boot admin through LB

` @Bean public WebServerFactoryCustomizer webServerFactoryCustomizer() {

	return factory -> factory.setContextPath("/springadmin");
} `

At the nginx server

`http { client_max_body_size 250M;

upstream mybackend { #Round Robin - default server 127.0.0.1:9091; server 127.0.0.1:9092; }

upstream springAdmin { #Round Robin - default server 127.0.0.1:9011; }

server { listen 8080; location / { proxy_pass http://mybackend; } location /springadmin { proxy_pass http://springAdmin; } } } events { worker_connections 10000; }`

manojgct84 avatar Jun 27 '22 16:06 manojgct84