GitOps Workflow¶
This homelab is managed using GitOps principles with Flux CD, ensuring all infrastructure and applications are declaratively defined and automatically deployed from Git.
Overview¶
GitOps Philosophy:
- Git is the single source of truth for all cluster configuration
- All changes flow through Git commits and pull requests
- Flux continuously reconciles cluster state with Git repository
- Manual
kubectlcommands are avoided in favor of declarative manifests
Key Components:
- Flux CD: GitOps operator managing deployments
- Helm: Package manager for applications
- Kustomize: Configuration management and patching
- 1Password Connect: Secret synchronization from vault
Repository Structure¶
k8s/
├── orchestration/ # Flux and foundational resources
│ ├── flux-system/ # Flux controllers and configuration
│ │ ├── gotk-components.yaml # Flux toolkit components
│ │ ├── gotk-sync.yaml # Git repository sync
│ │ └── flux-notifications/ # Discord webhook alerts
│ └── foundational/ # Base cluster resources
│ ├── namespaces/ # Namespace definitions
│ └── helmrepos/ # Helm repository sources
└── core/ # Application deployments
├── database/ # PostgreSQL and Redis
├── network/ # Networking components
├── observability/ # Monitoring applications
├── security/ # Authentication services
└── storage/ # Storage systems
Flux Configuration¶
GitRepository Source¶
Flux monitors this Git repository for changes and applies them to the cluster:
Key Settings:
- Repository: https://github.com/kylejschultz/kjho.me
- Branch:
main - Interval: 1 minute reconciliation
- Path:
k8s/orchestration
Kustomization Hierarchy¶
Flux applies resources in a structured hierarchy:
- Foundational: Namespaces, Helm repositories
- Core Infrastructure: Storage, networking, databases
- Applications: Security, observability, services
📋 View Orchestration Kustomization
Deployment Process¶
Standard GitOps Flow¶
- Code Changes: Modify YAML manifests or add new resources
- Commit & Push: Changes pushed to
mainbranch - Flux Sync: Flux detects changes within 1 minute
- Reconciliation: Flux applies changes to cluster
- Notifications: Discord alerts on success/failure
HelmRelease Workflow¶
Applications are deployed using HelmReleases:
- Helm Repository: Define chart source in
helmrepos/ - Namespace: Create namespace in
namespaces/ - HelmRelease: Define application configuration
- Secrets: 1Password items for sensitive values
- Dependencies: Use
dependsOnfor deployment ordering
Example HelmRelease structure:
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: app-name
namespace: app-namespace
spec:
interval: 5m
chart:
spec:
chart: chart-name
version: "1.0.0"
sourceRef:
kind: HelmRepository
name: chart-repo
values:
# Application configuration
Secrets Management¶
1Password Integration¶
Secrets are stored in 1Password vault and synchronized to Kubernetes:
OnePasswordItem Resources:
- Define secret mappings from 1Password vault
- Sync credentials, API keys, certificates
- Automatic secret rotation and updates
Secret References in HelmReleases:
Monitoring and Alerts¶
Discord Notifications¶
Flux sends deployment notifications to Discord:
- Success: Green notifications for successful deployments
- Failures: Red alerts with error details
- Reconciliation: Status updates on configuration changes
📋 View Discord Alerts Configuration
Useful Commands¶
# Check Flux system status
flux get kustomizations
# View HelmRelease status
flux get helmreleases --all-namespaces
# Force reconciliation
flux reconcile kustomization flux-system
# Check Git repository sync
flux get sources git
# View Flux logs
kubectl logs -n flux-system -l app=source-controller
# Suspend/resume reconciliation
flux suspend kustomization core-database
flux resume kustomization core-database
Best Practices¶
Development Workflow¶
For Infrastructure Changes:
- Create feature branch for testing
- Test changes in development environment
- Create pull request for review
- Merge to
mainfor automatic deployment
For Application Updates:
- Update chart version or values in HelmRelease
- Commit changes to trigger deployment
- Monitor deployment via Discord notifications
- Rollback via Git revert if needed
Configuration Management¶
- Minimal Manifests: Keep deployments simple and focused
- Individual Files: Separate each resource into its own file
- Consistent Naming: Use consistent resource naming patterns
- Documentation: Link to source files in documentation
- Dependencies: Use explicit
dependsOnrelationships
Security Considerations¶
- No Secrets in Git: All sensitive data in 1Password vault
- Least Privilege: Minimal RBAC permissions for Flux
- Network Policies: Restrict pod-to-pod communication
- Image Scanning: Use trusted container images
📁 Related Files: - Flux System Kustomization - Core Kustomization - Foundational Resources