Home / OCI

OCIRunbookAdvanced

Sev1: The production load balancer was deleted; rebuild it and get traffic back

A production OCI load balancer was deleted and the site is down. Rebuild from code if you can, otherwise recreate the listener, backend set and certificate by CLI, reuse the reserved IP or repoint DNS.

Deepak Bhardwaj6 min read

Applies toOCI Load Balancer (flexible shape), OCI CLI 3.x, Resource Manager / Terraform stacks, OCI DNS

Symptoms

  • The public site times out or the DNS name resolves to an IP that no longer answers.
  • The load balancer is missing from the console, or shows DELETED.
  • The audit log has a DeleteLoadBalancer event, often from a Terraform destroy, a cleanup script, or a stack applied to the wrong workspace.
  • Backend instances are healthy and reachable on their private IPs.

A deleted load balancer cannot be undeleted. The goal is to recreate it quickly with the same configuration and, ideally, the same public IP.

1. Confirm scope and impact (3 minutes)

export COMP=ocid1.compartment.oc1..xxxx
export OLD_LB=ocid1.loadbalancer.oc1..xxxx    # from DNS records, monitoring or the audit log

oci lb load-balancer get --load-balancer-id $OLD_LB \
  --query 'data.{state:"lifecycle-state", name:"display-name", ips:"ip-addresses"}'

Find who deleted it and when:

oci logging-search search-logs \
  --search-query 'search "'"$COMP"'/_Audit" | where data.eventName = '"'DeleteLoadBalancer'"' | sort by datetime desc' \
  --time-start $(date -u -d '-24 hours' +%Y-%m-%dT%H:%M:%SZ) \
  --time-end $(date -u +%Y-%m-%dT%H:%M:%SZ) \
  --query 'data.results[].data.{time:datetime, who:data.identity.principalName, lb:data.resourceName}'

If the deletion came from an automation identity, stop that pipeline or schedule now, so it does not delete the replacement.

Check whether the old LB used a reserved public IP. A reserved IP survives the deletion; an ephemeral one does not.

oci network public-ip list --compartment-id $COMP --scope REGION --lifetime RESERVED --all \
  --query 'data[].{ip:"ip-address", id:id, state:"lifecycle-state", assigned:"assigned-entity-id"}' --output table

An AVAILABLE reserved IP with no assigned entity, matching the address in your DNS record, is the one to reuse.

2. Fastest path: rebuild from code

If the load balancer was defined in Terraform or a Resource Manager stack, re-apply it. This restores listeners, backend sets, certificates, rule sets and NSGs in one go.

# Resource Manager
oci resource-manager job create-apply-job --stack-id ocid1.ormstack.oc1..xxxx \
  --execute-plan-strategy AUTO_APPROVED

# Plain Terraform
terraform plan -target=oci_load_balancer_load_balancer.public
terraform apply

Warning

If the deletion came from this same stack (wrong variable, wrong workspace), read the plan before applying. Make sure it creates the load balancer and does not destroy anything else.

For a load balancer created by an OKE Service of type LoadBalancer, do not hand-build it. The cloud controller manages it; recreate the service so it provisions a new one:

kubectl -n web get svc web-lb -o yaml > /tmp/web-lb.yaml
kubectl -n web delete svc web-lb && kubectl apply -f /tmp/web-lb.yaml
kubectl -n web get svc web-lb -w

3. No code: rebuild by CLI

Collect what you need first: subnet OCIDs, NSG OCIDs, backend IPs and ports, health check path, and the TLS certificate files (certificate, private key, chain). Certificates uploaded directly to the deleted load balancer are gone with it; certificates managed in the OCI Certificates service still exist and can be referenced again.

Create the load balancer with the reserved IP and delete protection:

cat > /tmp/reserved-ips.json <<EOF
[{"id": "ocid1.publicip.oc1..xxxx"}]
EOF

oci lb load-balancer create --compartment-id $COMP \
  --display-name prod-web-lb \
  --shape-name flexible \
  --shape-details '{"minimumBandwidthInMbps": 10, "maximumBandwidthInMbps": 400}' \
  --subnet-ids '["ocid1.subnet.oc1..public"]' \
  --network-security-group-ids '["ocid1.networksecuritygroup.oc1..lb"]' \
  --reserved-ips file:///tmp/reserved-ips.json \
  --is-private false \
  --is-delete-protection-enabled true \
  --wait-for-state SUCCEEDED

Use the bandwidth values from your previous configuration if you know them. Leave out --reserved-ips if there was none.

Backend set, backends and certificate:

export LB=ocid1.loadbalancer.oc1..new

oci lb backend-set create --load-balancer-id $LB --name web-bs \
  --policy ROUND_ROBIN \
  --health-checker-protocol HTTP --health-checker-port 8080 \
  --health-checker-url-path /health --health-checker-return-code 200 \
  --wait-for-state SUCCEEDED

for ip in 10.0.2.15 10.0.2.16 10.0.3.15; do
  oci lb backend create --load-balancer-id $LB --backend-set-name web-bs \
    --ip-address $ip --port 8080 --wait-for-state SUCCEEDED
done

oci lb certificate create --load-balancer-id $LB --certificate-name web-2026 \
  --public-certificate-file /secure/web.crt \
  --private-key-file /secure/web.key \
  --ca-certificate-file /secure/chain.crt \
  --wait-for-state SUCCEEDED

If the backends are an instance pool, attach the pool instead of adding IPs by hand:

oci compute-management instance-pool attach-lb --instance-pool-id $POOL \
  --load-balancer-id $LB --backend-set-name web-bs --port 8080 --vnic-selection PrimaryVnic

Listeners:

oci lb listener create --load-balancer-id $LB --name https \
  --default-backend-set-name web-bs --port 443 --protocol HTTP \
  --ssl-certificate-name web-2026 \
  --wait-for-state SUCCEEDED

Recreate the port 80 redirect listener and any rule sets, hostnames or path route sets the old load balancer had. Check oci lb listener create --help on your CLI version for the SSL options it accepts.

Caution

The private key file is a credential. Load it from your secret store onto a locked-down host, and delete the local copy when the listener is up.

4. Repoint DNS if the IP changed

Without a reserved IP the new load balancer has a new address. Get it and update the record with a low TTL:

oci lb load-balancer get --load-balancer-id $LB --query 'data."ip-addresses"[0]."ip-address"' --raw-output

oci dns record rrset update --zone-name-or-id example.com --domain www.example.com --rtype A \
  --items '[{"domain":"www.example.com","rtype":"A","rdata":"203.0.113.25","ttl":60}]' --force

For DNS hosted elsewhere, make the same change there. Clients keep the old address until their cached TTL expires, so recovery is gradual.

5. Verify recovery

oci lb backend-set-health get --load-balancer-id $LB --backend-set-name web-bs
curl -sS -o /dev/null -w '%{http_code}\n' https://www.example.com/health
openssl s_client -connect www.example.com:443 -servername www.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -enddate
  • Backend set health is OK; every backend is listed.
  • HTTPS returns 200 with the right certificate and chain.
  • WAF policies, access logs and alarms that referenced the old load balancer OCID are attached to the new one.

Communicate

Tell users: " was unavailable from to because its load balancer was removed by mistake. A replacement is in service. Some users may see errors for a few more minutes while DNS updates."

Prevent it next time

  • Enable delete protection on every production load balancer (oci lb load-balancer update --is-delete-protection-enabled true).
  • Always front production with a reserved public IP, so a rebuild does not need a DNS change.
  • Keep load balancers in code and store certificates in the OCI Certificates service rather than uploading them to the load balancer.
  • Use prevent_destroy lifecycle rules in Terraform for load balancers, and separate production state from non-production.
  • Create an Events rule on DeleteLoadBalancer in production compartments that pages the on-call team.