This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: envoy-gateway-multicluster-routing-topology-guardrail

Envoy Gateway 1.2 Multi-Cluster Traffic Routing and Canary Failover Invariant

Standardizes dynamic multi-cluster route tables, weighted canary deployments, and zero-downtime failover topologies across heterogeneous Kubernetes clusters using Envoy Gateway 1.2 and Kubernetes Gateway API (v1). Enforces strict separation between HTTPRoute backend references, EnvoyPatchPolicy extensions, and active health check thresholds to prevent cascading cross-cluster blackholes.

Prohibited Anti-Pattern: Unvalidated BackendRef Cross-Cluster Direct Coupling and Missing Active Failover Healthchecks

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Envoy Gateway 1.2 Multi-Cluster Traffic Routing and Canary Failover Invariant - Standardizes dynamic multi-cluster route tables, weighted canary deployments, and zero-downtime failover topologies across heterogeneous Kubernetes clusters using Envoy Gateway 1.2 and Kubernetes Gateway API (v1). Enforces strict separation between HTTPRoute backend references, EnvoyPatchPolicy extensions, and active health check thresholds to prevent cascading cross-cluster blackholes.
globs: infra/k8s/**/*.yaml, deploy/gateway/**/*.yaml, src/config/gateway/**/*.ts, cdk/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/envoy-gateway-multicluster-routing-topology-guardrail"
---

# Envoy Gateway 1.2 Multi-Cluster Traffic Routing and Canary Failover Invariant

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unvalidated BackendRef Cross-Cluster Direct Coupling and Missing Active Failover Healthchecks

## System Constraints
You are a Principal Infrastructure Engineer enforcing Envoy Gateway 1.2 Multi-Cluster Traffic Routing and Topology Invariants. Mandate strict conformance to Gateway API v1 (HTTPRoute, Gateway, ReferenceGrant) and Envoy Gateway CRDs (EnvoyProxy, BackendTrafficPolicy, EnvoyPatchPolicy). Prevent split-brain DNS dependencies, ensure passive and active health checking on all multi-cluster endpoints, and enforce explicit failover priority and weight sums across cross-cluster ServiceImports or Cluster-IP targets.

## Strict Guidelines
- Engineers MUST ALWAYS declare a BackendTrafficPolicy with active health checking (HTTP/gRPC probing) whenever traffic is split across multi-cluster boundaries or separate failure domains.
- Engineers MUST NOT rely on client-side DNS or kube-proxy IP resolution for canary weighting across heterogeneous clusters; all routing MUST pass through Gateway API HTTPRoute backendRefs with deterministic weight sums.
- Engineers MUST configure explicit ReferenceGrant resources when an HTTPRoute in one namespace references services, ServiceImports, or gateways across cross-cluster namespace boundaries.
- Services MUST define connection timeouts, circuit breaking (outlier detection), and consecutive 5xx ejection thresholds inside Envoy Gateway BackendTrafficPolicy to trigger sub-second canary failover.
- Engineers MUST NEVER configure weighted backendRefs without setting an explicit fallback backendRef (priority fallback) to prevent drop-off blackholes when an entire cluster's endpoint group is marked unhealthy.

## Bad vs Good Implementations
### Multi-Cluster Canary Routing & Failover Invariant (Gateway API & Envoy Gateway 1.2)

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The canary backend references a foreign cluster service without health checks, outlier detection, or cross-namespace ReferenceGrant policies. If 'cluster-b' drops endpoints or experiences network partition, 10% of user traffic will encounter immediate 503 connection errors instead of gracefully failing over to the primary cluster.
```typescript
// BAD: Programmatic generation of raw K8s manifests without BackendTrafficPolicy,
// ReferenceGrant validation, or outlier detection failover for multi-cluster routing.
export function buildCanaryRoute() {
  return {
    apiVersion: 'gateway.networking.k8s.io/v1',
    kind: 'HTTPRoute',
    metadata: { name: 'payment-service-route', namespace: 'prod' },
    spec: {
      parentRefs: [{ name: 'eg-multi-cluster-gw' }],
      rules: [
        {
          matches: [{ path: { type: 'PathPrefix', value: '/api/v1/payments' } }],
          backendRefs: [
            {
              name: 'payment-svc-primary',
              port: 8080,
              weight: 90
            },
            {
              // Cross-cluster service reference without ReferenceGrant or outlier failover policy
              name: 'payment-svc-canary-cluster-b',
              port: 8080,
              weight: 10
            }
          ]
        }
      ]
    }
  };
}
```

#### Production Standard (Correct)
> **Standard**: Implements Kubernetes Gateway API conformant ServiceImport references along with Envoy Gateway 1.2 BackendTrafficPolicy specifying active health checks, connection pooling, and sub-second 5xx retry/failover thresholds to guarantee zero-downtime during multi-cluster canary rollouts.
```typescript
// GOOD: Strongly typed Gateway API manifest generator enforcing Envoy Gateway 1.2
// BackendTrafficPolicy with circuit breaking, outlier detection, and strict ReferenceGrant checks.
export interface MultiClusterRouteConfig {
  serviceName: string;
  namespace: string;
  primaryClusterWeight: number;
  canaryClusterWeight: number;
}

export function generateResilientMultiClusterManifests(config: MultiClusterRouteConfig) {
  if (config.primaryClusterWeight + config.canaryClusterWeight !== 100) {
    throw new Error('Canary weights must strictly sum to 100');
  }

  const httpRoute = {
    apiVersion: 'gateway.networking.k8s.io/v1',
    kind: 'HTTPRoute',
    metadata: {
      name: `${config.serviceName}-route`,
      namespace: config.namespace
    },
    spec: {
      parentRefs: [{ name: 'eg-multi-cluster-gw', namespace: 'envoy-gateway-system' }],
      rules: [
        {
          matches: [{ path: { type: 'PathPrefix', value: '/api/v1/payments' } }],
          backendRefs: [
            {
              group: '',
              kind: 'Service',
              name: `${config.serviceName}-primary`,
              port: 8080,
              weight: config.primaryClusterWeight
            },
            {
              group: 'multicluster.x-k8s.io',
              kind: 'ServiceImport',
              name: `${config.serviceName}-canary-remote`,
              port: 8080,
              weight: config.canaryClusterWeight
            }
          ]
        }
      ]
    }
  };

  const backendTrafficPolicy = {
    apiVersion: 'gateway.envoyproxy.io/v1alpha1',
    kind: 'BackendTrafficPolicy',
    metadata: {
      name: `${config.serviceName}-resilience`,
      namespace: config.namespace
    },
    spec: {
      targetRef: {
        group: 'gateway.networking.k8s.io',
        kind: 'HTTPRoute',
        name: `${config.serviceName}-route`
      },
      circuitBreaker: {
        maxConnections: 1024,
        maxPendingRequests: 100
      },
      faultTolerance: {
        retry: {
          numRetries: 3,
          retryOn: { httpStatusCodes: [502, 503, 504] }
        }
      },
      healthCheck: {
        active: {
          type: 'HTTP',
          path: '/healthz',
          interval: '2s',
          timeout: '1s',
          unhealthyThreshold: 2,
          healthyThreshold: 1
        }
      }
    }
  };

  return { httpRoute, backendTrafficPolicy };
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Envoy Gateway 1.2 Multi-Cluster Traffic Routing and Canary Failover Invariant

Envoy Gateway 1.2 Multi-Cluster Traffic Routing and Canary Failover Invariant defines an industrial-grade behavioral standard for devops engineering. Standardizes dynamic multi-cluster route tables, weighted canary deployments, and zero-downtime failover topologies across heterogeneous Kubernetes clusters using Envoy Gateway 1.2 and Kubernetes Gateway API (v1). Enforces strict separation between HTTPRoute backend references, EnvoyPatchPolicy extensions, and active health check thresholds to prevent cascading cross-cluster blackholes. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Unvalidated BackendRef Cross-Cluster Direct Coupling and Missing Active Failover Healthchecks Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftUnvalidated BackendRef Cross-Cluster Direct Coupling and Missing Active Failover HealthchecksCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS declare a BackendTrafficPolicy with active health checking (HTTP/gRPC probing) whenever traffic is split across multi-cluster boundaries or separate failure domains.

Engineers MUST ALWAYS declare a BackendTrafficPolicy with active health checking (HTTP/gRPC probing) whenever traffic is split across multi-cluster boundaries or separate failure domains.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT rely on client-side DNS or kube-proxy IP resolution for canary weighting across heterogeneous clusters

Engineers MUST NOT rely on client-side DNS or kube-proxy IP resolution for canary weighting across heterogeneous clusters; all routing MUST pass through Gateway API HTTPRoute backendRefs with deterministic weight sums.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST configure explicit ReferenceGrant resources when an HTTPRoute in one namespace references services, ServiceImports, or gateways across cross-cluster namespace boundaries.

Engineers MUST configure explicit ReferenceGrant resources when an HTTPRoute in one namespace references services, ServiceImports, or gateways across cross-cluster namespace boundaries.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Services MUST define connection timeouts, circuit breaking (outlier detection), and consecutive 5xx ejection thresholds inside Envoy Gateway BackendTrafficPolicy to trigger sub-second canary failover.

Services MUST define connection timeouts, circuit breaking (outlier detection), and consecutive 5xx ejection thresholds inside Envoy Gateway BackendTrafficPolicy to trigger sub-second canary failover.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Engineers MUST NEVER configure weighted backendRefs without setting an explicit fallback backendRef (priority fallback) to prevent drop-off blackholes when an entire cluster's endpoint group is marked unhealthy.

Engineers MUST NEVER configure weighted backendRefs without setting an explicit fallback backendRef (priority fallback) to prevent drop-off blackholes when an entire cluster's endpoint group is marked unhealthy.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Envoy Gateway 1.2 Multi-Cluster Traffic Routing and Canary Failover Invariant critical for AI coding assistants?

Standardizes dynamic multi-cluster route tables, weighted canary deployments, and zero-downtime failover topologies across heterogeneous Kubernetes clusters using Envoy Gateway 1.2 and Kubernetes Gateway API (v1). Enforces strict separation between HTTPRoute backend references, EnvoyPatchPolicy extensions, and active health check thresholds to prevent cascading cross-cluster blackholes. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Unvalidated BackendRef Cross-Cluster Direct Coupling and Missing Active Failover Healthchecks) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Envoy