SpringBoot, DiscoveryServer et Config Server

20
DIRECTION DES SYSTEMES D’INFORMATION Rendre une application Spring Boot résiliente JDEV 2020 Stéphane Deraco <[email protected] > Spring Boot, Discovery Server et Config Server

Transcript of SpringBoot, DiscoveryServer et Config Server

Page 1: SpringBoot, DiscoveryServer et Config Server

DIRECTION DES SYSTEMES D’INFORMATION

Rendre une application Spring Boot résiliente

JDEV 2020

Stéphane Deraco <[email protected]>

Spring Boot, Discovery Server et Config

Server

Page 2: SpringBoot, DiscoveryServer et Config Server

P 2DIRECTION DES SYSTEMES D’INFORMATION

Agenda

• Une appli web et 1 service• Deux instances du service• Discovery Server• Config Server• Conclusion

0

Page 3: SpringBoot, DiscoveryServer et Config Server

P 3DIRECTION DES SYSTEMES D’INFORMATION

Architecture initiale

• Spring Boot• Idée : Récupérer la position de l’ISS

• « web » → « position-fetcher » toutes les 5 secondes• « position-fetcher » retourne l’adresse postale de l’ISS• « web » met jour la page web

1

Page 4: SpringBoot, DiscoveryServer et Config Server

P 4DIRECTION DES SYSTEMES D’INFORMATION

Architecture initiale

• « position-fetcher »

1

Page 5: SpringBoot, DiscoveryServer et Config Server

P 5DIRECTION DES SYSTEMES D’INFORMATION

Architecture initiale

• « web »• Toutes les 5 secondes, appel du service…

• … avec un RestTemplate

1

Page 6: SpringBoot, DiscoveryServer et Config Server

P 6DIRECTION DES SYSTEMES D’INFORMATION

Architecture initiale

• « web »• … pour au final mettre à jour la page web avec une WebSocket

1

Page 7: SpringBoot, DiscoveryServer et Config Server

P 7DIRECTION DES SYSTEMES D’INFORMATION

Architecture initiale1

Page 8: SpringBoot, DiscoveryServer et Config Server

P 8DIRECTION DES SYSTEMES D’INFORMATION

Plusieurs instances du service de position

• URLs configurées en dur• Manque de souplesse

2

Page 9: SpringBoot, DiscoveryServer et Config Server

P 9DIRECTION DES SYSTEMES D’INFORMATION

Plusieurs instances du service de position

• Plusieurs solutions• API Gateway• VIP, Load Balancer• Kubernetes• Discovery Server

2

Page 10: SpringBoot, DiscoveryServer et Config Server

P 10DIRECTION DES SYSTEMES D’INFORMATION

Discovery Server

• Application Spring Boot• Basée sur les projets Netflix

3

� Chaque instance du service s’enregistre sur le DS pour indiquer son nom (son service) et son url

� « web » interroge le DS pour récupérer la liste des urls proposant un service donné

� « web » interroge alors directement une des instances retournées par le DS

Page 11: SpringBoot, DiscoveryServer et Config Server

P 11DIRECTION DES SYSTEMES D’INFORMATION

Discovery Server3

Discovery Server

Page 12: SpringBoot, DiscoveryServer et Config Server

P 12DIRECTION DES SYSTEMES D’INFORMATION

Discovery Server3

Page 13: SpringBoot, DiscoveryServer et Config Server

P 13DIRECTION DES SYSTEMES D’INFORMATION

Discovery Server3

Page 14: SpringBoot, DiscoveryServer et Config Server

P 14DIRECTION DES SYSTEMES D’INFORMATION

Discovery Server

• Gestion des indisponibilités• Le DS fonctionne par heartbeat

• Si une instance tombe, le DS n’est pas notifié• Au bout d’un certain temps sans heartbeat de l’instance le DS le considère non

disponible et ne la retournera plus• « web » a un cache local des instances (ne pas interroger le DS à

chaque fois)• Même si une instance est sortie du DS, elle peut encore être présente dans le

cache local

• Solution Spring• spring-retry

3

Page 15: SpringBoot, DiscoveryServer et Config Server

P 15DIRECTION DES SYSTEMES D’INFORMATION

Discovery Server3

Page 16: SpringBoot, DiscoveryServer et Config Server

P 16DIRECTION DES SYSTEMES D’INFORMATION

Discovery Server

• Plusieurs instances du services• Ajout et suppression dynamique

• Comment s’assurer que la configuration de chaque instance est la même ?

3

Page 17: SpringBoot, DiscoveryServer et Config Server

P 17DIRECTION DES SYSTEMES D’INFORMATION

Config Server

• Problème : N instances avec toutes la même configuration

• Si fichiers de conf gérés manuellement, risques d’erreur

• Solutions possibles• Déployer les instances avec Ansible• Config Server• Mode Config First

• Les instances récupèrent l’emplacement du DS dans la config via le CS

• Mode Discovery First• Les instances interrogent le DS pour connaitre l’emplacement du CS

4

Page 18: SpringBoot, DiscoveryServer et Config Server

P 18DIRECTION DES SYSTEMES D’INFORMATION

Config Server

• Application Spring Boot

4

� Le CS s’enregistre sur le DS� Les services interrogent le DS pour connaitre l’adresse du CS� Les services interrogent le CS pour obtenir leur configuration

�bis Le CS récupère la configuration du service via Git

� Les services s’enregistrent sur le DS� Interrogation du DS pour avoir les URLsdes services� Appel du service

Page 19: SpringBoot, DiscoveryServer et Config Server

P 19DIRECTION DES SYSTEMES D’INFORMATION

Conclusion

• Fonctionnalités Spring « Cloud »• Discovery• Config• Beaucoup d’autres projets https://spring.io/projects/spring-cloud

• Pour aller plus loin• Cluster de DS et CS• Authentification et autorisation des appels au DS et CS (Spring Security)

• À utiliser si adapté au besoin, à l’infra, aux compétences existantes, …

• Cluster K8S en place ?• Hashicorp Consul déjà utilisé ?• Déploiement via Ansible ?

• Code source• https://forge.git.cnrs.fr/jdev2020

5

Page 20: SpringBoot, DiscoveryServer et Config Server

P 20DIRECTION DES SYSTEMES D’INFORMATION

Merci de votre attention5

Ressources et crédits

Emplacement ISSEn direct : https://www.esa.int/Science_Exploration/Human_and_Robotic_Exploration/International_Space_Station/Where_is_the_International_Space_Station

Latitude et longitude : API de https://wheretheiss.at/w/developer

Reverse Geo IP : https://nominatim.openstreetmap.org/ (basé sur OpenStreetMap)

Spring BootGuide Service Registration and Discovery : https://spring.io/guides/gs/service-registration-and-discovery/

Guide Centralized Configuration : https://spring.io/guides/gs/centralized-configuration/

Doc : Spring Cloud Netflix : https://cloud.spring.io/spring-cloud-netflix/2.2.x/reference/html/

Doc : Spring Cloud Config : https://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.2.3.RELEASE/reference/html/