Skip to content

Commit 9d6f746

Browse files
authored
Deep service insight endpoint (#3261)
Add Service Insight endpoint for Virtual Servers
1 parent b734e72 commit 9d6f746

File tree

25 files changed

+973
-22
lines changed

25 files changed

+973
-22
lines changed

cmd/nginx-ingress/flags.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ var (
139139
prometheusMetricsListenPort = flag.Int("prometheus-metrics-listen-port", 9113,
140140
"Set the port where the Prometheus metrics are exposed. [1024 - 65535]")
141141

142+
enableServiceInsight = flag.Bool("enable-service-insight", false,
143+
`Enable service insight for external load balancers. Requires -nginx-plus`)
144+
145+
serviceInsightTLSSecretName = flag.String("service-insight-tls-secret", "",
146+
`A Secret with a TLS certificate and key for TLS termination of the service insight.`)
147+
148+
serviceInsightListenPort = flag.Int("service-insight-listen-port", 9114,
149+
"Set the port where the Service Insight stats are exposed. Requires -nginx-plus. [1024 - 65535]")
150+
142151
enableCustomResources = flag.Bool("enable-custom-resources", true,
143152
"Enable custom resources")
144153

@@ -250,6 +259,11 @@ func parseFlags() {
250259
*enableLatencyMetrics = false
251260
}
252261

262+
if *enableServiceInsight && !*nginxPlus {
263+
glog.Warning("enable-service-insight flag support is for NGINX Plus, service insight endpoint will not be exposed")
264+
*enableServiceInsight = false
265+
}
266+
253267
if *enableCertManager && !*enableCustomResources {
254268
glog.Fatal("enable-cert-manager flag requires -enable-custom-resources")
255269
}
@@ -352,6 +366,11 @@ func validationChecks() {
352366
glog.Fatalf("Invalid value for ready-status-port: %v", readyStatusPortValidationError)
353367
}
354368

369+
healthProbePortValidationError := validatePort(*serviceInsightListenPort)
370+
if healthProbePortValidationError != nil {
371+
glog.Fatalf("Invalid value for service-insight-listen-port: %v", metricsPortValidationError)
372+
}
373+
355374
var err error
356375
allowedCIDRs, err = parseNginxStatusAllowCIDRs(*nginxStatusAllowCIDRs)
357376
if err != nil {

cmd/nginx-ingress/main.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/nginxinc/kubernetes-ingress/internal/configs"
1717
"github.com/nginxinc/kubernetes-ingress/internal/configs/version1"
1818
"github.com/nginxinc/kubernetes-ingress/internal/configs/version2"
19+
"github.com/nginxinc/kubernetes-ingress/internal/healthcheck"
1920
"github.com/nginxinc/kubernetes-ingress/internal/k8s"
2021
"github.com/nginxinc/kubernetes-ingress/internal/k8s/secrets"
2122
"github.com/nginxinc/kubernetes-ingress/internal/metrics"
@@ -120,6 +121,10 @@ func main() {
120121
transportServerValidator := cr_validation.NewTransportServerValidator(*enableTLSPassthrough, *enableSnippets, *nginxPlus)
121122
virtualServerValidator := cr_validation.NewVirtualServerValidator(cr_validation.IsPlus(*nginxPlus), cr_validation.IsDosEnabled(*appProtectDos), cr_validation.IsCertManagerEnabled(*enableCertManager), cr_validation.IsExternalDNSEnabled(*enableExternalDNS))
122123

124+
if *enableServiceInsight {
125+
createHealthProbeEndpoint(kubeClient, plusClient, cnf)
126+
}
127+
123128
lbcInput := k8s.NewLoadBalancerControllerInput{
124129
KubeClient: kubeClient,
125130
ConfClient: confClient,
@@ -446,6 +451,10 @@ func createGlobalConfigurationValidator() *cr_validation.GlobalConfigurationVali
446451
forbiddenListenerPorts[*prometheusMetricsListenPort] = true
447452
}
448453

454+
if *enableServiceInsight {
455+
forbiddenListenerPorts[*serviceInsightListenPort] = true
456+
}
457+
449458
return cr_validation.NewGlobalConfigurationValidator(forbiddenListenerPorts)
450459
}
451460

@@ -674,6 +683,22 @@ func createPlusAndLatencyCollectors(
674683
return plusCollector, syslogListener, lc
675684
}
676685

686+
func createHealthProbeEndpoint(kubeClient *kubernetes.Clientset, plusClient *client.NginxClient, cnf *configs.Configurator) {
687+
if !*enableServiceInsight {
688+
return
689+
}
690+
var serviceInsightSecret *api_v1.Secret
691+
var err error
692+
693+
if *serviceInsightTLSSecretName != "" {
694+
serviceInsightSecret, err = getAndValidateSecret(kubeClient, *serviceInsightTLSSecretName)
695+
if err != nil {
696+
glog.Fatalf("Error trying to get the service insight TLS secret %v: %v", *serviceInsightTLSSecretName, err)
697+
}
698+
}
699+
go healthcheck.RunHealthCheck(*serviceInsightListenPort, plusClient, cnf, serviceInsightSecret)
700+
}
701+
677702
func processGlobalConfiguration() {
678703
if *globalConfiguration != "" {
679704
_, _, err := k8s.ParseNamespaceName(*globalConfiguration)

deployments/deployment/nginx-plus-ingress.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ spec:
3232
containerPort: 8081
3333
- name: prometheus
3434
containerPort: 9113
35+
- name: service-insight
36+
containerPort: 9114
3537
readinessProbe:
3638
httpGet:
3739
path: /nginx-ready
@@ -75,4 +77,5 @@ spec:
7577
#- -report-ingress-status
7678
#- -external-service=nginx-ingress
7779
#- -enable-prometheus-metrics
80+
#- -enable-service-insight
7881
#- -global-configuration=$(POD_NAMESPACE)/nginx-configuration

deployments/helm-chart/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ Parameter | Description | Default
262262
`prometheus.port` | Configures the port to scrape the metrics. | 9113
263263
`prometheus.scheme` | Configures the HTTP scheme to use for connections to the Prometheus endpoint. | http
264264
`prometheus.secret` | The namespace / name of a Kubernetes TLS Secret. If specified, this secret is used to secure the Prometheus endpoint with TLS connections. | ""
265+
`serviceInsight.create` | Expose NGINX Plus Service Insight endpoint. | false
266+
`serviceInsight.port` | Configures the port to expose endpoints. | 9114
267+
`serviceInsight.scheme` | Configures the HTTP scheme to use for connections to the Service Insight endpoint. | http
268+
`serviceInsight.secret` | The namespace / name of a Kubernetes TLS Secret. If specified, this secret is used to secure the Service Insight endpoint with TLS connections. | ""
265269
`nginxServiceMesh.enable` | Enable integration with NGINX Service Mesh. See the NGINX Service Mesh [docs](https://docs.nginx.com/nginx-service-mesh/tutorials/kic/deploy-with-kic/) for more details. Requires `controller.nginxplus`. | false
266270
`nginxServiceMesh.enableEgress` | Enable NGINX Service Mesh workloads to route egress traffic through the Ingress Controller. See the NGINX Service Mesh [docs](https://docs.nginx.com/nginx-service-mesh/tutorials/kic/deploy-with-kic/#enabling-egress) for more details. Requires `nginxServiceMesh.enable`. | false
267271

deployments/helm-chart/templates/controller-daemonset.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ spec:
9494
- name: prometheus
9595
containerPort: {{ .Values.prometheus.port }}
9696
{{- end }}
97+
{{- if .Values.serviceInsight.create }}
98+
- name: service-insight
99+
containerPort: {{ .Values.serviceInsight.port }}
100+
{{- end }}
97101
{{- if .Values.controller.readyStatus.enable }}
98102
- name: readiness-port
99103
containerPort: {{ .Values.controller.readyStatus.port }}
@@ -199,6 +203,9 @@ spec:
199203
- -enable-prometheus-metrics={{ .Values.prometheus.create }}
200204
- -prometheus-metrics-listen-port={{ .Values.prometheus.port }}
201205
- -prometheus-tls-secret={{ .Values.prometheus.secret }}
206+
- -enable-service-insight={{ .Values.serviceInsight.create }}
207+
- -service-insight-listen-port={{ .Values.serviceInsight.port }}
208+
- -service-insight-tls-secret={{ .Values.serviceInsight.secret }}
202209
- -enable-custom-resources={{ .Values.controller.enableCustomResources }}
203210
- -enable-snippets={{ .Values.controller.enableSnippets }}
204211
- -include-year={{ .Values.controller.includeYear }}

deployments/helm-chart/templates/controller-deployment.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ spec:
9797
- name: prometheus
9898
containerPort: {{ .Values.prometheus.port }}
9999
{{- end }}
100+
{{- if .Values.serviceInsight.create }}
101+
- name: service-insight
102+
containerPort: {{ .Values.serviceInsight.port }}
103+
{{- end }}
100104
{{- if .Values.controller.readyStatus.enable }}
101105
- name: readiness-port
102106
containerPort: {{ .Values.controller.readyStatus.port }}
@@ -202,6 +206,9 @@ spec:
202206
- -enable-prometheus-metrics={{ .Values.prometheus.create }}
203207
- -prometheus-metrics-listen-port={{ .Values.prometheus.port }}
204208
- -prometheus-tls-secret={{ .Values.prometheus.secret }}
209+
- -enable-service-insight={{ .Values.serviceInsight.create }}
210+
- -service-insight-listen-port={{ .Values.serviceInsight.port }}
211+
- -service-insight-tls-secret={{ .Values.serviceInsight.secret }}
205212
- -enable-custom-resources={{ .Values.controller.enableCustomResources }}
206213
- -enable-snippets={{ .Values.controller.enableSnippets }}
207214
- -include-year={{ .Values.controller.includeYear }}

deployments/helm-chart/values.schema.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"controller",
88
"rbac",
99
"prometheus",
10+
"serviceInsight",
1011
"nginxServiceMesh"
1112
],
1213
"properties": {
@@ -1436,6 +1437,56 @@
14361437
}
14371438
]
14381439
},
1440+
"serviceInsight": {
1441+
"type": "object",
1442+
"default": {},
1443+
"title": "The Service Insight Schema",
1444+
"required": [
1445+
"create"
1446+
],
1447+
"properties": {
1448+
"create": {
1449+
"type": "boolean",
1450+
"default": false,
1451+
"title": "The create",
1452+
"examples": [
1453+
true
1454+
]
1455+
},
1456+
"port": {
1457+
"type": "integer",
1458+
"default": 9114,
1459+
"title": "The port",
1460+
"examples": [
1461+
9114
1462+
]
1463+
},
1464+
"secret": {
1465+
"type": "string",
1466+
"default": "",
1467+
"title": "The secret",
1468+
"examples": [
1469+
""
1470+
]
1471+
},
1472+
"scheme": {
1473+
"type": "string",
1474+
"default": "http",
1475+
"title": "The scheme",
1476+
"examples": [
1477+
"http"
1478+
]
1479+
}
1480+
},
1481+
"examples": [
1482+
{
1483+
"create": true,
1484+
"port": 9114,
1485+
"secret": "",
1486+
"scheme": "http"
1487+
}
1488+
]
1489+
},
14391490
"nginxServiceMesh": {
14401491
"type": "object",
14411492
"default": {},
@@ -1622,6 +1673,12 @@
16221673
"secret": "",
16231674
"scheme": "http"
16241675
},
1676+
"serviceInsight": {
1677+
"create": true,
1678+
"port": 9114,
1679+
"secret": "",
1680+
"scheme": "http"
1681+
},
16251682
"nginxServiceMesh": {
16261683
"enable": false,
16271684
"enableEgress": false

deployments/helm-chart/values.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,19 @@ prometheus:
433433
## Configures the HTTP scheme used.
434434
scheme: http
435435

436+
serviceInsight:
437+
## Expose NGINX Plus Service Insight endpoint.
438+
create: false
439+
440+
## Configures the port to expose endpoint.
441+
port: 9114
442+
443+
## Specifies the namespace/name of a Kubernetes TLS Secret which will be used to protect the Service Insight endpoint.
444+
secret: ""
445+
446+
## Configures the HTTP scheme used.
447+
scheme: http
448+
436449
nginxServiceMesh:
437450
## Enables integration with NGINX Service Mesh.
438451
## Requires controller.nginxplus

docs/content/configuration/global-configuration/command-line-arguments.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,30 @@ Format: `[1024 - 65535]` (default `9113`)
336336

337337
A Secret with a TLS certificate and key for TLS termination of the Prometheus metrics endpoint.
338338

339-
* If the argument is not set, the prometheus endpoint will not use a TLS connection.
339+
* If the argument is not set, the Prometheus endpoint will not use a TLS connection.
340+
* If the argument is set, but the Ingress Controller is not able to fetch the Secret from Kubernetes API, the Ingress Controller will fail to start.
341+
 
342+
<a name="cmdoption-enable-service-insight"></a>
343+
344+
### -enable-service-insight
345+
346+
Exposes the Service Insight endpoint for Ingress Controller.
347+
&nbsp;
348+
<a name="cmdoption-service-insight-listen-port"></a>
349+
350+
### -service-insight-listen-port `<int>`
351+
352+
Sets the port where the Service Insight is exposed.
353+
354+
Format: `[1024 - 65535]` (default `9114`)
355+
&nbsp;
356+
<a name="cmdoption-service-insight-tls-secret"></a>
357+
358+
### -service-insight-tls-secret `<string>`
359+
360+
A Secret with a TLS certificate and key for TLS termination of the Service Insight endpoint.
361+
362+
* If the argument is not set, the Service Insight endpoint will not use a TLS connection.
340363
* If the argument is set, but the Ingress Controller is not able to fetch the Secret from Kubernetes API, the Ingress Controller will fail to start.
341364

342365
Format: `<namespace>/<name>`

docs/content/installation/installation-with-helm.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ The following tables lists the configurable parameters of the NGINX Ingress Cont
250250
|``prometheus.port`` | Configures the port to scrape the metrics. | 9113 |
251251
|``prometheus.scheme`` | Configures the HTTP scheme that requests must use to connect to the Prometheus endpoint. | http |
252252
|``prometheus.secret`` | Specifies the namespace/name of a Kubernetes TLS secret which can be used to establish a secure HTTPS connection with the Prometheus endpoint. | "" |
253+
|``serviceInsight.create`` | Expose NGINX Plus Service Insight endpoint. | false |
254+
|``serviceInsight.port`` | Configures the port to scrape the metrics. | 9114 |
255+
|``serviceInsight.scheme`` | Configures the HTTP scheme to use for connections to the Service Insight endpoint. | http |
256+
|``serviceInsight.secret`` | The namespace / name of a Kubernetes TLS Secret. If specified, this secret is used to secure the Service Insight endpoint with TLS connections. | "" |
253257
{{% /table %}}
254258

255259
## Notes

0 commit comments

Comments
 (0)