OCI DevOps Deployment Pipelines: Blue-Green and Canary Releases to OKE

OCI DevOps Deployment Pipelines orchestrate releases to OKE, compute instances, and serverless Functions. They support environment-specific configuration through deploy environment definitions, approval gates that block progression between stages, and automatic rollback on deployment failure. This post covers creating a deployment pipeline that implements a canary release to OKE with an approval gate before full promotion, using Terraform for all pipeline resources.

Step 1: Deploy Environments

resource "oci_devops_deploy_environment" "oke_production" {
  project_id              = var.devops_project_id
  display_name            = "oke-production"
  description             = "Production OKE cluster"
  deploy_environment_type = "OKE_CLUSTER"
  cluster_id              = var.oke_cluster_id

  defined_tags = { "Operations.Environment" = "production", "Operations.ManagedBy" = "terraform" }
}

resource "oci_devops_deploy_artifact" "orders_api_manifest" {
  project_id               = var.devops_project_id
  display_name             = "orders-api-k8s-manifest"
  deploy_artifact_type     = "KUBERNETES_MANIFEST"
  argument_substitution_mode = "SUBSTITUTE_PLACEHOLDERS"

  deploy_artifact_source {
    deploy_artifact_source_type = "INLINE"
    base64encoded_content       = base64encode(file("${path.module}/k8s/orders-api.yaml"))
  }
}

output "environment_id" { value = oci_devops_deploy_environment.oke_production.id }

Step 2: Deployment Pipeline with Canary Stages

resource "oci_devops_deploy_pipeline" "orders_api_deploy" {
  project_id   = var.devops_project_id
  display_name = "orders-api-deploy"
  description  = "Canary deployment pipeline for orders API to OKE"

  deploy_pipeline_parameters {
    items {
      name          = "IMAGE_TAG"
      description   = "Container image tag to deploy"
      default_value = "latest"
    }
    items {
      name          = "CANARY_WEIGHT"
      description   = "Percentage of traffic to canary deployment"
      default_value = "10"
    }
  }
}

# Stage 1: Deploy canary (10% traffic)
resource "oci_devops_deploy_stage" "canary_deploy" {
  deploy_pipeline_id    = oci_devops_deploy_pipeline.orders_api_deploy.id
  display_name          = "deploy-canary-10-percent"
  deploy_stage_type     = "OKE_CANARY_DEPLOYMENT"
  description           = "Deploy new version to 10% of traffic"

  oke_cluster_deploy_environment_id = oci_devops_deploy_environment.oke_production.id
  kubernetes_manifest_deploy_artifact_ids = [oci_devops_deploy_artifact.orders_api_manifest.id]

  canary_strategy {
    ingress_name    = "orders-api-ingress"
    namespace       = "orders"
    nginx_ingress_deploy_artifact_id = oci_devops_deploy_artifact.orders_api_manifest.id
  }

  deploy_stage_predecessor_collection {
    items { id = oci_devops_deploy_pipeline.orders_api_deploy.id }
  }
}

# Stage 2: Approval gate before full promotion
resource "oci_devops_deploy_stage" "approval_gate" {
  deploy_pipeline_id = oci_devops_deploy_pipeline.orders_api_deploy.id
  display_name       = "approve-full-rollout"
  deploy_stage_type  = "WAIT"
  description        = "Manual approval required before 100% traffic shift"

  wait_criteria {
    wait_type     = "ABSOLUTE_WAIT"
    wait_duration = "PT0S"
  }

  deploy_stage_predecessor_collection {
    items { id = oci_devops_deploy_stage.canary_deploy.id }
  }
}

# Stage 3: Full production rollout
resource "oci_devops_deploy_stage" "full_rollout" {
  deploy_pipeline_id = oci_devops_deploy_pipeline.orders_api_deploy.id
  display_name       = "full-production-rollout"
  deploy_stage_type  = "OKE_CANARY_TRAFFIC_SHIFT"
  description        = "Shift 100% traffic to new version"

  oke_cluster_deploy_environment_id      = oci_devops_deploy_environment.oke_production.id
  kubernetes_manifest_deploy_artifact_ids = [oci_devops_deploy_artifact.orders_api_manifest.id]

  canary_strategy {
    ingress_name = "orders-api-ingress"
    namespace    = "orders"
    nginx_ingress_deploy_artifact_id = oci_devops_deploy_artifact.orders_api_manifest.id
  }

  deploy_stage_predecessor_collection {
    items { id = oci_devops_deploy_stage.approval_gate.id }
  }
}

output "deploy_pipeline_id" { value = oci_devops_deploy_pipeline.orders_api_deploy.id }

Operational Notes

The WAIT stage in OCI DevOps pauses the pipeline until a user approves progression in the console or via the API. This is the built-in approval gate. Combined with your monitoring dashboards, it gives you the observability window needed to validate canary behavior before committing to a full rollout. If error rates increase during the canary window, trigger a rollback from the pipeline UI rather than approving progression.

Pass image tags as pipeline parameters rather than hardcoding them in the manifest artifact. The build pipeline injects the image tag as a parameter when triggering the deployment pipeline. This creates an auditable link between a specific build run and the deployment that used it, which is essential for incident investigation and for rolling back to a specific known-good image version.

Regards,
Osama

#OCI #OracleCloud #DevOps #BlueGreen #Canary #OKE #Terraform #IaC #TechBlog #Oracle #CICD #PlatformEngineering #CloudNative #OracleCloudInfrastructure #Kubernetes #DeploymentPipeline #ApprovalGate #Rollback #GitOps #SoftwareDelivery

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.