This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: gateway-api-automated-canary-traffic-shifting

Vendor-Neutral Declarative HTTPRoute Canary Shifting with Automated Rollback

Enforces Gateway API 1.2 HTTPRoute declarative traffic splitting for progressive delivery, replacing vendor-locked ingress annotations. Requires automated metric validation thresholds (P99 latency, HTTP 5xx error budget burn) with strict rollback triggers before promoting canary weights.

Prohibited Anti-Pattern: Proprietary Ingress Annotations with Manual or Unvalidated Traffic Splitting

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Vendor-Neutral Declarative HTTPRoute Canary Shifting with Automated Rollback - Enforces Gateway API 1.2 HTTPRoute declarative traffic splitting for progressive delivery, replacing vendor-locked ingress annotations. Requires automated metric validation thresholds (P99 latency, HTTP 5xx error budget burn) with strict rollback triggers before promoting canary weights.
globs: k8s/**/*.yaml, deploy/**/*.yaml, helm/**/*.yaml, infra/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/gateway-api-automated-canary-traffic-shifting"
---

# Vendor-Neutral Declarative HTTPRoute Canary Shifting with Automated Rollback

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Proprietary Ingress Annotations with Manual or Unvalidated Traffic Splitting

## System Constraints
You are a Principal Infrastructure Architect enforcing Kubernetes Gateway API 1.2 specifications for canary traffic shifting. Reject legacy Ingress controllers and vendor-proprietary annotations (e.g., nginx.ingress.kubernetes.io/canary, traefik.ingress.kubernetes.io). Mandate standard gateway.networking.k8s.io/v1 HTTPRoute resources with deterministic backendRef weight splitting. Require continuous telemetry validation (P99 latency, error percentage) linked to automated rollback controllers (Flagger, Argo Rollouts, or KEDA) before weight progression increments.

## Strict Guidelines
- Engineers MUST ALWAYS use `gateway.networking.k8s.io/v1` HTTPRoute resources for traffic distribution rather than vendor-specific ingress controller annotations.
- Engineers MUST configure declarative `backendRefs` with explicit integer `weight` fields that sum up to 100 across stable and canary targets.
- Engineers MUST NOT mutate production `HTTPRoute` weights manually in live clusters without an automated progressive delivery controller evaluating real-time metrics.
- Services MUST define automated rollback triggers linked to Prometheus/Datadog metrics (e.g., HTTP 5xx rate > 1%, P99 latency > target SLA) evaluated on every progression step.
- Components NEVER route traffic to canary pods before readiness probes pass and active synthetic smoke tests execute against the canary backendRef filter.

## Bad vs Good Implementations
### Declarative HTTPRoute Canary with Automated Rollback Hook

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Relies on deprecated, proprietary NGINX ingress annotations without SLO validation. If the canary emits 500 errors, there is no automated rollback trigger, risking customer-facing failure during the 20% traffic shift.
```yaml
# Anti-Pattern: Vendor-locked Ingress annotations with manual, unvalidated canary weights
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: payment-service-canary
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/canary: "true"
    nginx.ingress.kubernetes.io/canary-weight: "20"
spec:
  rules:
  - host: payments.internal.net
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: payment-service-canary
            port:
              number: 8080
```

#### Production Standard (Correct)
> **Standard**: Uses standard Kubernetes Gateway API v1 via Flagger progressive delivery. Ensures traffic weight increments iteratively (10% steps) and automatically rolls back if success rate drops below 99.5% or P99 latency exceeds 200ms.
```yaml
# Standard: Gateway API 1.2 HTTPRoute managed via Progressive Delivery (Flagger / Argo)
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
  name: payment-service
  namespace: production
spec:
  provider: gatewayapi:v1
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: payment-service
  service:
    port: 8080
    gatewayRefs:
      - name: production-gateway
        namespace: gateway-infra
  analysis:
    interval: 1m
    threshold: 3
    maxWeight: 50
    stepWeight: 10
    metrics:
      - name: request-success-rate
        thresholdRange:
          min: 99.5
        interval: 1m
      - name: p99-latency
        thresholdRange:
          max: 200
        interval: 1m
    webhooks:
      - name: smoke-test
        type: pre-rollout
        url: http://flagger-tester.test-tools/run
        timeout: 5s
        metadata:
          type: bash
          cmd: "curl -sd 'health' http://payment-service-canary:8080/health"
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Vendor-Neutral Declarative HTTPRoute Canary Shifting with Automated Rollback

Vendor-Neutral Declarative HTTPRoute Canary Shifting with Automated Rollback defines an industrial-grade behavioral standard for devops engineering. Enforces Gateway API 1.2 HTTPRoute declarative traffic splitting for progressive delivery, replacing vendor-locked ingress annotations. Requires automated metric validation thresholds (P99 latency, HTTP 5xx error budget burn) with strict rollback triggers before promoting canary weights. 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: Proprietary Ingress Annotations with Manual or Unvalidated Traffic Splitting 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 DriftProprietary Ingress Annotations with Manual or Unvalidated Traffic SplittingCritical
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 use `gateway.networking.k8s.io/v1` HTTPRoute resources for traffic distribution rather than vendor-specific ingress controller annotations.

Engineers MUST ALWAYS use `gateway.networking.k8s.io/v1` HTTPRoute resources for traffic distribution rather than vendor-specific ingress controller annotations.

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 configure declarative `backendRefs` with explicit integer `weight` fields that sum up to 100 across stable and canary targets.

Engineers MUST configure declarative `backendRefs` with explicit integer `weight` fields that sum up to 100 across stable and canary targets.

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 NOT mutate production `HTTPRoute` weights manually in live clusters without an automated progressive delivery controller evaluating real-time metrics.

Engineers MUST NOT mutate production `HTTPRoute` weights manually in live clusters without an automated progressive delivery controller evaluating real-time metrics.

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 automated rollback triggers linked to Prometheus/Datadog metrics (e.g., HTTP 5xx rate > 1%, P99 latency > target SLA) evaluated on every progression step.

Services MUST define automated rollback triggers linked to Prometheus/Datadog metrics (e.g., HTTP 5xx rate > 1%, P99 latency > target SLA) evaluated on every progression step.

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

Components NEVER route traffic to canary pods before readiness probes pass and active synthetic smoke tests execute against the canary backendRef filter.

Components NEVER route traffic to canary pods before readiness probes pass and active synthetic smoke tests execute against the canary backendRef filter.

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 Vendor-Neutral Declarative HTTPRoute Canary Shifting with Automated Rollback critical for AI coding assistants?

Enforces Gateway API 1.2 HTTPRoute declarative traffic splitting for progressive delivery, replacing vendor-locked ingress annotations. Requires automated metric validation thresholds (P99 latency, HTTP 5xx error budget burn) with strict rollback triggers before promoting canary weights. 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 (Proprietary Ingress Annotations with Manual or Unvalidated Traffic Splitting) 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

Vendor-Neutral