Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add use-cluster-ip annotation for ingress resources #4862

Merged
merged 11 commits into from
Jan 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ The table below summarizes the available annotations.
|``nginx.com/health-checks-mandatory`` | N/A | Configures active health checks as mandatory. | ``False`` | [Support for Active Health Checks](https://github.com/nginxinc/kubernetes-ingress/tree/v3.4.0/examples/ingress-resources/health-checks). |
|``nginx.com/health-checks-mandatory-queue`` | N/A | When active health checks are mandatory, creates a queue where incoming requests are temporarily stored while NGINX Plus is checking the health of the endpoints after a configuration reload. | ``0`` | [Support for Active Health Checks](https://github.com/nginxinc/kubernetes-ingress/tree/v3.4.0/examples/ingress-resources/health-checks). |
|``nginx.com/slow-start`` | N/A | Sets the upstream server [slow-start period](https://docs.nginx.com/nginx/admin-guide/load-balancer/http-load-balancer/#server-slow-start). By default, slow-start is activated after a server becomes [available](https://docs.nginx.com/nginx/admin-guide/load-balancer/http-health-check/#passive-health-checks) or [healthy](https://docs.nginx.com/nginx/admin-guide/load-balancer/http-health-check/#active-health-checks). To enable slow-start for newly-added servers, configure [mandatory active health checks](https://github.com/nginxinc/kubernetes-ingress/tree/v3.4.0/examples/ingress-resources/health-checks). | ``"0s"`` | |
|``nginx.org/use-cluster-ip`` | N/A | Enables using the Cluster IP and port of the service instead of the default behavior of using the IP and port of the pods. When this field is enabled, the fields that configure NGINX behavior related to multiple upstream servers (like ``lb-method`` and ``next-upstream``) will have no effect, as the Ingress Controller will configure NGINX with only one upstream server that will match the service Cluster IP. | ``False`` | |
j1m-ryan marked this conversation as resolved.
Show resolved Hide resolved
{{% /table %}}

### Snippets and Custom Templates
Expand Down
2 changes: 1 addition & 1 deletion docs/content/tutorials/nginx-ingress-istio.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ We can see in the above output that our curl request is sent and received by NGI

By default, for NGINX Ingress Controller, we populate the upstream server addresses with the endpoint IPs of the pods.

When using the new `use-cluster-ip` feature, we will no populate the upstream with the `service` IP address, instead of the endpoint IP addresses.
When using the new `use-cluster-ip` feature, we will now populate the upstream with the `service` IP address, instead of the endpoint IP addresses.

In the 1.11 release, NGINX Ingress controller will only send one host header, depending on how you configure Ingress. By default NGINX Ingress Controller will send `proxy_set_header $host`. If Ingress has been configured with `action.proxy.requestHeaders` this ensures that only one set of headers will be sent to the upstream server. In summary, by setting `action.proxy.requestHeaders` in the `VirtualServer` CRD, NGINX Ingress will only send the specified headers that have been defined.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ apiVersion: v1
kind: Service
metadata:
name: tea-svc
labels:
spec:
ports:
- port: 80
Expand Down
12 changes: 12 additions & 0 deletions internal/configs/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// PathRegexAnnotation is the annotation where the regex location (path) modifier is specified.
const PathRegexAnnotation = "nginx.org/path-regex"

// UseClusterIPAnnotation is the annotation where the use-cluster-ip boolean is specified.
const UseClusterIPAnnotation = "nginx.org/use-cluster-ip"

// AppProtectPolicyAnnotation is where the NGINX App Protect policy is specified
const AppProtectPolicyAnnotation = "appprotect.f5.com/app-protect-policy"

Expand All @@ -37,6 +40,7 @@
"nginx.com/health-checks": true,
"nginx.com/health-checks-mandatory": true,
"nginx.com/health-checks-mandatory-queue": true,
UseClusterIPAnnotation: true,
}

var minionBlacklist = map[string]bool{
Expand Down Expand Up @@ -401,6 +405,14 @@
glog.Errorf("Ingress %s/%s: Invalid value nginx.org/path-regex: got %q. Allowed values: 'case_sensitive', 'case_insensitive', 'exact'", ingEx.Ingress.GetNamespace(), ingEx.Ingress.GetName(), pathRegex)
}
}

if useClusterIP, exists, err := GetMapKeyAsBool(ingEx.Ingress.Annotations, UseClusterIPAnnotation, ingEx.Ingress); exists {
if err != nil {
glog.Error(err)
} else {
cfgParams.UseClusterIP = useClusterIP
}

Check warning on line 414 in internal/configs/annotations.go

View check run for this annotation

Codecov / codecov/patch

internal/configs/annotations.go#L410-L414

Added lines #L410 - L414 were not covered by tests
}
return cfgParams
}

Expand Down
1 change: 1 addition & 0 deletions internal/configs/config_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type ConfigParams struct {
SlowStart string
SSLRedirect bool
UpstreamZoneSize string
UseClusterIP bool
VariablesHashBucketSize uint64
VariablesHashMaxSize uint64

Expand Down
26 changes: 19 additions & 7 deletions internal/configs/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,21 +511,33 @@
endps = []string{}
}

for _, endp := range endps {
if cfg.UseClusterIP {
upsServers = append(upsServers, version1.UpstreamServer{
Address: endp,
Address: fmt.Sprintf("%s:%d", backend.Service.Name, backend.Service.Port.Number),

Check warning on line 516 in internal/configs/ingress.go

View check run for this annotation

Codecov / codecov/patch

internal/configs/ingress.go#L516

Added line #L516 was not covered by tests
MaxFails: cfg.MaxFails,
MaxConns: cfg.MaxConns,
FailTimeout: cfg.FailTimeout,
SlowStart: cfg.SlowStart,
Resolve: isExternalNameSvc,
})
}
if len(upsServers) > 0 {
sort.Slice(upsServers, func(i, j int) bool {
return upsServers[i].Address < upsServers[j].Address
})
ups.UpstreamServers = upsServers
} else {
for _, endp := range endps {
upsServers = append(upsServers, version1.UpstreamServer{
Address: endp,
MaxFails: cfg.MaxFails,
MaxConns: cfg.MaxConns,
FailTimeout: cfg.FailTimeout,
SlowStart: cfg.SlowStart,
Resolve: isExternalNameSvc,
})
}
if len(upsServers) > 0 {
sort.Slice(upsServers, func(i, j int) bool {
return upsServers[i].Address < upsServers[j].Address
})

Check warning on line 538 in internal/configs/ingress.go

View check run for this annotation

Codecov / codecov/patch

internal/configs/ingress.go#L537-L538

Added lines #L537 - L538 were not covered by tests
ups.UpstreamServers = upsServers
}
}
}

Expand Down
Loading