|
| 1 | +# Configuration Flow |
| 2 | + |
| 3 | +This diagram shows how Gateway API resources map to NGINX configurations. |
| 4 | + |
| 5 | +## Simple Overview |
| 6 | + |
| 7 | +```mermaid |
| 8 | +%%{init: {'theme':'dark', 'themeVariables': {'fontSize': '16px', 'darkMode': true, 'primaryColor': '#4f46e5', 'primaryTextColor': '#e5e7eb', 'primaryBorderColor': '#6b7280', 'lineColor': '#9ca3af', 'secondaryColor': '#1f2937', 'tertiaryColor': '#374151', 'background': '#111827', 'mainBkg': '#1f2937', 'secondBkg': '#374151', 'tertiaryTextColor': '#d1d5db'}}}%% |
| 9 | +graph TB |
| 10 | + %% User Actions |
| 11 | + USER[👤 User] --> K8S |
| 12 | +
|
| 13 | + %% Kubernetes API Layer |
| 14 | + subgraph "Kubernetes API" |
| 15 | + K8S[🔵 API Server] |
| 16 | + GW[Gateway] |
| 17 | + ROUTE[HTTPRoute] |
| 18 | + SVC[Service] |
| 19 | + end |
| 20 | +
|
| 21 | + %% Control Plane |
| 22 | + subgraph "Control Plane Pod" |
| 23 | + NGF[🎯 NGF Controller] |
| 24 | + end |
| 25 | +
|
| 26 | + %% Data Plane |
| 27 | + subgraph "Data Plane Pod" |
| 28 | + AGENT[🔧 NGINX Agent] |
| 29 | + NGINX[🌐 NGINX] |
| 30 | + CONF[nginx.conf] |
| 31 | + end |
| 32 | +
|
| 33 | + %% Flow |
| 34 | + K8S --> NGF |
| 35 | + GW --> NGF |
| 36 | + ROUTE --> NGF |
| 37 | + SVC --> NGF |
| 38 | +
|
| 39 | + NGF --> AGENT |
| 40 | + AGENT --> CONF |
| 41 | + CONF --> NGINX |
| 42 | +
|
| 43 | + %% Dark-friendly styling |
| 44 | + style USER fill:#fbbf24,stroke:#f59e0b,stroke-width:2px,color:#1f2937 |
| 45 | + style NGF fill:#3b82f6,stroke:#2563eb,stroke-width:2px,color:#ffffff |
| 46 | + style NGINX fill:#8b5cf6,stroke:#7c3aed,stroke-width:2px,color:#ffffff |
| 47 | + style K8S fill:#6b7280,stroke:#4b5563,stroke-width:2px,color:#ffffff |
| 48 | +``` |
| 49 | + |
| 50 | +## Step-by-Step Process |
| 51 | + |
| 52 | +### 1. User Creates Resources |
| 53 | + |
| 54 | +```yaml |
| 55 | +# User applies Gateway API resources |
| 56 | +apiVersion: gateway.networking.k8s.io/v1 |
| 57 | +kind: Gateway |
| 58 | +metadata: |
| 59 | + name: my-gateway |
| 60 | +``` |
| 61 | +
|
| 62 | +### 2. Kubernetes Stores Resources |
| 63 | +
|
| 64 | +- Gateway, HTTPRoute, Service resources stored in etcd |
| 65 | +- Kubernetes API Server notifies controllers(watchers) of changes |
| 66 | +
|
| 67 | +### 3. NGF Controller Processes Changes |
| 68 | +
|
| 69 | +```text |
| 70 | +NGF Controller: |
| 71 | +├── Watches Gateway API resources |
| 72 | +├── Validates configurations |
| 73 | +├── Builds internal config graph |
| 74 | +└── Generates NGINX configuration |
| 75 | +``` |
| 76 | + |
| 77 | +### 4. Configuration Sent to Data Plane |
| 78 | + |
| 79 | +```text |
| 80 | +Control Plane → Data Plane: |
| 81 | +├── gRPC connection (secure) |
| 82 | +├── nginx.conf file contents |
| 83 | +├── SSL certificates |
| 84 | +└── Other config files |
| 85 | +``` |
| 86 | + |
| 87 | +### 5. NGINX Agent Updates Configuration |
| 88 | + |
| 89 | +```text |
| 90 | +NGINX Agent: |
| 91 | +├── Receives config from control plane |
| 92 | +├── Validates NGINX syntax |
| 93 | +├── Writes files to disk |
| 94 | +├── Tests configuration |
| 95 | +└── Reloads NGINX (if valid) |
| 96 | +``` |
| 97 | + |
| 98 | +## Detailed Configuration Flow |
| 99 | + |
| 100 | +```mermaid |
| 101 | +%%{init: {'theme':'dark', 'themeVariables': {'fontSize': '14px', 'darkMode': true, 'primaryColor': '#4f46e5', 'primaryTextColor': '#e5e7eb', 'primaryBorderColor': '#6b7280', 'lineColor': '#9ca3af', 'secondaryColor': '#1f2937', 'tertiaryColor': '#374151', 'background': '#111827', 'actorBkg': '#374151', 'actorBorder': '#6b7280', 'actorTextColor': '#e5e7eb', 'activationBkgColor': '#4f46e5', 'activationBorderColor': '#3730a3', 'signalColor': '#9ca3af', 'signalTextColor': '#e5e7eb', 'labelBoxBkgColor': '#1f2937', 'labelBoxBorderColor': '#6b7280', 'labelTextColor': '#e5e7eb', 'loopTextColor': '#e5e7eb', 'noteBkgColor': '#374151', 'noteBorderColor': '#6b7280', 'noteTextColor': '#e5e7eb'}}}%% |
| 102 | +sequenceDiagram |
| 103 | + participant User |
| 104 | + participant API as K8s API |
| 105 | + participant NGF as NGF Controller |
| 106 | + participant Agent as NGINX Agent |
| 107 | + participant NGINX |
| 108 | +
|
| 109 | + User->>API: Apply Gateway/Route |
| 110 | + API->>NGF: Watch notification |
| 111 | + NGF->>NGF: Validate resources |
| 112 | + NGF->>NGF: Build config graph |
| 113 | + NGF->>NGF: Generate nginx.conf |
| 114 | + NGF->>Agent: Send config (gRPC) |
| 115 | + Agent->>Agent: Write config files |
| 116 | + Agent->>NGINX: Test config |
| 117 | + Agent->>NGINX: Reload (if valid) |
| 118 | + Agent->>NGF: Report status |
| 119 | + NGF->>API: Update resource status |
| 120 | +``` |
| 121 | + |
| 122 | +## What Gets Generated? |
| 123 | + |
| 124 | +### NGINX Configuration Files |
| 125 | + |
| 126 | +NGF generates various NGINX configuration files dynamically based on the Gateway API resources. |
| 127 | + |
| 128 | +### Example Generated Config |
| 129 | + |
| 130 | +```nginx |
| 131 | +# Generated from Gateway API resources |
| 132 | +server { |
| 133 | + listen 80; |
| 134 | + server_name api.example.com; |
| 135 | +
|
| 136 | + location /users { |
| 137 | + proxy_pass http://user-service; |
| 138 | + } |
| 139 | +
|
| 140 | + location /orders { |
| 141 | + proxy_pass http://order-service; |
| 142 | + } |
| 143 | +} |
| 144 | +``` |
| 145 | + |
| 146 | +## Error Handling |
| 147 | + |
| 148 | +### Invalid Configuration |
| 149 | + |
| 150 | +1. **NGF validates** Gateway API resources |
| 151 | +2. **NGINX Agent tests** generated config |
| 152 | +3. **Rollback** if configuration is invalid |
| 153 | +4. **Status updates** report errors to Kubernetes |
| 154 | + |
| 155 | +### Recovery Process |
| 156 | + |
| 157 | +- Keep last known good configuration |
| 158 | +- Report errors in resource status |
| 159 | +- Retry configuration updates |
| 160 | +- Graceful degradation when possible |
0 commit comments