Environment Management with ArgoCD¶
This document explains how multiple environments are managed in this ArgoCD project using GitOps principles.
Environment Structure¶
The project uses a directory-based approach to manage different environments:
environments/
├── dev/ # Development environment
│ ├── apps/ # Kubernetes manifest applications
│ │ ├── app1/
│ │ └── app2/
│ └── helm/ # Helm chart applications
│ └── myargoapp-chart/
└── README.md # Environment documentation
This structure allows for: - Clear separation between environments - Environment-specific configurations - Consistent application structure across environments - Easy addition of new environments (staging, production, etc.)
Environment Configuration¶
Development Environment¶
The development environment (dev/
) is configured for:
- Local development using Kind
- Rapid iteration and testing
- Minimal resource requirements
- Debug-friendly settings
- Automated synchronization
Adding New Environments¶
To add new environments (e.g., staging, production):
-
Create a new directory under
environments/
: -
Copy and modify the base configurations:
-
Update environment-specific values:
- Resource limits and requests
- Replica counts
- Configuration parameters
-
External service endpoints
-
Create environment-specific ArgoCD Applications:
apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: myapp-staging namespace: argocd spec: project: default source: repoURL: https://github.com/sean-njela/argocd-demo.git targetRevision: HEAD path: environments/staging/apps/app1 destination: server: https://kubernetes.default.svc namespace: myapp-staging syncPolicy: automated: prune: true selfHeal: true syncOptions: - CreateNamespace=true
Environment Isolation¶
Each environment is isolated through:
- Namespace Separation: Each environment uses dedicated namespaces
- Configuration Separation: Environment-specific configurations
- Resource Quotas: Limits on CPU, memory, and other resources
- Network Policies: Controlled network access between environments
- RBAC: Role-based access control for different environments
Environment-Specific Values¶
Helm Values¶
For Helm-based applications, environment-specific values are managed through values files:
# environments/dev/helm/myargoapp-chart/values.yaml
replicaCount: 1
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 50m
memory: 64Mi
# environments/staging/helm/myargoapp-chart/values.yaml
replicaCount: 2
resources:
limits:
cpu: 200m
memory: 256Mi
requests:
cpu: 100m
memory: 128Mi
Kustomize Overlays¶
For applications using Kustomize, environment-specific configurations are managed through overlays:
apps/myapp/
├── base/
│ ├── deployment.yaml
│ ├── service.yaml
│ └── kustomization.yaml
├── overlays/
│ ├── dev/
│ │ ├── kustomization.yaml
│ │ └── patch.yaml
│ └── staging/
│ ├── kustomization.yaml
│ └── patch.yaml
Promotion Between Environments¶
The project supports promoting applications between environments:
- Testing in Development: Applications are first deployed to the development environment
- Validation: Automated and manual testing verifies the application
- Promotion: Changes are merged to the staging branch
- Staging Deployment: ArgoCD automatically deploys to staging
- Production Approval: Changes are approved for production
- Production Deployment: ArgoCD deploys to production
Environment-Specific Sync Policies¶
Different environments can have different sync policies:
-
Development: Automated sync with self-healing
-
Staging: Automated sync with manual approval
-
Production: Manual sync with sync windows
Environment Variables and Secrets¶
Environment-specific secrets and variables are managed through:
- Kubernetes Secrets: For sensitive information
- ConfigMaps: For non-sensitive configuration
- External Secret Management: Integration with tools like HashiCorp Vault (in production)
Best Practices¶
- Consistent Structure: Maintain the same structure across environments
- Minimal Differences: Keep environment-specific changes to a minimum
- Documentation: Document the purpose and configuration of each environment
- Testing: Test changes in lower environments before promotion
- Access Control: Implement appropriate access controls for each environment
- Monitoring: Set up environment-specific monitoring and alerts
- Disaster Recovery: Implement backup and recovery procedures for each environment