Restructure project: Move AKS cluster to beispiel-k8s-cluster directory
Major improvements: - Import existing Azure AKS cluster with aztfexport - Optimize VM size from Standard_D4d_v4 to Standard_D2as_v6 (50% cost reduction) - Configure availability zones to [1, 2] - Add comprehensive monitoring setup: * New Log Analytics Workspace * OMS Agent integration * Data Collection Rule for Container Insights * Email alerts for CPU and Memory - Refactor configuration: * Extract all values to variables.tf * Rename resources with meaningful names * Add detailed outputs.tf - Add project documentation: * Comprehensive README.md * cluster-status-commands.md with useful Azure CLI commands * terraform.tfvars.example template * .gitignore for sensitive files Infrastructure changes: - Resource Group: trusted_ai_demo_rg (Germany West Central) - AKS Cluster: trai_k8s_cluster (Kubernetes 1.33) - Node Pool: 2-3 nodes with auto-scaling - Network: VNet 10.0.0.0/16, Subnet 10.0.0.0/24 - Monitoring: Full Container Insights with alerts Cost optimization: ~€75/month (down from ~€140/month) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4fd1f14a3b
commit
dfff276de6
18 files changed
+702
-420
No files matched your search
@@ -0,0 +1,219 @@
|
||||
# AKS Cluster Terraform Configuration
|
||||
|
||||
Dieses Projekt verwaltet einen Azure Kubernetes Service (AKS) Cluster mit vollständigem Monitoring und Alerting über Terraform.
|
||||
|
||||
## Projektübersicht
|
||||
|
||||
Der AKS Cluster wurde ursprünglich in Azure erstellt und anschließend mit `aztfexport` in Terraform importiert. Die Konfiguration wurde optimiert und um zusätzliche Monitoring-Komponenten erweitert.
|
||||
|
||||
## Infrastruktur-Komponenten
|
||||
|
||||
### Netzwerk
|
||||
- **Resource Group**: `trusted_ai_demo_rg` (Germany West Central)
|
||||
- **Virtual Network**: `trusted_ai_demo_vn` (10.0.0.0/16)
|
||||
- **Subnet**: `default` (10.0.0.0/24)
|
||||
|
||||
### AKS Cluster
|
||||
- **Name**: `trai_k8s_cluster`
|
||||
- **Kubernetes Version**: 1.33
|
||||
- **VM Size**: `Standard_D2as_v6` (2 vCPUs, 8 GB RAM)
|
||||
- **Node Count**: 2-3 (Auto-Scaling)
|
||||
- **Availability Zones**: 1, 2
|
||||
- **Features**:
|
||||
- OIDC Issuer enabled
|
||||
- Workload Identity enabled
|
||||
- Image Cleaner enabled (wöchentlich)
|
||||
- Automatische Updates (Sonntags)
|
||||
- Azure CNI Overlay Networking
|
||||
|
||||
### Monitoring & Logging
|
||||
- **Log Analytics Workspace**: `aksloganalyticstraik8scluster`
|
||||
- SKU: PerGB2018
|
||||
- Retention: 30 Tage
|
||||
- **Data Collection Rule**: Container Insights mit:
|
||||
- Container Logs V2
|
||||
- Kubernetes Events
|
||||
- Pod Inventory
|
||||
- **OMS Agent**: Automatisch auf allen Nodes deployed
|
||||
|
||||
### Alerting
|
||||
- **Action Group**: Email-Benachrichtigungen
|
||||
- **Metric Alerts**:
|
||||
- CPU Usage > 95%
|
||||
- Memory Working Set > 100%
|
||||
|
||||
## Projektstruktur
|
||||
|
||||
```
|
||||
.
|
||||
├── README.md # Diese Datei
|
||||
├── main.tf # Haupt-Ressourcendefinitionen
|
||||
├── variables.tf # Variablendefinitionen
|
||||
├── terraform.tfvars # Aktuelle Variablenwerte
|
||||
├── outputs.tf # Output-Definitionen
|
||||
├── provider.tf # Azure Provider-Konfiguration
|
||||
├── terraform.tf # Terraform-Einstellungen
|
||||
├── terraform.tfstate # State-Datei (lokal)
|
||||
├── aztfexportResourceMapping.json # Import-Mapping
|
||||
├── aztfexportSkippedResources.txt # Übersprungene Ressourcen
|
||||
└── cluster-status-commands.md # Nützliche Azure CLI Befehle
|
||||
|
||||
```
|
||||
|
||||
## Verwendung
|
||||
|
||||
### Voraussetzungen
|
||||
- Terraform >= 1.0
|
||||
- Azure CLI
|
||||
- kubectl
|
||||
- Authentifizierung bei Azure (`az login`)
|
||||
|
||||
### Initialisierung
|
||||
```bash
|
||||
terraform init
|
||||
```
|
||||
|
||||
### Änderungen anzeigen
|
||||
```bash
|
||||
terraform plan
|
||||
```
|
||||
|
||||
### Infrastruktur erstellen/aktualisieren
|
||||
```bash
|
||||
terraform apply
|
||||
```
|
||||
|
||||
### Infrastruktur löschen
|
||||
```bash
|
||||
terraform destroy
|
||||
```
|
||||
|
||||
### Cluster-Zugriff einrichten
|
||||
```bash
|
||||
az aks get-credentials --resource-group trusted_ai_demo_rg --name trai_k8s_cluster --overwrite-existing
|
||||
kubectl get nodes
|
||||
```
|
||||
|
||||
## Konfiguration
|
||||
|
||||
### Wichtige Variablen (terraform.tfvars)
|
||||
|
||||
```hcl
|
||||
location = "germanywestcentral"
|
||||
resource_group_name = "trusted_ai_demo_rg"
|
||||
aks_cluster_name = "trai_k8s_cluster"
|
||||
aks_node_vm_size = "Standard_D2as_v6"
|
||||
aks_node_zones = ["1", "2"]
|
||||
alert_email_address = "your-email@example.com"
|
||||
```
|
||||
|
||||
### Anpassbare Parameter
|
||||
|
||||
| Variable | Beschreibung | Default |
|
||||
|----------|--------------|---------|
|
||||
| `aks_node_pool_min_count` | Minimale Anzahl Nodes | 2 |
|
||||
| `aks_node_pool_max_count` | Maximale Anzahl Nodes | 3 |
|
||||
| `aks_node_vm_size` | VM-Größe für Nodes | Standard_D2as_v6 |
|
||||
| `aks_node_zones` | Availability Zones | ["1", "2"] |
|
||||
|
||||
## Outputs
|
||||
|
||||
Nach dem Apply werden folgende Informationen ausgegeben:
|
||||
|
||||
```bash
|
||||
terraform output
|
||||
```
|
||||
|
||||
- `aks_cluster_fqdn` - Cluster FQDN
|
||||
- `aks_cluster_id` - Cluster Resource ID
|
||||
- `aks_oidc_issuer_url` - OIDC Issuer URL
|
||||
- `log_analytics_workspace_id` - Log Analytics Workspace ID
|
||||
- Weitere...
|
||||
|
||||
## Kostenübersicht
|
||||
|
||||
**Monatliche Kosten (geschätzt)**:
|
||||
- 2x Standard_D2as_v6 Nodes: ~€70/Monat
|
||||
- Log Analytics Workspace: ~€2-5/Monat (bei geringer Nutzung)
|
||||
- **Gesamt**: ~€75-80/Monat
|
||||
|
||||
**Kostenoptimierung**:
|
||||
- Ursprünglich Standard_D4d_v4: ~€140/Monat
|
||||
- **Ersparnis**: ~€60-65/Monat (ca. 50%)
|
||||
|
||||
## Import-Historie
|
||||
|
||||
Das Projekt wurde mit `aztfexport` erstellt:
|
||||
|
||||
```bash
|
||||
aztfexport resource-group trusted_ai_demo_rg --non-interactive --plain-ui --continue
|
||||
```
|
||||
|
||||
**Importierte Ressourcen**: 9
|
||||
- Resource Group
|
||||
- Virtual Network + Subnet
|
||||
- AKS Cluster
|
||||
- Monitor Action Group
|
||||
- 2x Metric Alerts
|
||||
- Data Collection Rule (nachträglich hinzugefügt)
|
||||
- Log Analytics Workspace (nachträglich hinzugefügt)
|
||||
|
||||
**Übersprungene Ressourcen**: 2
|
||||
- Maintenance Configurations (automatisch verwaltet)
|
||||
|
||||
## Optimierungen
|
||||
|
||||
1. **VM-Größe**: Wechsel von Standard_D4d_v4 zu Standard_D2as_v6
|
||||
- 50% Kostenreduktion
|
||||
- Moderne AMD EPYC v6 Prozessoren
|
||||
- Ausreichend für die meisten Workloads
|
||||
|
||||
2. **Availability Zones**: Reduziert auf Zonen 1 und 2
|
||||
- Zone 3 war für das Abonnement nicht verfügbar
|
||||
|
||||
3. **Monitoring**: Komplett neu aufgesetzt
|
||||
- Eigener Log Analytics Workspace (statt shared)
|
||||
- Container Insights mit modernem V2 Format
|
||||
- Strukturierte Alerting-Regeln
|
||||
|
||||
4. **Variabilisierung**: Alle Werte in variables.tf ausgelagert
|
||||
- Einfache Anpassung
|
||||
- Wiederverwendbar
|
||||
|
||||
## Nützliche Befehle
|
||||
|
||||
Siehe [cluster-status-commands.md](./cluster-status-commands.md) für eine vollständige Liste nützlicher Azure CLI und kubectl Befehle.
|
||||
|
||||
## Sicherheitshinweise
|
||||
|
||||
- `terraform.tfvars` enthält sensitive Werte (Email-Adresse) und sollte nicht in Version Control eingecheckt werden
|
||||
- `.gitignore` ist konfiguriert, um State-Dateien und sensitive Daten auszuschließen
|
||||
- Verwenden Sie Azure Key Vault oder ähnliche Lösungen für Production-Secrets
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Quota-Fehler bei Node Pool Rotation
|
||||
Wenn Sie VM-Größen ändern und einen Quota-Fehler erhalten:
|
||||
```bash
|
||||
terraform destroy
|
||||
terraform apply
|
||||
```
|
||||
|
||||
### Log Analytics Workspace existiert nicht
|
||||
Falls der Workspace gelöscht wurde, erstellt Terraform automatisch einen neuen.
|
||||
|
||||
## Weiterführende Schritte
|
||||
|
||||
- [ ] State zu Azure Blob Storage migrieren (Remote State)
|
||||
- [ ] Azure Key Vault Integration für Secrets
|
||||
- [ ] CI/CD Pipeline einrichten
|
||||
- [ ] Weitere Monitoring Dashboards erstellen
|
||||
- [ ] Backup-Strategie implementieren
|
||||
|
||||
## Kontakt
|
||||
|
||||
Für Fragen oder Probleme, siehe die GitHub Issues.
|
||||
|
||||
## Lizenz
|
||||
|
||||
Projekt für Demo-Zwecke.
|
||||
Reference in new issue
Block a user