Enoncé TP 1

/images/k8s.jpeg

TP1 : Mongodb

🇫🇷 Version Française

Deployment

Créer un deployment mongo db avec comme image docker : mongo:4.0.8.

Ce deployment va créér (par défault) 1 pod, l’utilisation des selecteurs est important (deployment -> pod). On attribuera le label role: mongo.

Service

Créer un service qui va servir à exposer notre pod Mongo à l’intérieur de notre cluster afin qu’il puisse être utilisé comme DB pour d’autres pods (un backend par exemple…).

Ce service ciblera les pods du deployment instancié plus hauts.

On mettra tout d’abord le service en type NodePort afin de pouvoir le tester.

Pour tester il faudra d’abord retrouvé l’IP de minikube via la commande minikube ip; puis tester la connexion à mongo via http ça ne marchera pas mais ça vous dira si votre cluster mongo est up et accessible ou non : curl MINIKUBE_IP:NODE_PORT Vous deviez avoir un message comme celui ci : “It looks like you are trying to access MongoDB over HTTP on the native driver port.”

On enlevera le type NodePort afin qu’il ne soit pas accessible directement via un port de la VM.

Note : le port par défault de mongo est le port 27017 et sera celui à utiliser pour accéder à notre pod.

🇬🇧 English version

Deployment

Create a deployment mongoDb with the docker image : mongo:4.0.8.

This deployment will create (by default) 1 pod, the use of the label selector is really important (deployment -> pod). We will use the label role: mongo.

Service

Create a service, it will expose your mongoDb pod inside the cluster. This service will be used by other pod to communicate with your mongoDb pod (a backend for example…).

This service will target the previously deployed pod.

This will be of type NodePort to be able to test it.

To test it, you will first have to find the ip of your minikube cluster with the command minikube ip; after that to test the connection to mongoDb with the command curl MINIKUBE_IP:NODE_PORT,it will fail but it will tell you that your mongo is runnning and accessible, a message like that : “It looks like you are trying to access MongoDB over HTTP on the native driver port.”

After your test, transform the service from NodePort to a classic ClusterIp (it’s the default value for a service).

FYI : the default port of mongoDb is 27017 and it will be the one you must use during all the TPs.

Latest Posts