Goal
You need to patch or reboot one server behind an OCI load balancer. If you simply reboot it, users with open connections get errors until the health check marks the backend down, which takes several failed checks. The clean way: drain the backend so it gets no new connections, wait for existing ones to finish, take it offline, patch, then bring it back.
How the backend flags work
Each backend in a backend set has four settings that control traffic:
| Setting | Effect | Use during maintenance |
|---|---|---|
drain (is-drain on NLB) | No new connections; existing ones continue | Step 1: let traffic bleed off |
offline (is-offline on NLB) | Receives no traffic at all | Step 2: before stopping the service |
backup (is-backup on NLB) | Gets traffic only when the primary backends are unhealthy | Leave as it was |
weight | Share of new connections with weighted policies | Leave as it was |
Warning
On the Flexible Load Balancer,
oci lb backend updaterequires all four values:--weight,--backup,--drainand--offline. Always read the current values first and pass them back unchanged, or you can accidentally turn a backup into a primary or reset its weight.
Before you start
- At least one other backend in the set must be OK, with enough capacity to carry the full load on its own.
- Check whether the backend set uses session persistence. Users pinned to the drained server will move to another one when it goes offline, and may need to sign in again if sessions are kept in local memory.
- If the backend belongs to an instance pool attached to the load balancer, the pool manages that backend. Use the pool's rolling replacement process rather than changing backends by hand.
LB=ocid1.loadbalancer.oc1...
BS=bs-web
BE=10.0.2.15:8080 # backend name is <ip>:<port>
oci lb backend-set-health get --load-balancer-id $LB --backend-set-name $BS
oci lb backend list --load-balancer-id $LB --backend-set-name $BS --output table
oci lb backend get --load-balancer-id $LB --backend-set-name $BS --backend-name $BE
Note weight and backup from the last command. The example below assumes weight 1 and backup false.
Step 1: drain the backend
oci lb backend update --load-balancer-id $LB --backend-set-name $BS --backend-name $BE \
--weight 1 --backup false --drain true --offline false \
--wait-for-state SUCCEEDED
Changes go through a work request. --wait-for-state makes the command block until it finishes. If it fails, check the work request:
oci lb work-request list --load-balancer-id $LB --limit 5 --output table
oci lb work-request get --work-request-id <work-request-ocid>
Tip
Only one configuration change runs on a load balancer at a time. If another team or a pipeline is changing the same load balancer, your request waits or fails. Script the drain and check the work request state instead of assuming success.
Step 2: wait for connections to finish
On the backend, count established connections on the service port coming from the load balancer subnet:
LB_SUBNET=10.0.1.0/24
watch -n 5 "ss -Htn state established '( sport = :8080 )' dst $LB_SUBNET | wc -l"
With a Network Load Balancer that preserves the client IP, the source addresses are the clients, not the LB subnet. Drop the dst filter in that case.
The count won't always reach zero. Long-lived connections (WebSockets, streaming, long polling) can stay open for as long as the idle timeout allows. Set a maximum wait that fits your application, for example 5 to 10 minutes, then move on.
Step 3: take it offline and patch
oci lb backend update --load-balancer-id $LB --backend-set-name $BS --backend-name $BE \
--weight 1 --backup false --drain true --offline true \
--wait-for-state SUCCEEDED
Now stop the application, patch and reboot:
sudo systemctl stop myapp
sudo dnf -y update # or apt-get / your patching tool
sudo reboot
After the reboot, confirm the service is up and the health endpoint answers locally before you send any traffic to it:
systemctl is-active myapp
curl -s -o /dev/null -w '%{http_code}\n' http://localhost:8080/health
sudo firewall-cmd --list-ports # make sure the patch didn't reset firewall rules
Step 4: put it back into rotation
oci lb backend update --load-balancer-id $LB --backend-set-name $BS --backend-name $BE \
--weight 1 --backup false --drain false --offline false \
--wait-for-state SUCCEEDED
oci lb backend-health get --load-balancer-id $LB --backend-set-name $BS --backend-name $BE
Wait until the backend health status is OK before you start on the next server. Patch one backend at a time unless you have proven spare capacity.
Caution
Don't start the next backend while the previous one is still
UNKNOWNorCRITICAL. If both drained servers end up out of rotation, the backend set can drop to zero healthy members and every request fails with 502.
Network Load Balancer version
The NLB uses is- prefixed flags and the update parameters are optional, so you only pass what you change. Backend names on an NLB can be <ip>:<port> or include a target OCID, so take the name from the list output.
NLB=ocid1.networkloadbalancer.oc1...
oci nlb backend list --network-load-balancer-id $NLB --backend-set-name $BS --output table
# Drain
oci nlb backend update --network-load-balancer-id $NLB --backend-set-name $BS \
--backend-name "$BE" --is-drain true --wait-for-state SUCCEEDED
# Offline for patching
oci nlb backend update --network-load-balancer-id $NLB --backend-set-name $BS \
--backend-name "$BE" --is-offline true --wait-for-state SUCCEEDED
# Return to service
oci nlb backend update --network-load-balancer-id $NLB --backend-set-name $BS \
--backend-name "$BE" --is-drain false --is-offline false --wait-for-state SUCCEEDED
oci nlb backend-health get --network-load-balancer-id $NLB --backend-set-name $BS --backend-name "$BE"
Check oci nlb backend update --help on your CLI version for the exact flag names.
Common problems
| Symptom | Cause | Fix |
|---|---|---|
| Update fails with a missing parameter error | lb backend update needs weight, backup, drain and offline | Pass all four, using the current values |
Work request stays IN_PROGRESS or fails with a conflict | Another change is running on the same load balancer | Wait for it, then retry |
| Users still reach the server after drain | Existing keep-alive or long-lived connections | Wait, then set offline |
Backend stays CRITICAL after returning | App not started, or firewall rules reset by the patch | Check the service, ss -ltnp and firewalld |
| Backup server now takes traffic all the time | --backup was set to the wrong value during update | Re-run the update with the original backup value |
| Backend reappears or vanishes on its own | Backend is managed by an instance pool | Use the pool's rolling replacement instead |
Prevent it next time
- Wrap the four steps in one script that reads the current
weightandbackupfirst, so nobody types them by hand. - Keep an alarm on
UnHealthyBackendServers(namespaceoci_lbaas) above 0 for each backend set, so a backend that never came back is spotted. - Size the backend set for N+1: with one server out for patching, the rest must carry peak load.
- Add a fast, dependency-free
/healthendpoint so the backend returns to OK quickly after a reboot.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get