Actualiser readme.md
This commit is contained in:
87
readme.md
87
readme.md
@@ -175,9 +175,9 @@ C:\DevOpsProject\
|
||||
└── docs\ # Documentation
|
||||
```
|
||||
|
||||
#🐍 ÉTAPE 3 : APPLICATION PYTHON CORRIGÉE
|
||||
#3.1 Fichier : src\app\requirements.txt
|
||||
|
||||
## 🐍 ÉTAPE 3 : APPLICATION PYTHON CORRIGÉE
|
||||
### 3.1 Fichier : `src\app\requirements.txt`
|
||||
```
|
||||
fastapi==0.104.1
|
||||
uvicorn[standard]==0.24.0
|
||||
pydantic==2.5.0
|
||||
@@ -185,8 +185,9 @@ prometheus-client==0.19.0
|
||||
python-dotenv==1.0.0
|
||||
pytest==7.4.3
|
||||
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 prometheus_client import Counter, Histogram, generate_latest, CONTENT_TYPE_LATEST
|
||||
import time
|
||||
@@ -315,8 +316,10 @@ if __name__ == "__main__":
|
||||
log_level="info",
|
||||
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
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
@@ -361,9 +364,12 @@ def test_env_endpoint():
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
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
|
||||
|
||||
WORKDIR /app
|
||||
@@ -397,9 +403,11 @@ USER devopsuser
|
||||
|
||||
# Commande de démarrage
|
||||
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'
|
||||
|
||||
services:
|
||||
@@ -562,45 +570,58 @@ scrape_configs:
|
||||
# alertmanagers:
|
||||
# - static_configs:
|
||||
# - 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
|
||||
|
||||
# Lancer en arrière-plan
|
||||
```
|
||||
Lancer en arrière-plan
|
||||
```
|
||||
docker-compose up -d
|
||||
|
||||
# Vérifier que tout fonctionne
|
||||
```
|
||||
Vérifier que tout fonctionne
|
||||
```
|
||||
docker-compose ps
|
||||
|
||||
# Voir les logs de l'application
|
||||
```
|
||||
Voir les logs de l'application
|
||||
```
|
||||
docker-compose logs app
|
||||
|
||||
# Tester l'application
|
||||
```
|
||||
Tester l'application
|
||||
```
|
||||
curl http://localhost:8000
|
||||
# ou dans PowerShell
|
||||
```
|
||||
ou dans PowerShell
|
||||
```
|
||||
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)
|
||||
2. Onglet Kubernetes
|
||||
3. ✅ Enable Kubernetes
|
||||
4. ✅ Show system containers (optional)
|
||||
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
|
||||
# Doit afficher : Kubernetes control plane is running at https://...
|
||||
|
||||
kubectl get nodes
|
||||
# Doit afficher : docker-desktop Ready
|
||||
|
||||
kubectl get pods --all-namespaces
|
||||
# Doit montrer les pods système
|
||||
#5.3 Fichier : kubernetes\manifests\namespace.yaml
|
||||
```
|
||||
|
||||
#### 5.3 Fichier : kubernetes\manifests\namespace.yaml
|
||||
```
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
@@ -608,8 +629,10 @@ metadata:
|
||||
labels:
|
||||
name: devops-demo
|
||||
environment: development
|
||||
#5.4 Fichier : kubernetes\manifests\configmap.yaml (NOUVEAU)
|
||||
```
|
||||
|
||||
### 5.4 Fichier : kubernetes\manifests\configmap.yaml (NOUVEAU)
|
||||
```
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
@@ -620,8 +643,10 @@ data:
|
||||
APP_NAME: "devops-windows-app"
|
||||
LOG_LEVEL: "INFO"
|
||||
PYTHONUNBUFFERED: "1"
|
||||
#5.5 Fichier : kubernetes\manifests\deployment.yaml (SIMPLIFIÉ)
|
||||
```
|
||||
|
||||
### 5.5 Fichier : kubernetes\manifests\deployment.yaml (SIMPLIFIÉ)
|
||||
```
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
@@ -693,6 +718,8 @@ spec:
|
||||
protocol: TCP
|
||||
name: http
|
||||
type: NodePort # CORRIGÉ : NodePort au lieu de LoadBalancer pour Windows
|
||||
```
|
||||
|
||||
#5.6 Déploiement Kubernetes :
|
||||
|
||||
# 1. Build l'image Docker avec un tag spécifique
|
||||
|
||||
Reference in New Issue
Block a user