Multi-Environment Deployments with ArgoCD
/ 3 min read
Series Navigation
- Part 1: Introduction to ArgoCD
- Part 2: Managing Applications with ArgoCD
- Part 3: Multi-Cluster Management with ArgoCD
- Part 4: Advanced ArgoCD Patterns
- Part 5: Real-World ArgoCD Case Studies
- Part 6: Multi-Environment Deployments (Current)
- Part 7: Environment-Specific Configurations
- Part 8: Comparing Deployment Approaches
Multi-Environment Deployments with ArgoCD
In this sixth part of our ArgoCD series, we’ll explore strategies for managing deployments across multiple environments.
Environment Management Strategies
1. Directory-Based Structure
├── environments/│ ├── dev/│ │ ├── kustomization.yaml│ │ └── values.yaml│ ├── staging/│ │ ├── kustomization.yaml│ │ └── values.yaml│ └── prod/│ ├── kustomization.yaml│ └── values.yaml└── base/ ├── deployment.yaml ├── service.yaml └── kustomization.yaml2. Branch-Based Strategy
apiVersion: argoproj.io/v1alpha1kind: Applicationmetadata: name: myapp-devspec: source: repoURL: https://github.com/org/myapp.git targetRevision: dev path: k8s destination: server: https://dev-cluster:6443 namespace: myapp-devUsing Kustomize for Environment Management
Base Configuration
apiVersion: kustomize.config.k8s.io/v1beta1kind: Kustomizationresources: - deployment.yaml - service.yaml - configmap.yamlEnvironment Overlay
apiVersion: kustomize.config.k8s.io/v1beta1kind: Kustomizationbases: - ../../basenamePrefix: dev-namespace: devpatchesStrategicMerge: - replica-count.yaml - resource-limits.yamlconfigMapGenerator: - name: app-config behavior: merge literals: - ENV=developmentUsing Helm for Environment Management
Values File Structure
environment: developmentreplicaCount: 2resources: limits: cpu: 500m memory: 512Mi requests: cpu: 250m memory: 256MiArgoCD Application with Helm
apiVersion: argoproj.io/v1alpha1kind: Applicationmetadata: name: myapp-devspec: source: repoURL: https://github.com/org/myapp.git path: helm helm: valueFiles: - values-dev.yaml destination: server: https://dev-cluster:6443 namespace: myapp-devApplicationSet for Multiple Environments
Using Matrix Generator
apiVersion: argoproj.io/v1alpha1kind: ApplicationSetmetadata: name: myapp-environmentsspec: generators: - matrix: generators: - list: elements: - env: dev cluster: dev-cluster namespace: dev - env: staging cluster: staging-cluster namespace: staging - env: prod cluster: prod-cluster namespace: prod - list: elements: - component: frontend path: frontend - component: backend path: backend template: metadata: name: '{{component}}-{{env}}' spec: project: default source: repoURL: https://github.com/org/myapp.git targetRevision: HEAD path: '{{path}}/environments/{{env}}' destination: server: 'https://{{cluster}}:6443' namespace: '{{namespace}}' syncPolicy: automated: prune: true selfHeal: trueEnvironment-Specific Configurations
Config Maps
apiVersion: v1kind: ConfigMapmetadata: name: app-configdata: DATABASE_URL: "postgres://dev-db:5432/myapp" CACHE_URL: "redis://dev-redis:6379" LOG_LEVEL: "debug"Secrets Management
apiVersion: external-secrets.io/v1beta1kind: ExternalSecretmetadata: name: app-secretsspec: refreshInterval: 1h secretStoreRef: name: vault-backend kind: ClusterSecretStore target: name: app-secrets data: - secretKey: API_KEY remoteRef: key: myapp/{{.Env}}/api-keyDeployment Strategies
Progressive Delivery
apiVersion: argoproj.io/v1alpha1kind: Rolloutmetadata: name: myappspec: strategy: canary: steps: - setWeight: 20 - pause: {duration: 1h} - setWeight: 40 - pause: {duration: 1h} - setWeight: 60 - pause: {duration: 1h} - setWeight: 80 - pause: {duration: 1h}Best Practices
-
Environment Parity
- Keep configurations as similar as possible
- Use the same deployment process
- Automate environment creation
-
Configuration Management
- Use environment variables
- Externalize configurations
- Version control all changes
-
Security
- Implement RBAC per environment
- Use different secrets per environment
- Audit all changes
-
Monitoring
- Set up monitoring per environment
- Configure appropriate alerting
- Track deployment success rates
Conclusion
Effective multi-environment management with ArgoCD requires:
- Clear environment separation
- Consistent deployment processes
- Environment-specific configurations
- Robust security measures
In the next part, we’ll dive deeper into environment-specific configurations and advanced deployment patterns.