01. October 2023
Enoncé TP 4

TP4 : Backend
🇫🇷 Version Française
Deployment
Créer un deployment pour notre Backend avec comme image docker : axelpereira/k8s-training-test-app-back:1.0
.
Ce deployment va devoir créer des pods qui vont répondre à plusieurs exigences :
- Ils doivent avoir le label
app: back-training-app
- L’image doit être pull seulement lorsqu’elle n’est pas présente dans notre cluster.
- Ils doivent avoir les variables d’environnement :
- MONGO_HOSTNAME -> DNS interne kubernetes pour accéder à Mongodb
- MONGO_PORT -> port exposé par mongo (27017)
- MONGO_DB -> nom de la base que l’on va utiliser (
training
)
Le container expose déjà le port 5000 donc pas besoin de l’exposé une autre fois dans le deployment.
Service
Créer un service qui va servir à exposer notre pod Backend à l’exterieur de notre cluster via une route défini que l’on définira dans l’ingress.
Ce service aura comme nom : back-training-app
Ce service ciblera les pods du deployment instancié plus hauts.
Ce service mappera le port 80 du service en entrée avec le port 5000 du pod sur lequel écoute notre backend.
Ingress applciatif
L’ingress va devoir router une nouvelle route pour le backend.
Ajouter la route /api
vers le service backend.
L’application écoute sur /quelque-chose
et non /api/quelque-chose
donc il va falloir ajouter des parametres à l’ingress.
- L’annotation rewrite target permet de réécrire l’url qui est transmis au service.
- les paths en
/quelque-chose/(.*)
indique que tous les urls en/quelque-chose
seront transmis au service correspondant peu importe ce qui suit l’url.
Deux solutions sont possibles pour ce TPs, la plus propre va être de créér un ingress spécifique pour le backend en plus de celui du frontend.
Pour tester vous pouvez essayer de créer un utilisateur via votre application (via le bouton “register”) avec des fausses valeurs. Plusieurs comportement peuvent arriver après avoir cliquer sur “register” :
- Aucun retour : la connexion à votre backend ne marche pas vérifiez que tout est configuré correctement (regardez l’onglet “réseau” de votre console developpeur de votre navigateur)
- Un retour rouge : indique que la connexion au back se fait, maintenant il faut tester avec des vraies valeurs
- un changement d’écran : indique que l’utilisateur est créé
🇬🇧 English version
Deployment
Create a deployment for our Backend with the docker image: axelpereira/k8s-training-test-app-back:1.0
.
This deployment will have to create pods that will meet several requirements:
- They must have the label
app: back-training-app
- The image should only be pulled when it is not present in our cluster.
- They must have the environment variables:
- MONGO_HOSTNAME -> Kubernetes internal DNS to access Mongodb
- MONGO_PORT -> port exposed by mongo (27017)
- MONGO_DB -> name of the database that we will use (
training
)
The container already exposes port 5000 so no need to expose it again in the deployment.
Service
Create a service which will be used to expose our Backend pod outside our cluster via a defined route which we will define in the ingress.
This service will have the name: back-training-app
This service will target the previously instantiated deployment pods.
This service will map port 80 of the input service to port 5000 of the pod on which our backend is listening.
Ingress applciatif
The ingress will have to route a new path for the backend.
Add the /api
path to the backend service.
The application listens on /something
and not /api/something
so we will have to add parameters to the ingress.
- The rewrite target annotation allows you to rewrite the URL that is transmitted to the service.
- paths in
/something/(.*)
indicates that all urls in/something
will be transmitted to the corresponding service regardless of what follows the url.
Two solutions are possible for this TPs, the cleanest will be to create a specific ingress for the backend in addition to the frontend one.
To test you can try to create a user via your application (via the “register” button) with false values. Several behaviors can occur after clicking “register”:
- No feedback: the connection to your backend does not work, check that everything is configured correctly (look at the “network” tab of your developer console in your browser)
- A red return: indicates that the connection to the back is made, now we must test with real values
- a screen change: indicates that the user is created