|
| 1 | +--- |
| 2 | +title: "HTTP Scaling for Ingress-Based Applications" |
| 3 | +weight: 3 |
| 4 | +layout: "learningpathall" |
| 5 | +--- |
| 6 | + |
| 7 | +Use this section to get a quick, hands-on feel for Kedify HTTP autoscaling. We’ll deploy a small web service, expose it through a standard Kubernetes Ingress, and rely on Kedify’s autowiring to route traffic via its proxy so requests are measured and drive scaling. |
| 8 | + |
| 9 | +Scale a real HTTP app exposed through Kubernetes Ingress using Kedify’s [kedify-http](https://docs.kedify.io/scalers/http-scaler/) scaler. You will deploy a simple app, enable autoscaling with a [ScaledObject](https://keda.sh/docs/latest/concepts/scaling-deployments/), generate load, and observe the system scale out and back in (including scale-to-zero when idle). |
| 10 | + |
| 11 | +## How it works |
| 12 | + |
| 13 | +With ingress autowiring enabled, Kedify automatically routes traffic through its proxy before it reaches your Service/Deployment: |
| 14 | + |
| 15 | +``` |
| 16 | +Ingress → kedify-proxy → Service → Deployment |
| 17 | +``` |
| 18 | + |
| 19 | +The [Kedify Proxy](https://docs.kedify.io/scalers/http-scaler/#kedify-proxy) gathers request metrics used by the scaler to make decisions. |
| 20 | + |
| 21 | +## What you’ll deploy |
| 22 | + |
| 23 | +- Deployment & Service: an HTTP server with a small response delay to simulate work |
| 24 | +- Ingress: public entry using host `application.keda` |
| 25 | +- ScaledObject: Kedify HTTP scaler with `trafficAutowire: ingress` |
| 26 | + |
| 27 | +## Step 1 — Create the application and Ingress |
| 28 | + |
| 29 | +Save the following as `application.yaml` and apply it: |
| 30 | + |
| 31 | +```bash |
| 32 | +kubectl apply -f application.yaml |
| 33 | +``` |
| 34 | + |
| 35 | +```yaml |
| 36 | +# application.yaml |
| 37 | +apiVersion: apps/v1 |
| 38 | +kind: Deployment |
| 39 | +metadata: |
| 40 | + name: application |
| 41 | +spec: |
| 42 | + replicas: 1 |
| 43 | + selector: |
| 44 | + matchLabels: |
| 45 | + app: application |
| 46 | + template: |
| 47 | + metadata: |
| 48 | + labels: |
| 49 | + app: application |
| 50 | + spec: |
| 51 | + containers: |
| 52 | + - name: application |
| 53 | + image: ghcr.io/kedify/sample-http-server:latest |
| 54 | + imagePullPolicy: Always |
| 55 | + ports: |
| 56 | + - name: http |
| 57 | + containerPort: 8080 |
| 58 | + protocol: TCP |
| 59 | + env: |
| 60 | + - name: RESPONSE_DELAY |
| 61 | + value: '0.3' |
| 62 | +--- |
| 63 | +apiVersion: v1 |
| 64 | +kind: Service |
| 65 | +metadata: |
| 66 | + name: application-service |
| 67 | +spec: |
| 68 | + ports: |
| 69 | + - name: http |
| 70 | + protocol: TCP |
| 71 | + port: 8080 |
| 72 | + targetPort: http |
| 73 | + selector: |
| 74 | + app: application |
| 75 | + type: ClusterIP |
| 76 | +--- |
| 77 | +apiVersion: networking.k8s.io/v1 |
| 78 | +kind: Ingress |
| 79 | +metadata: |
| 80 | + name: application-ingress |
| 81 | +spec: |
| 82 | + rules: |
| 83 | + - host: application.keda |
| 84 | + http: |
| 85 | + paths: |
| 86 | + - path: / |
| 87 | + pathType: Prefix |
| 88 | + backend: |
| 89 | + service: |
| 90 | + name: application-service |
| 91 | + port: |
| 92 | + number: 8080 |
| 93 | +``` |
| 94 | + |
| 95 | +Notes: |
| 96 | +- `RESPONSE_DELAY` adds ~300ms latency per request, making scaling effects easier to see. |
| 97 | +- The Ingress uses host `application.keda`. If you don’t have DNS set up, use your ingress controller’s IP with a `Host:` header (shown below). |
| 98 | + |
| 99 | +## Step 2 — Enable autoscaling with Kedify |
| 100 | + |
| 101 | +Save the following as `scaledobject.yaml` and apply it: |
| 102 | + |
| 103 | +```bash |
| 104 | +kubectl apply -f scaledobject.yaml |
| 105 | +``` |
| 106 | + |
| 107 | +```yaml |
| 108 | +# scaledobject.yaml |
| 109 | +kind: ScaledObject |
| 110 | +apiVersion: keda.sh/v1alpha1 |
| 111 | +metadata: |
| 112 | + name: application |
| 113 | +spec: |
| 114 | + scaleTargetRef: |
| 115 | + apiVersion: apps/v1 |
| 116 | + kind: Deployment |
| 117 | + name: application |
| 118 | + cooldownPeriod: 5 |
| 119 | + minReplicaCount: 0 |
| 120 | + maxReplicaCount: 10 |
| 121 | + fallback: |
| 122 | + failureThreshold: 2 |
| 123 | + replicas: 1 |
| 124 | + advanced: |
| 125 | + restoreToOriginalReplicaCount: true |
| 126 | + horizontalPodAutoscalerConfig: |
| 127 | + behavior: |
| 128 | + scaleDown: |
| 129 | + stabilizationWindowSeconds: 5 |
| 130 | + triggers: |
| 131 | + - type: kedify-http |
| 132 | + metadata: |
| 133 | + hosts: application.keda |
| 134 | + pathPrefixes: / |
| 135 | + service: application-service |
| 136 | + port: '8080' |
| 137 | + scalingMetric: requestRate |
| 138 | + targetValue: '1000' |
| 139 | + granularity: 1s |
| 140 | + window: 10s |
| 141 | + trafficAutowire: ingress |
| 142 | +``` |
| 143 | + |
| 144 | +What the key fields do: |
| 145 | +- `type: kedify-http` — Use Kedify’s HTTP scaler. |
| 146 | +- `hosts`, `pathPrefixes` — Which requests to observe for scaling. |
| 147 | +- `service`, `port` — The Service and port receiving traffic. |
| 148 | +- `scalingMetric: requestRate` and `targetValue: 1000` — Target 1000 req/s (per granularity/window) before scaling out. |
| 149 | +- `minReplicaCount: 0` — Allows scale-to-zero when idle. |
| 150 | +- `trafficAutowire: ingress` — Lets Kedify auto-wire your Ingress to the kedify-proxy. |
| 151 | + |
| 152 | +After applying, the ScaledObject will appear in the Kedify dashboard (https://dashboard.kedify.io/). |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | +## Step 3 — Send traffic and observe scaling |
| 157 | + |
| 158 | +First, hit the app to confirm routing works. Replace the address with your ingress endpoint if needed: |
| 159 | + |
| 160 | +```bash |
| 161 | +curl -I -H "Host: application.keda" http://localhost:9080 |
| 162 | +``` |
| 163 | + |
| 164 | +You should see a 200 OK response. Next, generate sustained load. You can use `hey` (or a similar tool): |
| 165 | + |
| 166 | +```bash |
| 167 | +hey -n 10000 -c 150 -host "application.keda" http://localhost:9080 |
| 168 | +``` |
| 169 | + |
| 170 | +While the load runs, watch replicas change: |
| 171 | + |
| 172 | +```bash |
| 173 | +kubectl get deploy application -w |
| 174 | +``` |
| 175 | + |
| 176 | +Expected behavior: |
| 177 | +- On bursty load, Kedify scales the Deployment up toward `maxReplicaCount`. |
| 178 | +- When traffic subsides, replicas scale down. After the cooldown, they can return to zero. |
| 179 | + |
| 180 | +You can also observe traffic and scaling in the Kedify dashboard: |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | +## Clean up |
| 185 | + |
| 186 | +```bash |
| 187 | +kubectl delete -f scaledobject.yaml |
| 188 | +kubectl delete -f application.yaml |
| 189 | +``` |
| 190 | + |
| 191 | +## Next steps |
| 192 | + |
| 193 | +Explore the official Kedify [How-to guides](https://docs.kedify.io/how-to/) for more configurations such as Gateway API, Istio VirtualService, or OpenShift Routes. |
| 194 | + |
| 195 | +### See also |
| 196 | + |
| 197 | +- Kedify documentation: https://docs.kedify.io |
0 commit comments