Modification des fichiers nginx et argo en .yaml pour k8' selon best practice en prod + écriture de 2 scripts vérifés et fonctionnels pour configurer le dashbord de k8' et argoced et les ouvrir dans une page web
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
# Activer le proxy
|
||||
# Installer le dashboard Kubernetes s'il n'existe pas
|
||||
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml 2>$null
|
||||
|
||||
# Démarrer le proxy Kubernetes
|
||||
Start-Process kubectl -ArgumentList "proxy" -WindowStyle Hidden
|
||||
|
||||
# Créer le ServiceAccount
|
||||
kubectl create serviceaccount dashboard-admin -n kubernetes-dashboard --force
|
||||
# Attendre que le proxy soit prêt
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
# Lui donner les droits admin
|
||||
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:dashboard-admin --force
|
||||
# Créer le ServiceAccount (pas de --force, gestion propre)
|
||||
if ($(kubectl get serviceaccount dashboard-admin -n kubernetes-dashboard -o name) -eq $null) {
|
||||
kubectl create serviceaccount dashboard-admin -n kubernetes-dashboard
|
||||
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:dashboard-admin
|
||||
}
|
||||
|
||||
# Générer le jeton
|
||||
$Token = kubectl create token dashboard-admin -n kubernetes-dashboard
|
||||
@@ -15,7 +21,7 @@ $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)
|
||||
# Générer le kubeconfig
|
||||
$Kubeconfig = @"
|
||||
apiVersion: v1
|
||||
kind: Config
|
||||
@@ -40,5 +46,10 @@ users:
|
||||
$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."
|
||||
|
||||
# Ouvrir le navigateur
|
||||
$Url = "http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/"
|
||||
Start-Process $Url
|
||||
|
||||
Write-Host "🌐 Dashboard ouvert dans le navigateur."
|
||||
Write-Host "→ Choisissez 'Kubeconfig' et sélectionnez le fichier généré."
|
||||
@@ -3,7 +3,7 @@ kind: Config
|
||||
clusters:
|
||||
- name: docker-desktop
|
||||
cluster:
|
||||
server: https://kubernetes.docker.internal:6443
|
||||
server: https://127.0.0.1:53514
|
||||
certificate-authority-data: DATA+OMITTED
|
||||
contexts:
|
||||
- name: docker-desktop
|
||||
@@ -14,4 +14,4 @@ current-context: docker-desktop
|
||||
users:
|
||||
- name: dashboard-admin
|
||||
user:
|
||||
token: eyJhbGciOiJSUzI1NiIsImtpZCI6Ikt1VTA5b0ZjYXNUS050T1ZkVFRhTVlIRXBzLU9MMEdnaWZqdDZjSTRLRDAifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwiXSwiZXhwIjoxNzY5MTAxMDkxLCJpYXQiOjE3NjkwOTc0OTEsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwianRpIjoiZmY1MTZiZmQtNTE2Mi00ZjFlLWFjNzEtMTg5ODQ5Yzg1Y2E0Iiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsInNlcnZp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QiOiJmYmMyOTIxOS00NjI4LTQ1M2EtOGY5Ny02Y2UxZWMwZTZlZjEifX0sIm5iZiI6MTc3MDAzNzU0MSwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmVybmV0ZXMtZGFzaGJvYXJkOmRhc2hib2FyZC1hZG1pbiJ9.gz0Roz8B4zz1HJ2YuDhhPGa6LD6Co9jm38tCXyIqwQl2imFbvSJwn8yf3YYXINfp_k09gJBVH4cUSif8DhgR-9k587N6OOWYrt5XjIlggssd9QC8v3NZv6yLaIoUV2PMFDgyDX33pGGHr_6VCSC7yoRxbyahTLnLVjA9XurvR66EA9IDje6xSpJ3iB5YqFqGYsy6Q4gcVhYQtXr6Q_UZoiiBeYQH-C66-N5RheGIxJuIQMpfIm_5644ZH8ddz3g3uLkmwCI15TSNGRL0NOSUploCytxXuiqqZSrJDeq4yyTMDhYUtK4_sUOpZFT26gzWuEPSQCq77zUXJdA9-7dbxA
|
||||
|
||||
49
scripts/start-argocd.ps1
Normal file
49
scripts/start-argocd.ps1
Normal file
@@ -0,0 +1,49 @@
|
||||
# === 1. Appliquer le namespace principal d'abord ===
|
||||
Write-Host "🚀 Création du namespace devops-demo..."
|
||||
kubectl apply -f C:\DevOpsProject\kubernetes\manifests\namespace.yaml
|
||||
|
||||
# Attendre que le namespace soit actif
|
||||
Write-Host "⏳ Attente que le namespace devops-demo soit prêt..."
|
||||
kubectl wait --for=condition=Active namespace/devops-demo --timeout=60s
|
||||
|
||||
# === 2. Appliquer les ConfigMap et Secret (préalables à nginx) ===
|
||||
Write-Host "📦 Création du ConfigMap et Secret pour Nginx..."
|
||||
kubectl apply -f C:\DevOpsProject\kubernetes\manifests\configmap.yaml
|
||||
kubectl create secret generic nginx-tls --from-file=C:\DevOpsProject\config\certs -n devops-demo --dry-run=client -o yaml | kubectl apply -f -
|
||||
|
||||
# === 3. Appliquer tous les autres manifests (y compris nginx-proxy.yaml) ===
|
||||
Write-Host "🔄 Application des déploiements (app, db, nginx-proxy)..."
|
||||
kubectl apply -f C:\DevOpsProject\kubernetes\manifests
|
||||
|
||||
# === 4. Attendre que nginx-proxy soit prêt (dépendance critique) ===
|
||||
Write-Host "⏳ Attente que nginx-proxy soit en état Ready..."
|
||||
kubectl wait --for=condition=ready pod -l app=nginx-proxy -n devops-demo --timeout=120s
|
||||
|
||||
# === 5. Installer ArgoCD si ce n'est pas déjà fait ===
|
||||
if ($(kubectl get namespace argocd -o name) -eq $null) {
|
||||
Write-Host "🎯 Installation d'ArgoCD..."
|
||||
kubectl create namespace argocd
|
||||
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
|
||||
}
|
||||
|
||||
# Attendre que ArgoCD soit disponible
|
||||
Write-Host "⏳ Attente du déploiement d'ArgoCD..."
|
||||
kubectl wait --for=condition=available --timeout=180s -n argocd deployment/argocd-server
|
||||
|
||||
# === 6. Récupérer le mot de passe admin ===
|
||||
$Password = kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | ForEach-Object { [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($_)) }
|
||||
|
||||
# === 7. Lancer le port-forward pour ArgoCD ===
|
||||
Start-Process kubectl -ArgumentList "port-forward svc/argocd-server -n argocd 8080:443" -WindowStyle Hidden
|
||||
|
||||
# === 8. Ouvrir l'interface ArgoCD dans le navigateur ===
|
||||
Start-Sleep -Seconds 5
|
||||
$Url = "https://localhost:8080"
|
||||
Start-Process $Url
|
||||
|
||||
# === Résumé final ===
|
||||
Write-Host "✅ Restauration terminée !"
|
||||
Write-Host "🌐 Accès ArgoCD : $Url"
|
||||
Write-Host "👤 Utilisateur : admin"
|
||||
Write-Host "🔑 Mot de passe : $Password"
|
||||
Write-Host "💡 Acceptez le certificat auto-signé dans le navigateur."
|
||||
Reference in New Issue
Block a user