# Deployment Automation Guide **Date**: 2025-01-27 **Purpose**: Guide for automating deployments across projects **Status**: Complete --- ## Overview This guide provides strategies and tools for automating deployments across the integrated workspace. --- ## Deployment Strategies ### 1. Blue-Green Deployment **Strategy**: Deploy new version alongside old, switch traffic **Benefits**: - Zero downtime - Easy rollback - Safe testing **Implementation**: ```bash # Deploy green environment kubectl apply -f deployment-green.yaml # Test green environment curl https://green.example.com/health # Switch traffic kubectl patch service app -p '{"spec":{"selector":{"version":"green"}}}' # Keep blue for rollback ``` ### 2. Canary Deployment **Strategy**: Gradual rollout to subset of users **Benefits**: - Risk mitigation - Gradual validation - Easy rollback **Implementation**: ```yaml # Deploy canary (10% traffic) apiVersion: v1 kind: Service metadata: name: app spec: selector: app: app version: canary ports: - port: 80 ``` ### 3. Rolling Deployment **Strategy**: Incremental replacement of instances **Benefits**: - No downtime - Resource efficient - Standard Kubernetes **Implementation**: ```yaml spec: replicas: 3 strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0 ``` --- ## GitOps Workflows ### ArgoCD **Setup**: ```bash # Install ArgoCD kubectl create namespace argocd kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml ``` **Application**: ```yaml apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: dbis-core spec: project: default source: repoURL: https://github.com/org/repo path: dbis_core/k8s targetRevision: main destination: server: https://kubernetes.default.svc namespace: dbis-core syncPolicy: automated: prune: true selfHeal: true ``` ### Flux **Setup**: ```bash # Install Flux flux install # Create GitRepository flux create source git dbis-core \ --url=https://github.com/org/repo \ --branch=main # Create Kustomization flux create kustomization dbis-core \ --source=dbis-core \ --path="./dbis_core/k8s" \ --prune=true ``` --- ## CI/CD Integration ### GitHub Actions ```yaml name: Deploy on: push: branches: [main] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Build run: pnpm build - name: Deploy to Kubernetes run: | kubectl set image deployment/app \ app=registry.example.com/app:${{ github.sha }} ``` ### GitLab CI/CD ```yaml deploy: stage: deploy script: - kubectl set image deployment/app \ app=registry.gitlab.com/group/project:$CI_COMMIT_SHA only: - main ``` --- ## Infrastructure as Code ### Terraform Deployment ```bash # Plan terraform plan -out=tfplan # Apply terraform apply tfplan # Destroy (if needed) terraform destroy ``` ### Ansible Deployment ```yaml - name: Deploy application hosts: app_servers tasks: - name: Pull latest image docker_container: name: app image: registry.example.com/app:latest state: started ``` --- ## Monitoring Deployments ### Health Checks ```yaml livenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 30 periodSeconds: 10 readinessProbe: httpGet: path: /ready port: 8080 initialDelaySeconds: 5 periodSeconds: 5 ``` ### Deployment Status ```bash # Check deployment status kubectl rollout status deployment/app # View deployment history kubectl rollout history deployment/app # Rollback if needed kubectl rollout undo deployment/app ``` --- ## Best Practices ### Pre-Deployment - Run all tests - Security scanning - Dependency audit - Documentation update ### During Deployment - Monitor metrics - Check logs - Verify health - Test functionality ### Post-Deployment - Monitor for issues - Verify metrics - Check alerts - Update status page --- **Last Updated**: 2025-01-27