init
This commit is contained in:
44
scripts/GenerKubConf.ps1
Normal file
44
scripts/GenerKubConf.ps1
Normal file
@@ -0,0 +1,44 @@
|
||||
# Activer le proxy
|
||||
Start-Process kubectl -ArgumentList "proxy" -WindowStyle Hidden
|
||||
|
||||
# Créer le ServiceAccount
|
||||
kubectl create serviceaccount dashboard-admin -n kubernetes-dashboard --force
|
||||
|
||||
# Lui donner les droits admin
|
||||
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:dashboard-admin --force
|
||||
|
||||
# Générer le jeton
|
||||
$Token = kubectl create token dashboard-admin -n kubernetes-dashboard
|
||||
|
||||
# Informations du cluster
|
||||
$ClusterName = kubectl config current-context
|
||||
$Server = kubectl config view -o jsonpath="{.clusters[?(@.name==`"$ClusterName`")].cluster.server}"
|
||||
$CACert = kubectl config view -o jsonpath="{.clusters[?(@.name==`"$ClusterName`")].cluster.certificate-authority-data}"
|
||||
|
||||
# Générer le kubeconfig avec token uniquement (pas de certificats)
|
||||
$Kubeconfig = @"
|
||||
apiVersion: v1
|
||||
kind: Config
|
||||
clusters:
|
||||
- name: $ClusterName
|
||||
cluster:
|
||||
server: $Server
|
||||
certificate-authority-data: $CACert
|
||||
contexts:
|
||||
- name: $ClusterName
|
||||
context:
|
||||
cluster: $ClusterName
|
||||
user: dashboard-admin
|
||||
current-context: $ClusterName
|
||||
users:
|
||||
- name: dashboard-admin
|
||||
user:
|
||||
token: $Token
|
||||
"@
|
||||
|
||||
# Sauvegarder
|
||||
$Kubeconfig | Out-File -FilePath "C:\DevOpsProject\scripts\dashboard.kubeconfig" -Encoding UTF8
|
||||
|
||||
Write-Host "✅ kubeconfig généré : C:\DevOpsProject\scripts\dashboard.kubeconfig"
|
||||
Write-Host "Accédez au dashboard : http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/"
|
||||
Write-Host "→ Choisissez 'Kubeconfig' et sélectionnez le fichier."
|
||||
83
scripts/cleanup.ps1
Normal file
83
scripts/cleanup.ps1
Normal file
@@ -0,0 +1,83 @@
|
||||
# Nettoyage complet DevOps Stack
|
||||
Write-Host "🧹 NETTOYAGE DEVOPS STACK" -ForegroundColor Yellow
|
||||
Write-Host "==========================" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
|
||||
# 1. Arrêter Docker Compose
|
||||
Write-Host "[1/4] Arrêt Docker Compose..." -ForegroundColor Yellow
|
||||
try {
|
||||
if (Test-Path "..\docker\docker-compose.yml") {
|
||||
Set-Location "..\docker"
|
||||
docker-compose down -v # -v pour supprimer les volumes
|
||||
Write-Host " ✅ Docker Compose arrêté" -ForegroundColor Green
|
||||
Set-Location $PSScriptRoot
|
||||
}
|
||||
} catch {
|
||||
Write-Host " ⚠️ Aucun service Docker Compose en cours" -ForegroundColor Gray
|
||||
}
|
||||
|
||||
# 2. Nettoyer Kubernetes
|
||||
Write-Host "[2/4] Nettoyage Kubernetes..." -ForegroundColor Yellow
|
||||
try {
|
||||
# Supprimer le namespace (supprime tout à l'intérieur)
|
||||
kubectl delete namespace devops-demo --ignore-not-found=true
|
||||
kubectl delete namespace terraform-ns --ignore-not-found=true
|
||||
|
||||
# Désinstaller Helm
|
||||
helm uninstall devops-release --namespace devops-demo --ignore-not-found=true
|
||||
|
||||
Write-Host " ✅ Kubernetes nettoyé" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host " ⚠️ Kubernetes non configuré ou déjà nettoyé" -ForegroundColor Gray
|
||||
}
|
||||
|
||||
# 3. Nettoyer Docker
|
||||
Write-Host "[3/4] Nettoyage Docker..." -ForegroundColor Yellow
|
||||
try {
|
||||
# Arrêter tous les conteneurs
|
||||
docker stop $(docker ps -aq) 2>$null
|
||||
|
||||
# Supprimer tous les conteneurs
|
||||
docker rm $(docker ps -aq) 2>$null
|
||||
|
||||
# Supprimer toutes les images
|
||||
docker rmi $(docker images -q) -f 2>$null
|
||||
|
||||
# Nettoyer le système
|
||||
docker system prune -a -f --volumes
|
||||
|
||||
Write-Host " ✅ Docker nettoyé" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host " ℹ️ Aucune ressource Docker à nettoyer" -ForegroundColor Gray
|
||||
}
|
||||
|
||||
# 4. Nettoyer Terraform
|
||||
Write-Host "[4/4] Nettoyage Terraform..." -ForegroundColor Yellow
|
||||
try {
|
||||
if (Test-Path "..\terraform") {
|
||||
Set-Location "..\terraform"
|
||||
|
||||
# Détruire l'infrastructure si terraform.tfstate existe
|
||||
if (Test-Path "terraform.tfstate") {
|
||||
terraform destroy -auto-approve 2>$null
|
||||
}
|
||||
|
||||
# Supprimer les fichiers temporaires
|
||||
Remove-Item -Path "*.tfstate*", ".terraform*", "terraform.tfstate.backup" -Force -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Host " ✅ Terraform nettoyé" -ForegroundColor Green
|
||||
Set-Location $PSScriptRoot
|
||||
}
|
||||
} catch {
|
||||
Write-Host " ℹ️ Terraform non configuré" -ForegroundColor Gray
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host " NETTOYAGE TERMINÉ !" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "✅ Toutes les ressources ont été nettoyées" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Pour recommencer :" -ForegroundColor Cyan
|
||||
Write-Host " .\setup.ps1" -ForegroundColor Gray
|
||||
17
scripts/dashboard.kubeconfig
Normal file
17
scripts/dashboard.kubeconfig
Normal file
@@ -0,0 +1,17 @@
|
||||
apiVersion: v1
|
||||
kind: Config
|
||||
clusters:
|
||||
- name: docker-desktop
|
||||
cluster:
|
||||
server: https://kubernetes.docker.internal:6443
|
||||
certificate-authority-data: DATA+OMITTED
|
||||
contexts:
|
||||
- name: docker-desktop
|
||||
context:
|
||||
cluster: docker-desktop
|
||||
user: dashboard-admin
|
||||
current-context: docker-desktop
|
||||
users:
|
||||
- name: d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ps1
Normal file
@@ -0,0 +1,181 @@
|
||||
# DevOps Windows Setup Script
|
||||
# PowerShell 5.1+ requis
|
||||
|
||||
param(
|
||||
[switch]$SkipDocker = $false,
|
||||
[switch]$SkipK8s = $false,
|
||||
[switch]$Help = $false
|
||||
)
|
||||
|
||||
if ($Help) {
|
||||
Write-Host "Usage: .\setup.ps1 [-SkipDocker] [-SkipK8s] [-Help]" -ForegroundColor Cyan
|
||||
Write-Host " -SkipDocker : Ne pas démarrer Docker Compose" -ForegroundColor Gray
|
||||
Write-Host " -SkipK8s : Ne pas déployer sur Kubernetes" -ForegroundColor Gray
|
||||
Write-Host " -Help : Afficher cette aide" -ForegroundColor Gray
|
||||
exit 0
|
||||
}
|
||||
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host " DEVOPS WINDOWS SETUP" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
# 1. Vérification des outils
|
||||
Write-Host "[1/5] Vérification des outils..." -ForegroundColor Yellow
|
||||
|
||||
$tools = @(
|
||||
@{Name="Docker"; Cmd="docker --version"},
|
||||
@{Name="kubectl"; Cmd="kubectl version --client"},
|
||||
@{Name="helm"; Cmd="helm version"},
|
||||
@{Name="python"; Cmd="python --version"}
|
||||
)
|
||||
|
||||
foreach ($tool in $tools) {
|
||||
try {
|
||||
$output = Invoke-Expression $tool.Cmd 2>&1
|
||||
Write-Host " ✅ $($tool.Name) : OK" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host " ❌ $($tool.Name) : MANQUANT" -ForegroundColor Red
|
||||
Write-Host " Installez avec: choco install $($tool.Name.ToLower())" -ForegroundColor Gray
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
|
||||
# 2. Build de l'application
|
||||
Write-Host "[2/5] Build de l'application Docker..." -ForegroundColor Yellow
|
||||
try {
|
||||
Set-Location "$PSScriptRoot\..\src\app"
|
||||
docker build -t devops-app:local .
|
||||
Write-Host " ✅ Image Docker construite" -ForegroundColor Green
|
||||
Set-Location $PSScriptRoot
|
||||
} catch {
|
||||
Write-Host " ❌ Erreur lors du build Docker" -ForegroundColor Red
|
||||
Write-Host $_.Exception.Message
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 3. Docker Compose
|
||||
if (-not $SkipDocker) {
|
||||
Write-Host "[3/5] Démarrage Docker Compose..." -ForegroundColor Yellow
|
||||
try {
|
||||
Set-Location "$PSScriptRoot\..\docker"
|
||||
|
||||
# Arrêter si déjà en cours
|
||||
docker-compose down 2>$null
|
||||
|
||||
# Démarrer
|
||||
docker-compose up -d
|
||||
|
||||
# Attendre que les services soient prêts
|
||||
Start-Sleep -Seconds 10
|
||||
|
||||
Write-Host " ✅ Docker Compose démarré" -ForegroundColor Green
|
||||
Write-Host " Attente supplémentaire pour les services..." -ForegroundColor Gray
|
||||
|
||||
# Vérifier l'application
|
||||
$attempts = 0
|
||||
$maxAttempts = 6
|
||||
while ($attempts -lt $maxAttempts) {
|
||||
try {
|
||||
$response = Invoke-WebRequest -Uri "http://localhost:8000/health" -UseBasicParsing -TimeoutSec 5
|
||||
if ($response.StatusCode -eq 200) {
|
||||
Write-Host " ✅ Application accessible" -ForegroundColor Green
|
||||
break
|
||||
}
|
||||
} catch {
|
||||
$attempts++
|
||||
Write-Host " ⏳ Tentative $attempts/$maxAttempts..." -ForegroundColor Yellow
|
||||
Start-Sleep -Seconds 10
|
||||
|
||||
if ($attempts -eq $maxAttempts) {
|
||||
Write-Host " ⚠️ Application lente à démarrer" -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Set-Location $PSScriptRoot
|
||||
} catch {
|
||||
Write-Host " ⚠️ Erreur Docker Compose : $($_.Exception.Message)" -ForegroundColor Yellow
|
||||
Set-Location $PSScriptRoot
|
||||
}
|
||||
}
|
||||
|
||||
# 4. Kubernetes
|
||||
if (-not $SkipK8s) {
|
||||
Write-Host "[4/5] Déploiement Kubernetes..." -ForegroundColor Yellow
|
||||
try {
|
||||
Set-Location "$PSScriptRoot\..\kubernetes\manifests"
|
||||
|
||||
# Vérifier que Kubernetes est activé
|
||||
$k8sContext = kubectl config current-context 2>$null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host " ℹ️ Kubernetes non configuré, passage au mode Docker uniquement" -ForegroundColor Yellow
|
||||
} else {
|
||||
# Appliquer les manifests
|
||||
kubectl apply -f namespace.yaml
|
||||
kubectl apply -f configmap.yaml
|
||||
kubectl apply -f deployment.yaml
|
||||
|
||||
Write-Host " ✅ Déploiement Kubernetes terminé" -ForegroundColor Green
|
||||
|
||||
# Obtenir les infos
|
||||
$service = kubectl get svc -n devops-demo devops-app-service -o json | ConvertFrom-Json
|
||||
$nodePort = $service.spec.ports[0].nodePort
|
||||
Write-Host " Accès K8s : http://localhost:$nodePort" -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
Set-Location $PSScriptRoot
|
||||
} catch {
|
||||
Write-Host " ⚠️ Erreur Kubernetes : $($_.Exception.Message)" -ForegroundColor Yellow
|
||||
Set-Location $PSScriptRoot
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "[5/5] Récapitulatif..." -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host " SETUP TERMINÉ !" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "🌐 ACCèS AUX SERVICES :" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host " 📊 Application FastAPI :" -ForegroundColor Cyan
|
||||
Write-Host " • Interface : http://localhost:8000" -ForegroundColor Gray
|
||||
Write-Host " • Health : http://localhost:8000/health" -ForegroundColor Gray
|
||||
Write-Host " • Docs : http://localhost:8000/docs" -ForegroundColor Gray
|
||||
Write-Host " • Métriques : http://localhost:8000/metrics" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host " 📈 Monitoring :" -ForegroundColor Cyan
|
||||
Write-Host " • Prometheus : http://localhost:9090" -ForegroundColor Gray
|
||||
Write-Host " • Grafana : http://localhost:3000" -ForegroundColor Gray
|
||||
Write-Host " Login : admin / admin123" -ForegroundColor DarkGray
|
||||
Write-Host ""
|
||||
Write-Host " 🐳 Gestion Docker :" -ForegroundColor Cyan
|
||||
Write-Host " • Portainer : http://localhost:9000" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
if (-not $SkipK8s) {
|
||||
Write-Host " ☸️ Kubernetes :" -ForegroundColor Cyan
|
||||
Write-Host " • Vérifier : kubectl get pods -n devops-demo" -ForegroundColor Gray
|
||||
Write-Host " • Logs : kubectl logs -f -n devops-demo -l app=devops-app" -ForegroundColor Gray
|
||||
}
|
||||
Write-Host ""
|
||||
Write-Host "🔧 COMMANDES UTILES :" -ForegroundColor White
|
||||
Write-Host " * Voir les logs : docker-compose logs -f [app|prometheus|grafana]" -ForegroundColor DarkGray
|
||||
Write-Host " * Arrêter tout : docker-compose down" -ForegroundColor DarkGray
|
||||
Write-Host " * Nettoyer : docker system prune -a -f --volumes" -ForegroundColor DarkGray
|
||||
Write-Host ""
|
||||
Write-Host "💡 CONSEIL :" -ForegroundColor Yellow
|
||||
Write-Host " Testez avec : curl http://localhost:8000 ou dans PowerShell :" -ForegroundColor Gray
|
||||
Write-Host " Invoke-WebRequest -Uri 'http://localhost:8000' -UseBasicParsing" -ForegroundColor DarkGray
|
||||
Write-Host ""
|
||||
|
||||
# Test automatique
|
||||
try {
|
||||
$test = Invoke-WebRequest -Uri "http://localhost:8000/health" -UseBasicParsing -TimeoutSec 5
|
||||
if ($test.StatusCode -eq 200) {
|
||||
Write-Host "✅ Test de santé réussi !" -ForegroundColor Green
|
||||
}
|
||||
} catch {
|
||||
Write-Host "⚠️ L'application n'est pas encore accessible, patientez..." -ForegroundColor Yellow
|
||||
}
|
||||
20
scripts/start_other_ctnrs.ps1
Normal file
20
scripts/start_other_ctnrs.ps1
Normal file
@@ -0,0 +1,20 @@
|
||||
# Définit le chemin vers le dossier contenant tous tes fichiers docker-compose.yml
|
||||
$projectPath = "C:\DevOpsProject\docker"
|
||||
|
||||
# La liste de tous tes fichiers docker-compose YAML à lancer
|
||||
$composeFiles = @(
|
||||
"docker-compose-db.yml",
|
||||
"docker-compose-elk.yml",
|
||||
"docker-compose-gitea.yml",
|
||||
"docker-compose-nginx.yml"
|
||||
)
|
||||
|
||||
# Pour chaque fichier dans la liste
|
||||
foreach ($file in $composeFiles) {
|
||||
# Lance une nouvelle instance de 'docker-compose' pour ce fichier, en mode détaché (-d)
|
||||
# Start-Process permet de lancer la commande en arrière-plan, sans bloquer le script
|
||||
Start-Process -NoNewWindow -FilePath "docker-compose" -ArgumentList "-f `"$projectPath\$file`" up -d"
|
||||
}
|
||||
|
||||
# Affiche un message une fois tous les containers lancés
|
||||
Write-Host "Tous les environnements ont été lancés."
|
||||
Reference in New Issue
Block a user