Merge branch 'main' of https://git.bonisco.fr/OrgaDevops/Tuto-Devops-A---Z
This commit is contained in:
@@ -1,57 +1,51 @@
|
|||||||
#TP DevOps Corrigé par DeepSeek
|
# TP DevOps
|
||||||
|
|
||||||
# ...et en cours de restructuration par Oualim (commentaires pour le futur pour tester une autre création à l'IA d'un tp, en tenant compte des manquements et des erreurs pour ne pas laisser l'IA les reproduire)
|
...et en cours de restructuration par Oualim (commentaires pour le futur pour tester une autre création à l'IA d'un tp, en tenant compte des manquements et des erreurs pour ne pas laisser l'IA les reproduire)
|
||||||
|
|
||||||
Original pourrit: https://cloud.bonisco.fr/s/Cb2bFdLXeFEFcLm
|
Original pourrit: https://cloud.bonisco.fr/s/Cb2bFdLXeFEFcLm
|
||||||
|
|
||||||
# Commentaire de Oualim (Celui de Deepseek est juste un peu moins pourri mais c'était aussi de la merde)
|
> Commentaire de Oualim (Celui de Deepseek est juste un peu moins pourri mais c'était aussi de la merde)
|
||||||
# Ce TP contient encore beaucoup de fautes sur les manips et fichiers et aucun sens sur la structure car l'IA a juste pris les mots clefs de "devops" sur internet, copié des fichiers et mélangé des concepts sans aucune présentation ni introduction ou explications (ex : correctif de l'ancien tp tout en bas :-/ ; terraform sur des docker ??? ; kub en faisant un doublon d'appli potentiellement conflictuel, aucune explication ni structure d'étape pour comprendre les logiques de docker et k8')
|
> Ce TP contient encore beaucoup de fautes sur les manips et fichiers et aucun sens sur la structure car l'IA a juste pris les mots clefs de "devops" sur internet, copié des fichiers et mélangé des concepts sans aucune présentation ni introduction ou explications (ex : correctif de l'ancien tp tout en bas :-/ ; terraform sur des docker ??? ; kub en faisant un doublon d'appli potentiellement conflictuel, aucune explication ni structure d'étape pour comprendre les logiques de docker et k8')
|
||||||
|
|
||||||
|
|
||||||
#📚 RÉCAPITULATIF DES CORRECTIONS APPORTÉES
|
#📚 RÉCAPITULATIF DES CORRECTIONS APPORTÉES
|
||||||
#✅ Corrections majeures :
|
|
||||||
Python : Ajout de Response dans les imports FastAPI
|
|
||||||
|
|
||||||
Docker Compose : Chemins corrigés, versions spécifiées
|
## ✅ Corrections majeures :
|
||||||
|
* Python : Ajout de Response dans les imports FastAPI
|
||||||
Kubernetes : Changé LoadBalancer → NodePort pour Windows
|
* Docker Compose : Chemins corrigés, versions spécifiées
|
||||||
|
* Kubernetes : Changé LoadBalancer → NodePort pour Windows
|
||||||
Image Docker : Tag :local au lieu de :latest pour K8s
|
* Image Docker : Tag :local au lieu de :latest pour K8s
|
||||||
|
* Terraform : Suppression du provider Docker problématique
|
||||||
Terraform : Suppression du provider Docker problématique
|
* Scripts : Ajout de gestion d'erreurs robuste
|
||||||
|
* Tests : Ajout de tests unitaires Python
|
||||||
Scripts : Ajout de gestion d'erreurs robuste
|
* Health checks : Ajout dans Docker Compose et K8s
|
||||||
|
|
||||||
Tests : Ajout de tests unitaires Python
|
|
||||||
|
|
||||||
Health checks : Ajout dans Docker Compose et K8s
|
|
||||||
|
|
||||||
|
|
||||||
#🎯 Améliorations :
|
## 🎯 Améliorations :
|
||||||
Structure de projet logique et organisée
|
* Structure de projet logique et organisée
|
||||||
|
* Scripts PowerShell avec paramètres et gestion d'erreurs
|
||||||
Scripts PowerShell avec paramètres et gestion d'erreurs
|
* Configuration monitoring fonctionnelle
|
||||||
|
* Documentation claire étape par étape
|
||||||
Configuration monitoring fonctionnelle
|
* Solutions de dépannage incluses
|
||||||
|
* Versionning spécifique des images Docker
|
||||||
Documentation claire étape par étape
|
|
||||||
|
|
||||||
Solutions de dépannage incluses
|
|
||||||
|
|
||||||
Versionning spécifique des images Docker
|
|
||||||
|
|
||||||
|
|
||||||
# Commentaire de Oualim
|
> Commentaire de Oualim
|
||||||
# Ce TP permet pour l'instant, de réaliser le paysage de docker pour un débutant, de comprendre une organisation de dossiers et fichiers, de créer qq containeurs docker :
|
> Ce TP permet pour l'instant, de réaliser le paysage de docker pour un débutant, de comprendre une organisation de dossiers et fichiers, de créer qq containeurs docker :
|
||||||
# - http://localhost:8000 (App)
|
> - http://localhost:8000 (App)
|
||||||
# - http://localhost:8000/docs (Documentation API)
|
> - http://localhost:8000/docs (Documentation API)
|
||||||
# - http://localhost:9090 (Prometheus)
|
> - http://localhost:9090 (Prometheus)
|
||||||
# - http://localhost:3000 (Grafana - admin/admin123)
|
> - http://localhost:3000 (Grafana - admin/admin123)
|
||||||
# - http://localhost:9000 (Portainer)
|
> - http://localhost:9000 (Portainer)
|
||||||
|
|
||||||
|
|
||||||
|
# 🚀 TP DevOps Windows - Stack Complète Locale (Corrigé & Optimisé)
|
||||||
|
|
||||||
|
## 📋 PRÉ-REQUIS WINDOWS - Installation Pas à Pas
|
||||||
|
|
||||||
|
### 🔧 1. Préparation du système (PowerShell Administrateur)
|
||||||
|
|
||||||
|
Ouvrir PowerShell en tant qu'ADMINISTRATEUR (clic droit → Exécuter en tant qu'administrateur)
|
||||||
|
|
||||||
#🚀 TP DevOps Windows - Stack Complète Locale (Corrigé & Optimisé)
|
#🚀 TP DevOps Windows - Stack Complète Locale (Corrigé & Optimisé)
|
||||||
|
|
||||||
@@ -67,24 +61,29 @@ Avant tout, bien penser à ACTIVER la fonction de VIRTUALISATION dans le BIOS du
|
|||||||
# 1. Activer les fonctionnalités Windows nécessaires
|
# 1. Activer les fonctionnalités Windows nécessaires
|
||||||
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
|
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
|
||||||
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
|
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
|
||||||
|
```
|
||||||
# 2. Installer WSL2 et Ubuntu
|
2. Installer WSL2 et Ubuntu
|
||||||
|
```
|
||||||
wsl --install -d Ubuntu-22.04
|
wsl --install -d Ubuntu-22.04
|
||||||
|
```
|
||||||
# 3. Définir WSL2 comme version par défaut
|
3. Définir WSL2 comme version par défaut
|
||||||
|
```
|
||||||
wsl --set-default-version 2
|
wsl --set-default-version 2
|
||||||
|
```
|
||||||
# 4. Redémarrer l'ordinateur (OBLIGATOIRE)
|
4. Redémarrer l'ordinateur (OBLIGATOIRE)
|
||||||
|
```
|
||||||
Restart-Computer
|
Restart-Computer
|
||||||
|
|
||||||
#📥 2. Installation des outils (après redémarrage)
|
#📥 2. Installation des outils (après redémarrage)
|
||||||
|
|
||||||
# 1. Installer Chocolatey (package manager Windows)
|
1. Installer Chocolatey (package manager Windows)
|
||||||
|
```
|
||||||
Set-ExecutionPolicy Bypass -Scope Process -Force
|
Set-ExecutionPolicy Bypass -Scope Process -Force
|
||||||
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
|
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
|
||||||
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
|
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
|
||||||
|
```
|
||||||
# 2. Installer tous les outils
|
2. Installer tous les outils
|
||||||
|
```
|
||||||
choco install -y git docker-desktop vscode kubernetes-cli minikube terraform helm postman
|
choco install -y git docker-desktop vscode kubernetes-cli minikube terraform helm postman
|
||||||
|
|
||||||
#🐧 3. Configuration WSL2 et Ubuntu
|
#🐧 3. Configuration WSL2 et Ubuntu
|
||||||
@@ -92,16 +91,20 @@ choco install -y git docker-desktop vscode kubernetes-cli minikube terraform hel
|
|||||||
# Vérifier l'installation WSL
|
# Vérifier l'installation WSL
|
||||||
wsl --list --verbose
|
wsl --list --verbose
|
||||||
# Doit afficher : Ubuntu-22.04 Running 2
|
# Doit afficher : Ubuntu-22.04 Running 2
|
||||||
|
```
|
||||||
|
|
||||||
# Entrer dans WSL pour configurer
|
Entrer dans WSL pour configurer
|
||||||
|
```
|
||||||
wsl
|
wsl
|
||||||
|
```
|
||||||
# Dans le terminal Ubuntu WSL :
|
Dans le terminal Ubuntu WSL :
|
||||||
|
```
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt upgrade -y
|
sudo apt upgrade -y
|
||||||
sudo apt install -y python3 python3-pip python3-venv nodejs npm curl wget
|
sudo apt install -y python3 python3-pip python3-venv nodejs npm curl wget
|
||||||
|
```
|
||||||
# Créer un alias pratique
|
Créer un alias pratique
|
||||||
|
```
|
||||||
echo "alias k=kubectl" >> ~/.bashrc
|
echo "alias k=kubectl" >> ~/.bashrc
|
||||||
source ~/.bashrc
|
source ~/.bashrc
|
||||||
exit # Retour à PowerShell
|
exit # Retour à PowerShell
|
||||||
@@ -113,43 +116,31 @@ exit # Retour à PowerShell
|
|||||||
Ouvrir Docker Desktop après installation
|
Ouvrir Docker Desktop après installation
|
||||||
|
|
||||||
Settings → General :
|
Settings → General :
|
||||||
|
* ✅ Use WSL 2 based engine
|
||||||
✅ Use WSL 2 based engine
|
* ✅ Expose daemon on tcp://localhost:2375 without TLS
|
||||||
|
|
||||||
✅ Expose daemon on tcp://localhost:2375 without TLS
|
|
||||||
|
|
||||||
Settings → Resources → WSL Integration :
|
Settings → Resources → WSL Integration :
|
||||||
|
* ✅ Enable integration with my default WSL distro
|
||||||
✅ Enable integration with my default WSL distro
|
* ✅ Ubuntu-22.04
|
||||||
|
|
||||||
✅ Ubuntu-22.04
|
|
||||||
|
|
||||||
Settings → Kubernetes :
|
Settings → Kubernetes :
|
||||||
|
* ✅ Enable Kubernetes
|
||||||
✅ Enable Kubernetes
|
* ✅ Deploy Docker Stacks to Kubernetes by default
|
||||||
|
|
||||||
✅ Deploy Docker Stacks to Kubernetes by default
|
|
||||||
|
|
||||||
Settings → Advanced :
|
Settings → Advanced :
|
||||||
|
* CPUs : 4 (ou 50% de vos CPUs)
|
||||||
CPUs : 4 (ou 50% de vos CPUs)
|
* Memory : 4.0 GB (ou 50% de votre RAM)
|
||||||
|
* Swap : 1.0 GB
|
||||||
Memory : 4.0 GB (ou 50% de votre RAM)
|
|
||||||
|
|
||||||
Swap : 1.0 GB
|
|
||||||
|
|
||||||
Appliquer et redémarrer Docker Desktop
|
Appliquer et redémarrer Docker Desktop
|
||||||
|
|
||||||
#✅ Vérification Docker/WSL2 :
|
### ✅ Vérification Docker/WSL2 :
|
||||||
|
```
|
||||||
# Dans PowerShell
|
# Dans PowerShell
|
||||||
docker --version
|
docker --version
|
||||||
# Doit afficher : Docker version 24.0.x
|
# Doit afficher : Docker version 24.0.x
|
||||||
|
|
||||||
docker run hello-world
|
docker run hello-world
|
||||||
# Doit afficher "Hello from Docker!"
|
# Doit afficher "Hello from Docker!"
|
||||||
|
```
|
||||||
# Vérifier l'intégration WSL2
|
Vérifier l'intégration WSL2
|
||||||
|
```
|
||||||
wsl -d Ubuntu-22.04 -e docker version
|
wsl -d Ubuntu-22.04 -e docker version
|
||||||
# Doit fonctionner sans erreur
|
# Doit fonctionner sans erreur
|
||||||
|
|
||||||
@@ -158,11 +149,14 @@ wsl -d Ubuntu-22.04 -e docker version
|
|||||||
|
|
||||||
#🗂️ Création de la structure :
|
#🗂️ Création de la structure :
|
||||||
|
|
||||||
# Créer le dossier principal
|
Créer le dossier principal
|
||||||
|
```
|
||||||
mkdir C:\DevOpsProject
|
mkdir C:\DevOpsProject
|
||||||
cd C:\DevOpsProject
|
cd C:\DevOpsProject
|
||||||
|
```
|
||||||
|
|
||||||
# Structure ORGANISÉE et LOGIQUE
|
Structure ORGANISÉE et LOGIQUE
|
||||||
|
```
|
||||||
New-Item -ItemType Directory -Path @(
|
New-Item -ItemType Directory -Path @(
|
||||||
"src\app",
|
"src\app",
|
||||||
"src\app\tests",
|
"src\app\tests",
|
||||||
@@ -176,8 +170,10 @@ New-Item -ItemType Directory -Path @(
|
|||||||
"docs",
|
"docs",
|
||||||
"config"
|
"config"
|
||||||
)
|
)
|
||||||
|
```
|
||||||
|
|
||||||
# Structure finale :
|
Structure finale :
|
||||||
|
```
|
||||||
C:\DevOpsProject\
|
C:\DevOpsProject\
|
||||||
├── src\ # Code source
|
├── src\ # Code source
|
||||||
│ ├── app\ # Application Python
|
│ ├── app\ # Application Python
|
||||||
@@ -336,8 +332,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
|
||||||
@@ -382,9 +380,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
|
||||||
@@ -425,6 +426,9 @@ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--no-access-
|
|||||||
|
|
||||||
#4.1 Fichier : docker\docker-compose.yml (RECOMMENCÉ)
|
#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:
|
||||||
@@ -591,21 +595,30 @@ scrape_configs:
|
|||||||
|
|
||||||
#4.3 Exécution Docker Compose :
|
#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
|
||||||
|
|
||||||
|
|
||||||
@@ -621,18 +634,21 @@ Invoke-WebRequest -Uri "http://localhost:8000" -UseBasicParsing
|
|||||||
|
|
||||||
#5.2 Vérification :
|
#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
|
||||||
|
|
||||||
|
#### 5.3 Fichier : kubernetes\manifests\namespace.yaml
|
||||||
|
```
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
metadata:
|
metadata:
|
||||||
@@ -643,6 +659,8 @@ metadata:
|
|||||||
|
|
||||||
#5.4 Fichier : kubernetes\manifests\configmap.yaml (NOUVEAU)
|
#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:
|
||||||
@@ -656,6 +674,8 @@ data:
|
|||||||
|
|
||||||
#5.5 Fichier : kubernetes\manifests\deployment.yaml (SIMPLIFIÉ)
|
#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:
|
||||||
Reference in New Issue
Block a user