Cloud

Azure APIM self-hosted gateway: diagnose configuration sync loss before restarting

A production runbook to separate served traffic, heartbeat, local configuration, DNS, TLS, authentication and Azure connectivity before restarting an APIM self-hosted gateway.

25 Oct 2026 azureapi-managementself-hosted-gatewaykuberneteshybrid-cloudnetworkingidentityobservabilityautomationrunbookrollbackproduction

Azure reports that an API Management self-hosted gateway is disconnected. Client calls still succeed at the industrial site, yet a policy change made in APIM never appears there. Restarting the pods or redeploying the Helm release looks like the fastest way to restore a clean state.

That restart can turn a synchronization failure into a real outage. A running gateway can continue serving its in-memory configuration during a temporary loss of Azure connectivity. After a restart, however, it must reach the configuration service or have a usable local configuration backup from which to start.

The running case is a v2 gateway on Kubernetes, associated with an Azure APIM instance and located near internal backends. The runbook separates four states: a healthy data plane with a disconnected control plane, stale local configuration, a failed gateway runtime, and a backend failure. It ends with a decision to reconnect, remain temporarily static, roll back configuration, or perform a controlled restart.

Freeze the running state before touching pods

Preserve the distinction between traffic and synchronization first. Azure derives gateway connectivity from periodic heartbeats; the disconnected status alone does not prove that the client path has stopped serving requests.

yaml 01-apim-self-hosted-incident.yml
incident: INC-APIM-847
window_utc: 2026-10-25T15:10:00Z/2026-10-25T15:40:00Z
apim_service: apim-platform-prod
gateway_resource: plant-west
kubernetes:
context: edge-prod
namespace: apim-gateway
deployment: apim-self-hosted
observed:
azure_status: disconnected
client_traffic: still_served
latest_policy_change_utc: 2026-10-25T15:18:00Z
new_policy_visible_on_gateway: false
containment:
rollout_paused: true
replicas_unchanged: true
config_changes_frozen: true
evidence:
- gateway_status_and_node_count
- pod_image_digest_and_restart_count
- configmap_digest_without_secrets
- local_gateway_logs
- synthetic_request_before_and_after_change

Retain the node count visible in APIM, last heartbeat time, deployed image, Kubernetes events and a synthetic call with a correlation ID. Do not remove a pod that is still carrying traffic until the remaining capacity and configuration backup have been qualified.

Separate the data plane from configuration service

The self-hosted gateway processes API calls locally. Its outbound Azure connection is used to report heartbeat, check for configuration updates and publish selected telemetry. Losing that path can therefore produce a disconnected gateway that still serves the last configuration it loaded.

text 02-two-planes.txt
LOCAL DATA PLANE
Client -> local endpoint -> self-hosted gateway -> backend
Prove: health endpoint, API request, observed policy, backend, latency

AZURE CONTROL PLANE
Gateway -> APIM configuration endpoint over HTTPS 443
Prove: DNS, route, proxy/firewall, TLS, authentication, heartbeat

STATES THAT MUST STAY DISTINCT
API works + change absent = synchronization is probably blocked
Health fails + pods are unstable = qualify runtime or hosting
Gateway works + backend fails = investigate the separate backend path
Pod stopped + no local backup = restart is unsafe

Call the built-in health endpoint from the local monitoring path, then run a no-effect synthetic operation against a known API. The health endpoint proves the gateway itself, not its backend. The synthetic request must separately validate routing, the expected policy and an identifiable backend response.

Read the deployment without disclosing credentials

Inspect the live cluster before relying on source manifests. An unapplied Git or Helm change does not explain the running pod, while an emergency manual edit may have introduced drift that the repository does not show.

bash 03-capture-kubernetes-state.sh
NS="apim-gateway"
DEPLOY="apim-self-hosted"

kubectl -n "$NS" get deploy "$DEPLOY" -o wide
kubectl -n "$NS" get pods -l app=apim-self-hosted -o wide
kubectl -n "$NS" rollout status deploy/"$DEPLOY" --timeout=10s
kubectl -n "$NS" get events --sort-by=.lastTimestamp | tail -40

kubectl -n "$NS" get deploy "$DEPLOY" -o jsonpath='{.spec.template.spec.containers[*].image}{"
"}'

kubectl -n "$NS" get configmap apim-gateway-env -o jsonpath='{.data.config.service.endpoint}{"
"}'

kubectl -n "$NS" logs deploy/"$DEPLOY" --since=45m --all-pods=true | grep -Ei 'config|connect|auth|certificate|timeout|error'

Do not print a gateway token, client secret or the full contents of a Kubernetes Secret. Check only its reference, age, version or fingerprint through the platform’s approved process.

Also confirm that the container image uses an explicit version tag or digest. A rolling tag makes it harder to tell configuration loss from a runtime change after a pod is recreated.

Prove DNS, TLS and HTTPS from the gateway network

The useful probe starts in the gateway namespace or network. Successful resolution from an operator workstation proves little when the cluster uses different DNS servers, egress routes or a proxy.

bash 04-test-configuration-endpoint.sh
NS="apim-gateway"
CONFIG_HOST="apim-platform-prod.configuration.azure-api.net"

kubectl -n "$NS" run apim-config-probe --image=curlimages/curl:8.12.1 --restart=Never --rm -i -- sh -c "nslookup $CONFIG_HOST && curl -svI --connect-timeout 5 https://$CONFIG_HOST/"

kubectl -n "$NS" run apim-tls-probe --image=alpine/openssl:3.3.3 --restart=Never --rm -i -- s_client -connect "$CONFIG_HOST:443" -servername "$CONFIG_HOST" -brief

An unsuccessful HTTP status can still prove that DNS, TCP and TLS work; do not automatically label it a network failure. Conversely, classify a failed request precisely: no resolution, wrong address, TCP timeout, untrusted certificate, proxy interception or authentication rejection.

If APIM uses a private configuration endpoint or custom hostname, test that exact contract. Do not open broad Internet egress to bypass a broken private DNS link. Do not disable certificate validation in production either: repair the demonstrated trust chain, SNI or network path.

Separate connectivity from authentication

A valid TLS session does not prove that the gateway can download configuration. Depending on the deployment, the container can authenticate with a gateway token or Microsoft Entra credentials. Establish the effective method, its configuration and the runtime error before rotating anything.

text 05-authentication-decision.txt
Gateway token
Check issue and expiry dates through the approved channel
Confirm the mounted Secret refers to the expected version
Rotate without printing the token

Microsoft Entra
Confirm tenant, client ID, audience and secret/certificate method
Check credential expiry and expected permissions
Separate token acquisition from APIM authorization

Do not
Regenerate every credential before reading the errors
Mount two competing methods without knowing which one is active
Broaden a role to fix DNS or TLS
Copy sensitive values into the incident record

After an identity fix, wait for both observed reconnection and a real configuration download. A restored heartbeat without the expected policy does not close the incident.

Prove which configuration is actually serving

Use a bounded, observable difference as the canary instead of a risky policy change. A test revision or operation can add a non-sensitive response header, allowing the affected gateway to be compared with another gateway that is already synchronized.

Treat local configuration as production state. Record the last known policy, API revision, referenced Named Values and last change time. Continued successful calls do not prove that the configuration is current: fail-static behavior favors continuity with the latest available copy.

yaml 06-sync-canary.yml
canary:
api: diagnostics-readonly
operation: GET /sync-version
expected_status: 200
expected_header: x-apim-config-revision
previous_value: rev-41
candidate_value: rev-42
side_effect: none

accept:
- azure_gateway_status_connected
- expected_node_count_visible
- candidate_value_seen_on_every_replica
- normal_api_success_rate_preserved
- local_logs_show_no_configuration_error

reject:
- replicas_serve_mixed_revisions
- only_heartbeat_recovers
- backend_checks_regress
- restart_is_required_without_verified_backup

Cloud metrics may disappear with Azure connectivity. Keep a local source as well: stdout and stderr, cluster log collection and, when configured, local metrics or OpenTelemetry. Missing Azure data during the outage must not be mistaken for missing traffic.

Restart only after proving restartability

Before a rollout, establish whether local configuration backup is enabled, persistent and restorable in this deployment. Without a backup, a running pod can serve its in-memory copy while a new pod cannot start until Azure connectivity returns.

Restart one replica first when capacity permits. Keep the remaining pods in place, run the canary against the new replica, and expand only after it reconnects and loads the correct revision. If the platform cannot isolate one replica cleanly, restore the configuration path before restarting.

Decide, validate or roll back

Match the action to the dominant evidence.

  • Remain static when traffic is healthy, the current configuration is acceptable and restarting would add risk.
  • Repair DNS, routing, proxy, firewall or TLS when the configuration endpoint is unreachable from the gateway.
  • Repair authentication when transport works but the runtime is rejected.
  • Roll back the latest APIM configuration when synchronization returns but the new policy fails the canary.
  • Restart progressively only after backup, capacity and recovery have been proved.

Rollback can mean restoring the previous APIM policy or revision, reverting the network or identity configuration, or stopping a rollout after the first canary. Validate both planes afterward: heartbeat and node count in Azure, served revision and backend calls locally.

Conclusion

A disconnected APIM self-hosted gateway is not necessarily an unavailable gateway. It is first a possible break between a local data plane that is still operating and a control plane that can no longer deliver configuration.

The correct response is not to restart until the status turns green. Prove served traffic, the loaded revision, DNS/TLS/HTTPS to the configuration endpoint, authentication and restartability. The decision then becomes bounded: reconnect, remain temporarily fail-static, roll back configuration, or perform a canary restart without sacrificing the last working gateway.