|
1 | 1 | # Observability Stack Setup |
2 | 2 |
|
3 | 3 | This document outlines the steps to set up an observability stack using Loki, |
4 | | -Prometheus, and Grafana. |
| 4 | +Prometheus, and Grafana with Traefik Gateway API. |
| 5 | + |
| 6 | +## Architecture Notes |
| 7 | + |
| 8 | +**Ingress Controller:** Traefik with Kubernetes Gateway API (migrated from ingress-nginx in Nov 2025) |
| 9 | + |
| 10 | +**Why Gateway API?** |
| 11 | +- ingress-nginx retired (EOL: March 2026) |
| 12 | +- Gateway API is Kubernetes standard for traffic routing |
| 13 | +- Better separation of concerns (infrastructure vs application routing) |
| 14 | + |
| 15 | +**Key Components:** |
| 16 | +- **Gateway API v1.4.0**: Standard CRDs for traffic routing |
| 17 | +- **Traefik v3.6+**: Gateway API controller |
| 18 | +- **Gateway**: Defines HTTPS listener on port 8443 (internal), exposed as 443 externally |
| 19 | +- **HTTPRoutes**: Route `/grafana` and `/loki` to respective services |
| 20 | +- **Middlewares**: Request buffering (50MB limit), security headers |
5 | 21 |
|
6 | 22 | ## 1. Prerequisites & Initial Setup |
7 | 23 |
|
@@ -36,7 +52,7 @@ Prometheus, and Grafana. |
36 | 52 | Install and update necessary Helm chart repositories: |
37 | 53 |
|
38 | 54 | ```bash |
39 | | -helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx |
| 55 | +helm repo add traefik https://traefik.github.io/charts |
40 | 56 | helm repo add grafana https://grafana.github.io/helm-charts |
41 | 57 | helm repo add prometheus-community https://prometheus-community.github.io/helm-charts |
42 | 58 | helm repo update |
@@ -78,20 +94,41 @@ helm repo update |
78 | 94 | kubectl get deployment metrics-server -n kube-system |
79 | 95 | ``` |
80 | 96 |
|
81 | | -4. **NGINX Ingress Controller** _Create Namespace (if not present, though |
82 | | - usually handled by Helm):_ |
| 97 | +4. **Gateway API & Traefik** |
| 98 | +
|
| 99 | + _Install Gateway API CRDs:_ |
83 | 100 | ```bash |
84 | | - kubectl create namespace ingress-nginx # Optional, Helm might create it |
| 101 | + kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.4.0/standard-install.yaml |
85 | 102 | ``` |
86 | | - _Install:_ |
| 103 | +
|
| 104 | + _Verify CRDs:_ |
87 | 105 | ```bash |
88 | | - helm upgrade ingress-nginx ingress-nginx/ingress-nginx --namespace ingress-nginx --install -f charts/ingress-nginx/values.yaml |
| 106 | + kubectl get crd gateways.gateway.networking.k8s.io |
89 | 107 | ``` |
90 | | - _Verify:_ |
| 108 | +
|
| 109 | + _Install Traefik with Gateway API support:_ |
| 110 | + ```bash |
| 111 | + helm upgrade traefik traefik/traefik \ |
| 112 | + --namespace o11y \ |
| 113 | + --install \ |
| 114 | + --values charts/traefik/values.yaml \ |
| 115 | + --reuse-values=false |
| 116 | + ``` |
| 117 | +
|
| 118 | + _Deploy Gateway and HTTPRoutes:_ |
91 | 119 | ```bash |
92 | | - kubectl get pods -n ingress-nginx -l app.kubernetes.io/name=ingress-nginx |
| 120 | + kubectl apply -f k8s/gateway/gateway.yaml |
| 121 | + kubectl apply -f k8s/gateway/httproutes.yaml |
93 | 122 | ``` |
94 | 123 |
|
| 124 | + _Verify Gateway status:_ |
| 125 | + ```bash |
| 126 | + kubectl get gateway -n o11y o11y-gateway |
| 127 | + kubectl get httproute -n o11y |
| 128 | + ``` |
| 129 | +
|
| 130 | + Expected: Gateway PROGRAMMED = True, 2 HTTPRoutes (grafana-route, loki-route) |
| 131 | +
|
95 | 132 | ## 4. Observability Stack Deployment |
96 | 133 |
|
97 | 134 | 1. **Loki Deployment (Log Aggregation)** _Install:_ |
@@ -139,27 +176,44 @@ helm repo update |
139 | 176 | [Kubernetes cluster monitoring (via Prometheus) - ID 315](https://grafana.com/grafana/dashboards/315-kubernetes-cluster-monitoring-via-prometheus/) |
140 | 177 | or create your own. |
141 | 178 |
|
142 | | -## 5. Ingress & DNS Configuration |
| 179 | +## 5. Gateway & DNS Configuration |
| 180 | +
|
| 181 | +> **Note:** Gateway and HTTPRoutes are deployed in Step 3.4 above. This section covers DNS configuration only. |
143 | 182 |
|
144 | | -1. **Ingress Configuration (Grafana/Loki)** _Apply:_ |
| 183 | +1. **Verify Gateway Configuration** |
145 | 184 |
|
| 185 | + _Check Gateway status:_ |
146 | 186 | ```bash |
147 | | - kubectl apply -f k8s/ingress/o11y-ingress.yaml -n o11y |
| 187 | + kubectl get gateway -n o11y o11y-gateway |
148 | 188 | ``` |
| 189 | + Expected: `PROGRAMMED = True` |
149 | 190 |
|
150 | | - _Verify:_ |
151 | | -
|
| 191 | + _Check HTTPRoutes:_ |
152 | 192 | ```bash |
153 | | - kubectl get ingress -n o11y |
| 193 | + kubectl get httproute -n o11y |
154 | 194 | ``` |
| 195 | + Expected: 2 routes (grafana-route, loki-route) |
155 | 196 |
|
156 | 197 | 2. **DNS Configuration (Manual)** |
157 | | - 1. Get Load Balancer IP for the NGINX Ingress controller: |
| 198 | +
|
| 199 | + 1. Get Load Balancer IP for Traefik: |
158 | 200 | ```bash |
159 | | - kubectl get svc -n ingress-nginx ingress-nginx-controller -o jsonpath='{.status.loadBalancer.ingress[0].ip}' | cat |
| 201 | + kubectl get svc -n o11y traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}' |
| 202 | + echo |
| 203 | + ``` |
| 204 | +
|
| 205 | + 2. Update A record in Cloudflare for `o11y.freecodecamp.net` to point to the Traefik LoadBalancer IP. |
| 206 | +
|
| 207 | + 3. Test endpoints before DNS update (optional): |
| 208 | + ```bash |
| 209 | + TRAEFIK_IP=$(kubectl get svc -n o11y traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}') |
| 210 | +
|
| 211 | + # Test Grafana |
| 212 | + curl -k -H "Host: o11y.freecodecamp.net" https://$TRAEFIK_IP/grafana/api/health |
| 213 | +
|
| 214 | + # Test Loki |
| 215 | + curl -k -H "Host: o11y.freecodecamp.net" https://$TRAEFIK_IP/loki/api/v1/status/buildinfo |
160 | 216 | ``` |
161 | | - 2. Create an A record in Cloudflare for `o11y.freecodecamp.net` pointing to |
162 | | - the retrieved IP. |
163 | 217 |
|
164 | 218 | ## 6. Final Verification |
165 | 219 |
|
|
0 commit comments