Skip to content

Commit fef7d3e

Browse files
authored
Preserve client IPs and bump NGINX replicas (#848)
<!-- Provide a brief summary of your changes --> ## Motivation and Context <!-- Why is this change needed? What problem does it solve? --> A few changes related to configuring the rate limiting: * Set `externalTrafficPolicy: Local` to preserve real client IPs (otherwise we only see the cluster IPs) * Disable `use-forwarded-headers` (L4 LB doesn't set `X-Forwarded-For`, prevents spoofing) * Scale NGINX to 2 replicas in prod (costs nothing, gives us zero-downtime deploys to prod) ## How Has This Been Tested? <!-- Have you tested this in a real application? Which scenarios were tested? --> ## Breaking Changes <!-- Will users need to update their code or configurations? --> ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [ ] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [ ] My code follows the repository's style guidelines - [ ] New and existing tests pass locally - [ ] I have added appropriate error handling - [ ] I have added or updated documentation as needed ## Additional context <!-- Add any other context, implementation notes, or design decisions --> Signed-off-by: Radoslav Dimitrov <[email protected]>
1 parent 7cfd3f0 commit fef7d3e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

deploy/pkg/k8s/ingress.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ func SetupIngressController(ctx *pulumi.Context, cluster *providers.ProviderInfo
4040
return "LoadBalancer"
4141
}).(pulumi.StringOutput)
4242

43+
// Configure replicas based on environment
44+
// Staging: 1 replica (sufficient for testing, allows brief downtime during deploys)
45+
// Production: 2 replicas (HA, zero-downtime deploys, node-level resilience)
46+
replicaCount := 1
47+
if environment == "prod" {
48+
replicaCount = 2
49+
}
50+
4351
// Install NGINX Ingress Controller
4452
ingressNginx, err := helm.NewChart(ctx, "ingress-nginx", helm.ChartArgs{
4553
Chart: pulumi.String("ingress-nginx"),
@@ -50,18 +58,22 @@ func SetupIngressController(ctx *pulumi.Context, cluster *providers.ProviderInfo
5058
Namespace: ingressNginxNamespace.Metadata.Name().Elem(),
5159
Values: pulumi.Map{
5260
"controller": pulumi.Map{
61+
"replicaCount": pulumi.Int(replicaCount),
5362
"service": pulumi.Map{
54-
"type": serviceType,
55-
"annotations": pulumi.Map{},
63+
"type": serviceType,
64+
"externalTrafficPolicy": pulumi.String("Local"),
65+
"annotations": pulumi.Map{},
5666
},
5767
"config": pulumi.Map{
5868
// Disable strict path validation, to work around a bug in ingress-nginx
5969
// https://cert-manager.io/docs/releases/release-notes/release-notes-1.18/#acme-http01-challenge-paths-now-use-pathtype-exact-in-ingress-routes
6070
// https://github.com/kubernetes/ingress-nginx/issues/11176
6171
"strict-validate-path-type": pulumi.String("false"),
6272

63-
// Use forwarded headers for proper client IP handling
64-
"use-forwarded-headers": pulumi.String("true"),
73+
// Do NOT use forwarded headers with L4 load balancer
74+
// GCP L4 Passthrough Network Load Balancer does not set X-Forwarded-For
75+
// Real client IP comes from TCP connection source with externalTrafficPolicy: Local
76+
"use-forwarded-headers": pulumi.String("false"),
6577
},
6678
},
6779
},

0 commit comments

Comments
 (0)