GitOps mit Flux
Flux automatisiert Deployments aus GitLab - Infrastructure as Code mit Git als Single Source of Truth.
Prinzip
Section titled “Prinzip”graph LR
subgraph Git ["GitLab (gitlab.ciss.de/ciss/janus)"]
direction TB
AnsibleRepo["ansible/<br/>Server-Konfiguration"]
AppRepo["home/<br/>SvelteKit-App"]
FluxRepo["flux/<br/>GitOps-Konfiguration"]
end
subgraph Janus ["Janus K3s Cluster"]
FluxAgent["Flux Controller"]
Kustomize["Kustomize"]
Helm["Helm Controller"]
Workloads["Workloads"]
end
FluxRepo -->|"reconcile"| FluxAgent
AppRepo -->|"Image Updates"| FluxAgent
FluxAgent --> Kustomize
FluxAgent --> Helm
Kustomize --> Workloads
Helm --> Workloads
AnsibleRepo -.->|"Ansible"| Janus
Workflow
Section titled “Workflow”- Entwickler pusht Code nach GitLab
- GitLab CI/CD baut Container-Image
- Flux erkennt Änderung im Git-Repository
- Flux pullt neue Konfiguration und Images
- Flux aktualisiert K3s-Deployments
- Neue Pods starten automatisch
Flux läuft unter dem Service-Benutzer services mit Kubeconfig unter ~/.kube/config.
Flux-Komponenten
Section titled “Flux-Komponenten”| Komponente | Aufgabe |
|---|---|
| Source Controller | Überwacht Git-Repositories |
| Kustomize Controller | Wendet Kustomize-Overlays an |
| Helm Controller | Installiert/aktualisiert Helm-Releases |
| Notification Controller | Sendet Status-Benachrichtigungen |
Konfiguration
Section titled “Konfiguration”Flux-Konfiguration liegt im flux-Repository:
flux/├── clusters/│ └── janus/│ ├── flux-system/ # Flux-eigene Konfiguration│ └── apps/ # App-Deployments│ ├── kustomization.yaml│ ├── namespace.yaml│ └── deployment.yaml├── infrastructure/ # Infrastruktur-Deployments│ ├── ingress-nginx/│ └── cert-manager/└── apps/ # Applikationen └── home/Status prüfen
Section titled “Status prüfen”# Flux-Statusflux get sources allflux get kustomizationsflux get helmreleases
# Reconciliation erzwingenflux reconcile kustomization --with-source