Actualiser readme.md
This commit is contained in:
87
readme.md
87
readme.md
@@ -175,9 +175,9 @@ C:\DevOpsProject\
|
|||||||
└── docs\ # Documentation
|
└── docs\ # Documentation
|
||||||
```
|
```
|
||||||
|
|
||||||
#🐍 ÉTAPE 3 : APPLICATION PYTHON CORRIGÉE
|
## 🐍 ÉTAPE 3 : APPLICATION PYTHON CORRIGÉE
|
||||||
#3.1 Fichier : src\app\requirements.txt
|
### 3.1 Fichier : `src\app\requirements.txt`
|
||||||
|
```
|
||||||
fastapi==0.104.1
|
fastapi==0.104.1
|
||||||
uvicorn[standard]==0.24.0
|
uvicorn[standard]==0.24.0
|
||||||
pydantic==2.5.0
|
pydantic==2.5.0
|
||||||
@@ -185,8 +185,9 @@ prometheus-client==0.19.0
|
|||||||
python-dotenv==1.0.0
|
python-dotenv==1.0.0
|
||||||
pytest==7.4.3
|
pytest==7.4.3
|
||||||
httpx==0.25.1
|
httpx==0.25.1
|
||||||
#3.2 Fichier : src\app\main.py (CORRIGÉ)
|
```
|
||||||
|
#3.2 Fichier : `src\app\main.py `(CORRIGÉ)
|
||||||
|
```
|
||||||
from fastapi import FastAPI, Request, Response, HTTPException
|
from fastapi import FastAPI, Request, Response, HTTPException
|
||||||
from prometheus_client import Counter, Histogram, generate_latest, CONTENT_TYPE_LATEST
|
from prometheus_client import Counter, Histogram, generate_latest, CONTENT_TYPE_LATEST
|
||||||
import time
|
import time
|
||||||
@@ -315,8 +316,10 @@ if __name__ == "__main__":
|
|||||||
log_level="info",
|
log_level="info",
|
||||||
reload=True # Auto-reload en développement
|
reload=True # Auto-reload en développement
|
||||||
)
|
)
|
||||||
#3.3 Fichier : src\app\tests\test_main.py (NOUVEAU)
|
```
|
||||||
|
|
||||||
|
### 3.3 Fichier : `src\app\tests\test_main.py` (NOUVEAU)
|
||||||
|
```
|
||||||
import pytest
|
import pytest
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from main import app
|
from main import app
|
||||||
@@ -361,9 +364,12 @@ def test_env_endpoint():
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
data = response.json()
|
data = response.json()
|
||||||
assert "ENV" in data
|
assert "ENV" in data
|
||||||
#3.4 Fichier : src\app\Dockerfile (OPTIMISÉ)
|
```
|
||||||
|
|
||||||
# Étape 1 : Build
|
### 3.4 Fichier : `src\app\Dockerfile` (OPTIMISÉ)
|
||||||
|
|
||||||
|
Étape 1 : Build
|
||||||
|
```
|
||||||
FROM python:3.11-slim AS builder
|
FROM python:3.11-slim AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@@ -397,9 +403,11 @@ USER devopsuser
|
|||||||
|
|
||||||
# Commande de démarrage
|
# Commande de démarrage
|
||||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--no-access-log"]
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--no-access-log"]
|
||||||
#🐳 ÉTAPE 4 : DOCKER COMPOSE CORRIGÉ
|
```
|
||||||
#4.1 Fichier : docker\docker-compose.yml (RECOMMENCÉ)
|
|
||||||
|
|
||||||
|
## 🐳 ÉTAPE 4 : DOCKER COMPOSE CORRIGÉ
|
||||||
|
### 4.1 Fichier : `docker\docker-compose.yml` (RECOMMENCÉ)
|
||||||
|
```
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
@@ -562,45 +570,58 @@ scrape_configs:
|
|||||||
# alertmanagers:
|
# alertmanagers:
|
||||||
# - static_configs:
|
# - static_configs:
|
||||||
# - targets: []
|
# - targets: []
|
||||||
#4.3 Exécution Docker Compose :
|
```
|
||||||
|
|
||||||
# Se placer dans le dossier docker
|
## 4.3 Exécution Docker Compose :
|
||||||
|
|
||||||
|
Se placer dans le dossier docker
|
||||||
|
```
|
||||||
cd C:\DevOpsProject\docker
|
cd C:\DevOpsProject\docker
|
||||||
|
```
|
||||||
# Lancer en arrière-plan
|
Lancer en arrière-plan
|
||||||
|
```
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
|
```
|
||||||
# Vérifier que tout fonctionne
|
Vérifier que tout fonctionne
|
||||||
|
```
|
||||||
docker-compose ps
|
docker-compose ps
|
||||||
|
```
|
||||||
# Voir les logs de l'application
|
Voir les logs de l'application
|
||||||
|
```
|
||||||
docker-compose logs app
|
docker-compose logs app
|
||||||
|
```
|
||||||
# Tester l'application
|
Tester l'application
|
||||||
|
```
|
||||||
curl http://localhost:8000
|
curl http://localhost:8000
|
||||||
# ou dans PowerShell
|
```
|
||||||
|
ou dans PowerShell
|
||||||
|
```
|
||||||
Invoke-WebRequest -Uri "http://localhost:8000" -UseBasicParsing
|
Invoke-WebRequest -Uri "http://localhost:8000" -UseBasicParsing
|
||||||
#☸️ ÉTAPE 5 : KUBERNETES SIMPLIFIÉ POUR WINDOWS
|
```
|
||||||
#5.1 Activer Kubernetes dans Docker Desktop :
|
|
||||||
|
##☸️ ÉTAPE 5 : KUBERNETES SIMPLIFIÉ POUR WINDOWS
|
||||||
|
### 5.1 Activer Kubernetes dans Docker Desktop :
|
||||||
|
|
||||||
1. Docker Desktop → Settings (roue crantée)
|
1. Docker Desktop → Settings (roue crantée)
|
||||||
2. Onglet Kubernetes
|
2. Onglet Kubernetes
|
||||||
3. ✅ Enable Kubernetes
|
3. ✅ Enable Kubernetes
|
||||||
4. ✅ Show system containers (optional)
|
4. ✅ Show system containers (optional)
|
||||||
5. Apply & Restart (patienter 2-3 minutes)
|
5. Apply & Restart (patienter 2-3 minutes)
|
||||||
#5.2 Vérification :
|
|
||||||
|
|
||||||
# Vérifier que Kubernetes fonctionne
|
### 5.2 Vérification :
|
||||||
|
|
||||||
|
Vérifier que Kubernetes fonctionne
|
||||||
|
```
|
||||||
kubectl cluster-info
|
kubectl cluster-info
|
||||||
# Doit afficher : Kubernetes control plane is running at https://...
|
# Doit afficher : Kubernetes control plane is running at https://...
|
||||||
|
|
||||||
kubectl get nodes
|
kubectl get nodes
|
||||||
# Doit afficher : docker-desktop Ready
|
# Doit afficher : docker-desktop Ready
|
||||||
|
|
||||||
kubectl get pods --all-namespaces
|
kubectl get pods --all-namespaces
|
||||||
# Doit montrer les pods système
|
# Doit montrer les pods système
|
||||||
#5.3 Fichier : kubernetes\manifests\namespace.yaml
|
```
|
||||||
|
|
||||||
|
#### 5.3 Fichier : kubernetes\manifests\namespace.yaml
|
||||||
|
```
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
metadata:
|
metadata:
|
||||||
@@ -608,8 +629,10 @@ metadata:
|
|||||||
labels:
|
labels:
|
||||||
name: devops-demo
|
name: devops-demo
|
||||||
environment: development
|
environment: development
|
||||||
#5.4 Fichier : kubernetes\manifests\configmap.yaml (NOUVEAU)
|
```
|
||||||
|
|
||||||
|
### 5.4 Fichier : kubernetes\manifests\configmap.yaml (NOUVEAU)
|
||||||
|
```
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
@@ -620,8 +643,10 @@ data:
|
|||||||
APP_NAME: "devops-windows-app"
|
APP_NAME: "devops-windows-app"
|
||||||
LOG_LEVEL: "INFO"
|
LOG_LEVEL: "INFO"
|
||||||
PYTHONUNBUFFERED: "1"
|
PYTHONUNBUFFERED: "1"
|
||||||
#5.5 Fichier : kubernetes\manifests\deployment.yaml (SIMPLIFIÉ)
|
```
|
||||||
|
|
||||||
|
### 5.5 Fichier : kubernetes\manifests\deployment.yaml (SIMPLIFIÉ)
|
||||||
|
```
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
@@ -693,6 +718,8 @@ spec:
|
|||||||
protocol: TCP
|
protocol: TCP
|
||||||
name: http
|
name: http
|
||||||
type: NodePort # CORRIGÉ : NodePort au lieu de LoadBalancer pour Windows
|
type: NodePort # CORRIGÉ : NodePort au lieu de LoadBalancer pour Windows
|
||||||
|
```
|
||||||
|
|
||||||
#5.6 Déploiement Kubernetes :
|
#5.6 Déploiement Kubernetes :
|
||||||
|
|
||||||
# 1. Build l'image Docker avec un tag spécifique
|
# 1. Build l'image Docker avec un tag spécifique
|
||||||
|
|||||||
Reference in New Issue
Block a user