Back to All Engineering Insights
DevOps & SRE

Zero-Downtime Blue/Green Deployments with Kubernetes and Terraform on AWS

Zero-Downtime Blue/Green Deployments with Kubernetes and Terraform on AWS
Table of Contents

1. The Zero-Downtime Imperative

In high-throughput enterprise SaaS environments, rolling deployments can inadvertently introduce brief dropped TCP connections, in-flight transaction terminations, and transient 502 Bad Gateway errors if pod lifecycle management is misconfigured.

At Aerovix, we engineer automated GitOps release pipelines combining Terraform, Amazon EKS, and ArgoCD Rollouts that achieve genuine zero-downtime deployments with automated canary health analysis.

2. GitOps Workflow with ArgoCD

Every change to infrastructure or application configuration is managed declaratively in Git. When a developer merges to main, GitHub Actions runs automated unit and integration tests, builds immutable container images tagged with git commit hashes, and commits the updated deployment manifest to the GitOps configuration repo.

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: aerovix-core-api
spec:
  replicas: 10
  strategy:
    canary:
      steps:
      - setWeight: 10
      - pause: { duration: 5m }
      - setWeight: 30
      - pause: { duration: 10m }
      - setWeight: 60
      - pause: { duration: 5m }
      analysis:
        templates:
        - templateName: success-rate-analysis

3. Weighted Canary Traffic Shifting with AWS ALB

Using the AWS Load Balancer Controller, traffic is dynamically split between the stable (Blue) target group and the canary (Green) target group. Real user traffic gradually shifts from 10% to 100% only after automated metrics verify zero errors.

4. Pod Lifecycle & PreStop Hook Mechanics

A frequent root cause of dropped HTTP connections is terminating Kubernetes pods before the upstream load balancer deregisters them. Our pod specifications include explicit preStop sleep hooks:

lifecycle:
  preStop:
    exec:
      command: ["/bin/sh", "-c", "sleep 15"]

This 15-second grace period allows the AWS ALB target group to cleanly complete in-flight transactions and cease sending new traffic before the container receives the SIGTERM signal.

5. Automated Rollback on Prometheus Metric Degradation

If the error rate on the canary pods exceeds 0.05% or p99 latency increases beyond 200ms during the analysis phase, ArgoCD instantly aborts the rollout, restores 100% of traffic to the stable version, and notifies the engineering incident channel — completely without human intervention.

Building Mission-Critical Software?

Partner with Aerovix's dedicated engineering pods to design, develop, and scale your Next.js platforms, FinTech compliance, or private AI infrastructure.

Schedule Architecture Review