Moving Avi from Blue to Green Without Ever Writing Back to Blue

Building GSLB is not the same job as moving the virtual services that already exist. The first job proves a name can fail over. The second job has a source of truth, a blue controller full of applications, and two green sites that should come to match it without anyone retyping a pool. The ask was specific: idempotent, deployable from YAML, customer-agnostic code with the customer’s environment in one file, one migration tool that does everything, and nothing created by hand. By the end, 67 virtual services and 285 objects per site were live at both sites, 62 GSLB services answered 65 names across four DNS zones, and every one of them was staged for a DNS cutover one name at a time, by a script that won’t change a name until the operator types it.

The Challenge

A virtual service is the visible object. Behind it is everything it uses. Copy the virtual service and forget a profile, and green looks installed until the first request. Copy everything, including the source site’s cloud, VRF and Service Engine group, and green is now pretending to be blue. The new site has its own cloud, its own VRF, its own SE group and its own VIP network. Those are the environment. They are not configuration to clone.

The first version of the tool, written two weeks before the real run, did export, plan and apply in three passes: profiles and monitors first, then SSL and pools, then VIPs and virtual services created disabled. It had 19 self-tests and a journal, and nothing was written without --commit. Reviewed against the real data, it would have stopped at pass 2. References were bare IDs. VIPs were rewritten after references were resolved. The Tier-1 was never changed. Placement fields went across untouched. It had one target, and no second site and no GSLB. One bug from that version set a rule for every test after it: references between objects created in the same run still pointed at blue’s IDs, and the self-test’s fake controller hid it because it never minted URLs. The fake controllers must behave like the real API.

Three Files Do Everything

avi_migrate.py holds no customer data. An environment file, env.<customer>.yaml, defines the customer: the source controller, both sites, mappings, secrets to ask for, GSLB zones and settings, and the domain controllers to ask. Two PowerShell scripts run on a domain controller: one exports every record of the zones, read-only, and one performs the cutover. The same files serve the next customer with a different environment file.

What Converge Does

The commands are converge, status, discover, export, purge and selftest. Everything is a dry run unless --commit is given. converge compares blue and the environment file with each green site and the GSLB leader, then reports every object:

State Meaning
ADD Not on green yet
UPDATE Made by the tool, and blue has changed since
UNCHANGED Matches
FROZEN One of its application’s names is flipped, so green owns it now
KEPT A same-named object built by hand on green, left alone (--adopt hands it over)
MAPPED Replaced by an existing object at that site, as configured
BLOCKED Can’t move as it is; the line names the reason and the fix

GSLB services read CREATE, UPDATE, ADD NAMES, ACTIVE, UNCHANGED, DIFFERS, HOLD or KEPT. Exit codes are 0 (nothing to do), 2 (changes pending) and 1 (blocked). GSLB is part of the same converge, not a later project: the leader gets a subdomain per zone, DNS services authoritative for them, and one GSLB service per blue VIP, named <host>.gslb.<zone>, built from explicit settings and never copied from another service. Priorities are 20 for the active site and 10 for the other, swappable with one setting, gslb_active_site, which has the same effect as raising the other site’s priority but never pushes the numbers higher. Health is the site controller’s view and a TCP check from each site’s DNS engines to the member VIP on its own port. The output that matters is a flip list: every DNS name, its GSLB target, and whether it is READY.

No client reaches green until its DNS name is flipped to the GSLB name. The flips are made from that list, on the Windows DNS side, name by name, when the application owner is ready. Not when the controller UI looks finished.

Who owns an application

A registry beside the environment file records everything the tool made or was handed. The tool only updates, publishes or sets live what is in it; everything else on green is left alone. Intent is recorded before each create, so an object whose reply was lost is taken over by the next run rather than orphaned, and every commit writes its own journal, never overwritten.

Blue is the source of truth until a name flips. Blue’s changes follow as UPDATE, and each VIP keeps the address green gave it. Once any name of an application is flipped, that application is FROZEN and belongs to green: its GSLB service only gains names, and its live state stays as green has it. Flip state is read live from every domain controller. A name any domain controller answers with the GSLB CNAME is flipped. A name a domain controller doesn’t answer for counts as flipped until it does, which is the fail-safe direction.

The rules the code enforces

  • It never writes to blue. The source client refuses POST, PUT, PATCH and DELETE, and a “target” that turns out to be blue’s cluster, by alias or address, stops the run before any write.
  • converge deletes nothing. purge deletes only what converge made, in an order the controllers accept, never an object that was on green before and never one a flipped application uses. The next converge builds it all again.
  • Virtual services are created disabled. A service is set live only where its SE group can place everything, and nothing live goes offline without --allow-offline.
  • It never lands a migrated service in the Supervisor’s Default-Group unless the environment file says so explicitly.
  • SE groups are raised, never lowered. Raising virtual services per engine costs no licence units; raising the engine count does.
  • GSLB names are only ever added, and a System- DNS profile is never edited.
  • It never writes DNS. The commit can’t flip anything. One thing does start at commit: health checks from green’s engines to the pool servers.

Two releases, one schema

Objects are posted in blue’s 31.1.2 schema, with X-Avi-Version, so 32.1.3 converts moved fields itself; a setting makes the tool convert them natively instead. Fields 32.1.3 refuses are removed using a product-change table built by diffing the two releases’ object models field by field. Fields the target owns are never treated as differences. These are the changes that mattered:

Change What it did How the tool handles it
content_rewrite.rewritable_content_ref removed 32.1.3 refused 61 of 67 virtual services on the first commit, even when told 31.1.2; no service used it, it was a default Removes it; drops a content rewrite with no rules
PING monitors refuse monitor_port The first commit stopped at the first PING monitor (8 affected) Drops the port, with a warning
graceful_disable_timeout (minutes) became graceful_disable_timeout_sec (seconds) 65 pools Left for the target to convert, or converted natively
WAF application-learning fields removed; updated_crs_rules_in_detection_mode became use_evaluation_mode_on_crs_update 2 WAF policies Removed or converted; a rule set version green doesn’t have is mapped to the newer one
configpb_attributes and other runtime fields Refused or meaningless on a new controller Never sent
Adding to GSLB dns_configs by PATCH refused (“Key not found”) Subdomains couldn’t be added Read the whole GSLB configuration and PUT it back, as the UI does
scaleout_ecmp set by the NSX cloud; PKI CA details recomputed Every re-run looked like a change Target-owned fields ignored; certificates compared by PEM content
SSL 3.0 and 3DES removed in 31.2.1; SHA-1 and MD5 deprecated in 32.1.3 Weak profiles Audited; 3DES and SSLv3 blocked until the owner decides

Secrets and trust

Controller passwords come from environment variables or a prompt, never the environment file. Private keys are read from blue with export_key at write time, held in memory, and never written to disk or a journal. Values blue masks as <sensitive>, such as the bind password and even the username of an LDAP health monitor, are asked for once, up front, and kept in memory; a skipped secret skips only its own object. On first contact the tool shows each controller certificate’s SHA-256 fingerprint and pins it only after the operator confirms. A changed certificate stops the run before the password is sent, and the CA-bundle environment variables that the Python requests library honours can’t override the pin. That last one closed a hole: an earlier tool used to silently accept a changed certificate and then send the password.

The First Real Run

The first dry run against production found 67 virtual services, not the 61 the UI had suggested, and 15 blockers per site from three causes. Three unused objects, two auth profiles and a certificate-management profile, were excluded with avi_exclude. Two LDAP health monitors carried a bind password the API never returns; creating them by hand was not an option, so avi_secrets was born: the tool asks once, keeps the value in memory, and never writes it anywhere. And a WAF rule set version green doesn’t have was mapped to the newer one, with both WAF policies in detection mode. Changes to the environment file went out as tested sed commands, so the file and its passwords stayed where they were.

The first commit stopped at the first PING monitor, because 32.1.3 refuses a port on it. From then on a refused write is reported with the controller’s own reason and skipped with its dependents, and the run carries on, so that anything else the new release rejects shows up in one pass instead of one run at a time. The next pass showed 61 of 67 virtual services refused for a field that no longer exists in 32.1. A purge rehearsal then rebuilt everything with the same 58 writes, and the run after it reported 0 changes. Repeatable, rinse and repeat.

discover came from a question asked that afternoon: can the GSLB names be pre-populated from the host the tool runs on? It collects the names blue gives each VIP (VIP DNS info, certificate names, SNI and virtual-hosting domains, reverse DNS, and later Host matches in HTTP policies, string groups, WAF allowlists and DataScripts, but never where a redirect sends a request), confirms each with the domain controllers, and writes the names file. It only ever adds names, and it never overwrites an export from a domain controller.

Convergence Day

One machine only. The tool had been run from two hosts, and its registry lives in the folder it runs from. Everything the first host had made, 436 objects, was purged from that host, and the rebuild ran from the second host only. Its dry run: 624 changes, 0 blocked. Choose one machine and use only that one.

Capacity at the second site. The dry run stopped the second site going live: its SE group held 30 virtual services and 67 needed placing. The tool learned to raise an SE group, and never lower one.

The GSLB API. PATCH /api/gslb/<uuid> answered “Failed to patch list of sub objects. Key not found.” 32.1.3 refuses a PATCH that adds to the subdomain list, so the fix reads the whole GSLB configuration and puts it back, as the UI does. A site password that comes back masked is kept by the controller. The journal showed staging had already finished by then: 285 objects at each site, all 67 services, nothing half-written.

The F5. Eleven applications’ names didn’t point at blue’s VIPs at all; they pointed at an F5 in front of them, and the domain controller confirmed it. One inference rule covers it: when a name blue gives exactly one VIP has a single A record that isn’t blue’s, that address is taken as the VIP’s current front door. Those applications got GSLB services too, 62 instead of 51. For them a flip is the cutover off the F5, and a rollback puts the F5 address back.

App Domain Names. The tool had stripped a VIP’s DNS names deliberately: if a green cloud publishes VIP names through an outside DNS provider such as Infoblox, blue’s names would be pointed at green’s addresses before any DNS flip. They now carry across unless the site’s cloud has an outside DNS provider.

The commit worked. The first site went live. The second went live after the SE group raise. Then the second commit rewrote every virtual service, because green adds fields of its own: the NSX cloud sets scaleout_ecmp, and 32.1.3 rewrites a PKI profile’s CA details. Ignoring the fields the target owns and comparing certificates by PEM content brought the next dry run to 0 changes to make. Nothing broke, but a run should change nothing when nothing has changed.

59 of 65 names READY. One cause of NOT READY: a service behind a network security policy that admits listed subnets and denies everyone else. That policy blocks GSLB’s own TCP checks, so GSLB thought both sites were down. Such a member is now watched through its site controllers instead, and the security policy is left alone.

The domain controller export: 20,180 records. It added one name discovery had missed, found two wildcard records answering the not-yet-delegated GSLB subdomains with blue’s addresses, and turned up one www name that exists only through a wildcard and needs a decision. Before the first flip, use a full export: only an export sees a name that also holds a TXT, MX or AAAA record. Such a name can’t become a CNAME, so it is marked MANUAL.

The Cutover Lever

The customer has to be able to migrate one DNS name at a time, with the lever pulled against one name and no room for error. The flip script runs on a domain controller in elevated Windows PowerShell 5.1, and refuses PowerShell 7 unless told otherwise. It has four modes: Check (read-only), Ttl (lowers the TTL a TTL ahead of the flip, and prints the earliest time to flip), Flip and Rollback. A Flip or Rollback takes exactly one fully written name; wildcards, several names and “all” need a separate switch. With the commit switch, the script shows the change and asks for the name to be typed; anything else changes nothing. A flip list more than a day old is refused, and the undo command is printed after every flip.

Before touching anything it checks that the name is READY, that it holds only its blue A record, and that its GSLB name answers the active site’s VIP from both DNS services and through the domain controller. It logs the name to a write-ahead log, then turns the A record into a CNAME. If the CNAME can’t be added, the A record goes straight back. It pushes AD replication and names any of the zone’s DNS servers that don’t answer the CNAME yet. Rollback works on the domain controller the log names, and cross-checks the zone’s other DNS servers before reporting success. The PowerShell side is not in the public repository yet.

How It Was Tested

76 self-tests run against in-memory blue and green controllers that behave like the real API where it matters: names on references only when asked, pagination and IPAM, export_key and GSLB member validation, the fields 32.1.3 refuses, masked values and the GSLB PATCH refusal. Every lesson from the real controllers became a test. The fake 32.1 controller holds its own list of every field 32.1.3 dropped and refuses each one, and the suite uses stand-in DNS for the domain controllers and both GSLB DNS services, with a real UDP round trip. Then we checked the tests have teeth: 100 deliberate breakages of the tool, one at a time, each caught, among them writing to blue, a purge that deletes what it didn’t make, and READY without the delegation.

Before the first commit, every body the tool would post from the real blue export was checked against both releases’ object models, discovery was run on the real export and the real domain controller export, and a purge-and-rebuild lifecycle was rehearsed for each release. The PowerShell scripts ran against mock DNS cmdlets under PowerShell 7.4 on Linux, with three simulated domain controllers that fail the way real ones do: 105 scenarios, and 27 broken copies of the flip script all caught, with PSScriptAnalyzer checking Windows PowerShell 5.1 compatibility. They had not yet run on a real domain controller.

The Results

All 67 virtual services and 285 objects per site live at both sites, nothing refused. 62 GSLB services answering 65 names across four zones, TTL 30 seconds, failover in about a minute. A second commit that changes nothing. A flip list with 59 of 65 names READY, and a lever that moves one of them at a time. Controller deployed on the 15th, GSLB proven on the 25th, all services live at both sites on the 29th.

Lessons Learned

  1. Make a migration converge, not just create. Dry run by default, a registry of what the tool owns, a journal per commit, and never write to the source. Prove repeatability with a real purge and rebuild, and expect a re-run to change nothing.
  2. Diff the object models between releases. Posting in the old schema covers most changes, not all of them. We built a field-by-field table from the two SDKs, and the real controller added the rest.
  3. Every lesson from production becomes a test. Then check the tests have teeth by breaking the code on purpose.
  4. Ship, then harden in the open. A morning of silent hardening cost more trust than any bug would have. Fifteen minutes is a long time when the customer is on the call. The pattern that worked: ship the fix with a quick sanity run, and extend the tests in the open.
  5. Move DNS one name at a time, with a typed confirmation and a printed undo.
  6. Keep one registry. Running the tool from two machines with a per-folder registry split what it owned.
  7. Copying the source site’s cloud and SE group makes green pretend to be blue. Those references are the environment, not configuration to clone.
  8. Don’t use the test service as a template. It would have carried test settings into production; explicit settings from Broadcom’s GSLB guidance replaced it.

Getting Started

Run the offline check first. It needs no controller. The environment file is yours. The sample keys are site_a and site_b. Point the hosts at your controllers, for example avi-blue.essential.coach.

python3 avi_migrate.py selftest
python3 avi_migrate.py --example-config > env.essential.yaml
python3 avi_migrate.py export   --config env.essential.yaml      # read blue only
python3 avi_migrate.py discover --config env.essential.yaml      # the DNS names, from blue and the domain controllers
python3 avi_migrate.py converge --config env.essential.yaml      # dry run: every object and its state
python3 avi_migrate.py converge --config env.essential.yaml --commit
python3 avi_migrate.py status   --config env.essential.yaml      # readiness and a fresh flip list

Clone avi-blue-green. Run the offline self-test before you point it at a controller. Rename site_a and site_b to your site keys. Converge does not write unless you pass --commit. Flip DNS names from the list the tool prints, one at a time, when the application owner is ready. Do not flip them because the controller UI looks finished.

What’s Next

Delegations for the remaining gslb subdomains, and a decision on the two wildcard records and the www name. Engine-group consolidation for licensing, by moving the first site’s applications into the Supervisor’s Default-Group and letting the emptied engines go. Server allow-lists for the 23 services that use their VIP as the source address. Sizing the second site before it is ever the active one. A second DNS engine per site and a rehearsed manual leader change. Then the cutover: export the zones from a domain controller, and flip one application at a time; the first one proves production failover. Blue retires application by application: after a week with no rollback, disable its services on blue; a week later, delete them. Never upgrade blue in place.

Conclusion

Blue stays the source of truth until a name flips. After that, green owns the application, and the tool will not drag it back. Nothing is ever written to blue, and nothing is ever written to DNS by anything but the one-name lever.


Repository: github.com/noahfarshad/avi-blue-green

Related Stories:

Scroll to Top