# azure/application-gateway-kubernetes-ingress architecture

> Architecture diagram of the GitHub repository azure/application-gateway-kubernetes-ingress, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azure/application-gateway-kubernetes-ingress
- Repository: https://github.com/azure/application-gateway-kubernetes-ingress

## Overview

AGIC watches selected Kubernetes resources, converts ingress intent into Application Gateway configuration, and reconciles that configuration with Azure ARM. Ingress events are queued and processed by a worker/controller; gateway configuration covers routing, TLS, affinity, and other L7 behavior. Brownfield handling preserves or filters existing gateway resources, while separate code supports Istio, multicluster resources, CNI reconciliation, metrics, and health endpoints. The README documents the core workflow and features; several subsystem links below are omitted where sampled source does not show their runtime wiring.

Main entry points: [`pkg/controller/controller.go`](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/controller/controller.go) (Ingress controller), [`cmd/appgw-ingress/main.go`](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/cmd/appgw-ingress/main.go) (AGIC process), [`pkg/k8scontext/context.go`](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/k8scontext/context.go) (Resource context), [`pkg/appgw/configbuilder.go`](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/appgw/configbuilder.go) (Gateway config builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Kubernetes inputs"]
  node_k8s[("Kubernetes resources")]
  node_apis["Custom resource APIs"]
  node_context["Resource context<br/>[context.go]"]
  node_handlers["Ingress handlers"]
  node_annotations["Ingress annotations"]
  node_multicluster["Multicluster integration<br/>[clientset.go]"]
end

subgraph group_reconcile["Reconciliation"]
  node_events["Event queue<br/>[events.go]"]
  node_worker["Event worker<br/>[worker.go]"]
  node_controller["Ingress controller<br/>[controller.go]"]
  node_pruning["Brownfield pruning<br/>[prune.go]"]
end

subgraph group_gateway["Gateway configuration"]
  node_brownfield["Existing gateway state<br/>[routing_rules.go]"]
  node_builder["Gateway config builder<br/>[configbuilder.go]"]
  node_routing["Routing rules"]
  node_azure["Azure client<br/>[client.go]"]
  node_istio["Istio integration<br/>[istio_config.go]"]
end

subgraph group_operations["Operations"]
  node_cni["CNI reconciliation<br/>[cni.go]"]
  node_metrics[("Metrics store<br/>[metricstore.go]")]
  node_http["Health and metrics HTTP<br/>[httpserver.go]"]
  node_entry["AGIC process<br/>[main.go]"]
end

node_operator(("Cluster operator"))
node_arm[("Azure Resource Manager")]

node_operator -->|"defines resources"| node_k8s
node_k8s -->|"monitors changes"| node_context
node_context -.->|"dispatches events"| node_handlers
node_handlers -->|"queues changes"| node_events
node_annotations -->|"configures routing"| node_routing
node_events -->|"supplies work"| node_worker
node_controller -->|"starts context"| node_context
node_controller -->|"reconciles CNI"| node_cni
node_controller -->|"gets gateway"| node_azure
node_worker -.->|"processes events"| node_controller
node_controller -.->|"builds configuration"| node_builder
node_controller -.->|"prunes resources"| node_pruning
node_pruning -->|"filters existing rules"| node_brownfield
node_builder -->|"builds routing"| node_routing
node_azure -->|"updates gateway"| node_arm
node_entry -->|"starts controller"| node_controller
node_entry -->|"constructs context"| node_context
node_entry -->|"starts server"| node_http
node_entry -->|"starts metrics"| node_metrics
node_entry -->|"creates client"| node_multicluster
node_context -->|"uses resource types"| node_apis
node_builder -.->|"supports Istio"| node_istio
node_http -->|"exposes metrics"| node_metrics

click node_apis "https://github.com/azure/application-gateway-kubernetes-ingress/tree/master/pkg/apis"
click node_context "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/k8scontext/context.go"
click node_handlers "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/k8scontext/ingress_handlers.go"
click node_annotations "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/annotations/ingress_annotations.go"
click node_events "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/events/events.go"
click node_worker "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/worker/worker.go"
click node_controller "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/controller/controller.go"
click node_pruning "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/controller/prune.go"
click node_brownfield "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/brownfield/routing_rules.go"
click node_builder "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/appgw/configbuilder.go"
click node_routing "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/appgw/requestroutingrules.go"
click node_azure "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/azure/client.go"
click node_istio "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/appgw/istio_config.go"
click node_multicluster "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/crd_client/azure_multicluster_crd_client/clientset/versioned/clientset.go"
click node_cni "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/cni/cni.go"
click node_metrics "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/metricstore/metricstore.go"
click node_http "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/httpserver/httpserver.go"
click node_entry "https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/cmd/appgw-ingress/main.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_k8s,node_apis,node_context,node_handlers,node_annotations,node_multicluster toneBlue
class node_events,node_worker,node_controller,node_pruning,node_arm toneAmber
class node_brownfield,node_builder,node_routing,node_azure,node_istio toneMint
class node_cni,node_metrics,node_http,node_entry toneRose
class node_operator toneIndigo
```

## Components

### Kubernetes inputs

- **Kubernetes resources**
- [Custom resource APIs](https://github.com/azure/application-gateway-kubernetes-ingress/tree/master/pkg/apis): `pkg/apis`
- [Resource context](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/k8scontext/context.go): `pkg/k8scontext/context.go`
- [Ingress handlers](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/k8scontext/ingress_handlers.go): `pkg/k8scontext/ingress_handlers.go`
- [Ingress annotations](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/annotations/ingress_annotations.go): `pkg/annotations/ingress_annotations.go`
- [Multicluster integration](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/crd_client/azure_multicluster_crd_client/clientset/versioned/clientset.go): `pkg/crd_client/azure_multicluster_crd_client/clientset/versioned/clientset.go`

### Reconciliation

- [Event queue](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/events/events.go): `pkg/events/events.go`
- [Event worker](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/worker/worker.go): `pkg/worker/worker.go`
- [Ingress controller](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/controller/controller.go): `pkg/controller/controller.go`
- [Brownfield pruning](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/controller/prune.go): `pkg/controller/prune.go`

### Gateway configuration

- [Existing gateway state](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/brownfield/routing_rules.go): `pkg/brownfield/routing_rules.go`
- [Gateway config builder](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/appgw/configbuilder.go): `pkg/appgw/configbuilder.go`
- [Routing rules](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/appgw/requestroutingrules.go): `pkg/appgw/requestroutingrules.go`
- [Azure client](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/azure/client.go): `pkg/azure/client.go`
- [Istio integration](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/appgw/istio_config.go): `pkg/appgw/istio_config.go`

### Operations

- [CNI reconciliation](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/cni/cni.go): `pkg/cni/cni.go`
- [Metrics store](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/metricstore/metricstore.go): `pkg/metricstore/metricstore.go`
- [Health and metrics HTTP](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/pkg/httpserver/httpserver.go): `pkg/httpserver/httpserver.go`
- [AGIC process](https://github.com/azure/application-gateway-kubernetes-ingress/blob/master/cmd/appgw-ingress/main.go): `cmd/appgw-ingress/main.go`

### Other components

- **Cluster operator**
- **Azure Resource Manager**

## Connections

- Cluster operator → Kubernetes resources: defines resources (evidence: `README.md`)
- Kubernetes resources → Resource context: monitors changes (evidence: `README.md`)
- Resource context → Ingress handlers: dispatches events
- Ingress handlers → Event queue: queues changes (evidence: `pkg/k8scontext/ingress_handlers.go`)
- Ingress annotations → Routing rules: configures routing (evidence: `pkg/appgw/requestroutingrules.go`)
- Event queue → Event worker: supplies work (evidence: `pkg/worker/worker.go`)
- Ingress controller → Resource context: starts context (evidence: `pkg/controller/controller.go`)
- Ingress controller → CNI reconciliation: reconciles CNI (evidence: `pkg/controller/controller.go`)
- Ingress controller → Azure client: gets gateway (evidence: `pkg/controller/controller.go`)
- Event worker → Ingress controller: processes events
- Ingress controller → Gateway config builder: builds configuration
- Ingress controller → Brownfield pruning: prunes resources
- Brownfield pruning → Existing gateway state: filters existing rules (evidence: `pkg/controller/prune.go`)
- Gateway config builder → Routing rules: builds routing (evidence: `pkg/appgw/requestroutingrules.go`)
- Azure client → Azure Resource Manager: updates gateway (evidence: `pkg/azure/client.go`)
- AGIC process → Ingress controller: starts controller (evidence: `cmd/appgw-ingress/main.go`)
- AGIC process → Resource context: constructs context (evidence: `cmd/appgw-ingress/main.go`)
- AGIC process → Health and metrics HTTP: starts server (evidence: `cmd/appgw-ingress/main.go`)
- AGIC process → Metrics store: starts metrics (evidence: `cmd/appgw-ingress/main.go`)
- AGIC process → Multicluster integration: creates client (evidence: `cmd/appgw-ingress/main.go`)
- Resource context → Custom resource APIs: uses resource types (evidence: `pkg/k8scontext/context.go`)
- Gateway config builder → Istio integration: supports Istio
- Health and metrics HTTP → Metrics store: exposes metrics (evidence: `pkg/httpserver/httpserver.go`)
