Skip to content

Commit 59a5520

Browse files
authored
Support configurable hostPort in helm chart (#3321)
Problem: hostPort is not configurable for now Solution: Support configuring the hostPorts for the nginx container via helm and the NginxProxy CRD.
1 parent 0ab30e6 commit 59a5520

File tree

11 files changed

+277
-32
lines changed

11 files changed

+277
-32
lines changed

apis/v1alpha2/nginxproxy_types.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,11 @@ type ContainerSpec struct {
479479
// +optional
480480
Lifecycle *corev1.Lifecycle `json:"lifecycle,omitempty"`
481481

482+
// HostPorts are the list of ports to expose on the host.
483+
//
484+
// +optional
485+
HostPorts []HostPort `json:"hostPorts,omitempty"`
486+
482487
// VolumeMounts describe the mounting of Volumes within a container.
483488
//
484489
// +optional
@@ -599,12 +604,25 @@ const (
599604
// automatically if required. The default NodePort range enforced by Kubernetes is 30000-32767.
600605
type NodePort struct {
601606
// Port is the NodePort to expose.
602-
// kubebuilder:validation:Minimum=1
603-
// kubebuilder:validation:Maximum=65535
607+
// +kubebuilder:validation:Minimum=1
608+
// +kubebuilder:validation:Maximum=65535
604609
Port int32 `json:"port"`
605610

606611
// ListenerPort is the Gateway listener port that this NodePort maps to.
607-
// kubebuilder:validation:Minimum=1
608-
// kubebuilder:validation:Maximum=65535
612+
// +kubebuilder:validation:Minimum=1
613+
// +kubebuilder:validation:Maximum=65535
609614
ListenerPort int32 `json:"listenerPort"`
610615
}
616+
617+
// HostPort exposes an nginx container port on the host.
618+
type HostPort struct {
619+
// Port to expose on the host.
620+
// +kubebuilder:validation:Minimum=1
621+
// +kubebuilder:validation:Maximum=65535
622+
Port int32 `json:"port"`
623+
624+
// ContainerPort is the port on the nginx container to map to the HostPort.
625+
// +kubebuilder:validation:Minimum=1
626+
// +kubebuilder:validation:Maximum=65535
627+
ContainerPort int32 `json:"containerPort"`
628+
}

apis/v1alpha2/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/nginx-gateway-fabric/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,13 @@ The following table lists the configurable parameters of the NGINX Gateway Fabri
264264
| `certGenerator.ttlSecondsAfterFinished` | How long to wait after the cert generator job has finished before it is removed by the job controller. | int | `30` |
265265
| `clusterDomain` | The DNS cluster domain of your Kubernetes cluster. | string | `"cluster.local"` |
266266
| `gateways` | A list of Gateway objects. View https://gateway-api.sigs.k8s.io/reference/spec/#gateway for full Gateway reference. | list | `[]` |
267-
| `nginx` | The nginx section contains the configuration for all NGINX data plane deployments installed by the NGINX Gateway Fabric control plane. | object | `{"config":{},"container":{},"debug":false,"image":{"pullPolicy":"Always","repository":"ghcr.io/nginx/nginx-gateway-fabric/nginx","tag":"edge"},"imagePullSecret":"","imagePullSecrets":[],"kind":"deployment","plus":false,"pod":{},"replicas":1,"service":{"externalTrafficPolicy":"Local","loadBalancerClass":"","loadBalancerIP":"","loadBalancerSourceRanges":[],"nodePorts":[],"type":"LoadBalancer"},"usage":{"caSecretName":"","clientSSLSecretName":"","endpoint":"","resolver":"","secretName":"nplus-license","skipVerify":false}}` |
267+
| `nginx` | The nginx section contains the configuration for all NGINX data plane deployments installed by the NGINX Gateway Fabric control plane. | object | `{"config":{},"container":{"hostPorts":[],"lifecycle":{},"resources":{},"volumeMounts":[]},"debug":false,"image":{"pullPolicy":"Always","repository":"ghcr.io/nginx/nginx-gateway-fabric/nginx","tag":"edge"},"imagePullSecret":"","imagePullSecrets":[],"kind":"deployment","plus":false,"pod":{},"replicas":1,"service":{"externalTrafficPolicy":"Local","loadBalancerClass":"","loadBalancerIP":"","loadBalancerSourceRanges":[],"nodePorts":[],"type":"LoadBalancer"},"usage":{"caSecretName":"","clientSSLSecretName":"","endpoint":"","resolver":"","secretName":"nplus-license","skipVerify":false}}` |
268268
| `nginx.config` | The configuration for the data plane that is contained in the NginxProxy resource. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{}` |
269-
| `nginx.container` | The container configuration for the NGINX container. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{}` |
269+
| `nginx.container` | The container configuration for the NGINX container. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{"hostPorts":[],"lifecycle":{},"resources":{},"volumeMounts":[]}` |
270+
| `nginx.container.hostPorts` | A list of HostPorts to expose on the host. This configuration allows containers to bind to a specific port on the host node, enabling external network traffic to reach the container directly through the host's IP address and port. Use this option when you need to expose container ports on the host for direct access, such as for debugging, legacy integrations, or when NodePort/LoadBalancer services are not suitable. Note: Using hostPort may have security and scheduling implications, as it ties pods to specific nodes and ports. | list | `[]` |
271+
| `nginx.container.lifecycle` | The lifecycle of the NGINX container. | object | `{}` |
272+
| `nginx.container.resources` | The resource requirements of the NGINX container. | object | `{}` |
273+
| `nginx.container.volumeMounts` | volumeMounts are the additional volume mounts for the NGINX container. | list | `[]` |
270274
| `nginx.debug` | Enable debugging for NGINX. Uses the nginx-debug binary. The NGINX error log level should be set to debug in the NginxProxy resource. | bool | `false` |
271275
| `nginx.image.repository` | The NGINX image to use. | string | `"ghcr.io/nginx/nginx-gateway-fabric/nginx"` |
272276
| `nginx.imagePullSecret` | The name of the secret containing docker registry credentials. Secret must exist in the same namespace as the helm release. The control plane will copy this secret into any namespace where NGINX is deployed. | string | `""` |

charts/nginx-gateway-fabric/templates/_helpers.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,7 @@ Filters out empty fields from a struct.
106106
{{- $result = merge $result (dict $key $value) }}
107107
{{- end }}
108108
{{- end }}
109-
{{- $result | toYaml }}
109+
{{- if $result -}}
110+
{{- $result | toYaml -}}
111+
{{- end -}}
110112
{{- end }}

charts/nginx-gateway-fabric/templates/nginxproxy.yaml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ spec:
1818
{{- toYaml .Values.nginx.pod | nindent 8 }}
1919
{{- end }}
2020
container:
21-
{{- if .Values.nginx.container }}
22-
{{- toYaml .Values.nginx.container | nindent 8 }}
21+
{{- with .Values.nginx.container }}
22+
{{- $filtered := include "filterEmptyFields" . }}
23+
{{- if $filtered }}
24+
{{- $filtered | nindent 8 }}
25+
{{- end }}
2326
{{- end }}
2427
image:
2528
{{- toYaml .Values.nginx.image | nindent 10 }}
@@ -34,8 +37,11 @@ spec:
3437
{{- toYaml .Values.nginx.pod | nindent 8 }}
3538
{{- end }}
3639
container:
37-
{{- if .Values.nginx.container }}
38-
{{- toYaml .Values.nginx.container | nindent 8 }}
40+
{{- with .Values.nginx.container }}
41+
{{- $filtered := include "filterEmptyFields" . }}
42+
{{- if $filtered }}
43+
{{- $filtered | nindent 8 }}
44+
{{- end }}
3945
{{- end }}
4046
image:
4147
{{- toYaml .Values.nginx.image | nindent 10 }}
@@ -46,6 +52,9 @@ spec:
4652
{{- if .Values.nginx.service }}
4753
service:
4854
{{- with .Values.nginx.service }}
49-
{{- include "filterEmptyFields" . | nindent 6 }}
55+
{{- $filtered := include "filterEmptyFields" . }}
56+
{{- if $filtered }}
57+
{{- $filtered | nindent 6 }}
58+
{{- end }}
5059
{{- end }}
5160
{{- end }}

charts/nginx-gateway-fabric/values.schema.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,53 @@
313313
},
314314
"container": {
315315
"description": "The container configuration for the NGINX container. This is applied globally to all Gateways managed by this\ninstance of NGINX Gateway Fabric.",
316+
"properties": {
317+
"hostPorts": {
318+
"description": "A list of HostPorts to expose on the host.\nThis configuration allows containers to bind to a specific port on the host node,\nenabling external network traffic to reach the container directly through the host's IP address and port.\nUse this option when you need to expose container ports on the host for direct access,\nsuch as for debugging, legacy integrations, or when NodePort/LoadBalancer services are not suitable.\nNote: Using hostPort may have security and scheduling implications, as it ties pods to specific nodes and ports.",
319+
"items": {
320+
"properties": {
321+
"containerPort": {
322+
"maximum": 65535,
323+
"minimum": 1,
324+
"required": [],
325+
"type": "integer"
326+
},
327+
"port": {
328+
"maximum": 65535,
329+
"minimum": 1,
330+
"required": [],
331+
"type": "integer"
332+
}
333+
},
334+
"required": [],
335+
"type": "object"
336+
},
337+
"required": [],
338+
"title": "hostPorts",
339+
"type": "array"
340+
},
341+
"lifecycle": {
342+
"description": "The lifecycle of the NGINX container.",
343+
"required": [],
344+
"title": "lifecycle",
345+
"type": "object"
346+
},
347+
"resources": {
348+
"description": "The resource requirements of the NGINX container.",
349+
"required": [],
350+
"title": "resources",
351+
"type": "object"
352+
},
353+
"volumeMounts": {
354+
"description": "volumeMounts are the additional volume mounts for the NGINX container.",
355+
"items": {
356+
"required": []
357+
},
358+
"required": [],
359+
"title": "volumeMounts",
360+
"type": "array"
361+
}
362+
},
316363
"required": [],
317364
"title": "container",
318365
"type": "object"

charts/nginx-gateway-fabric/values.yaml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,41 @@ nginx:
400400

401401
# -- The container configuration for the NGINX container. This is applied globally to all Gateways managed by this
402402
# instance of NGINX Gateway Fabric.
403-
container: {}
403+
container:
404+
# @schema
405+
# type: array
406+
# items:
407+
# type: object
408+
# properties:
409+
# port:
410+
# type: integer
411+
# required: true
412+
# minimum: 1
413+
# maximum: 65535
414+
# containerPort:
415+
# type: integer
416+
# required: true
417+
# minimum: 1
418+
# maximum: 65535
419+
# @schema
420+
# -- A list of HostPorts to expose on the host.
421+
# This configuration allows containers to bind to a specific port on the host node,
422+
# enabling external network traffic to reach the container directly through the host's IP address and port.
423+
# Use this option when you need to expose container ports on the host for direct access,
424+
# such as for debugging, legacy integrations, or when NodePort/LoadBalancer services are not suitable.
425+
# Note: Using hostPort may have security and scheduling implications, as it ties pods to specific nodes and ports.
426+
hostPorts: []
427+
# - port: 80
428+
# containerPort: 80
429+
404430
# -- The resource requirements of the NGINX container.
405-
# resources: {}
431+
resources: {}
406432

407433
# -- The lifecycle of the NGINX container.
408-
# lifecycle: {}
434+
lifecycle: {}
409435

410436
# -- volumeMounts are the additional volume mounts for the NGINX container.
411-
# volumeMounts: []
437+
volumeMounts: []
412438

413439
# -- The service configuration for the NGINX data plane. This is applied globally to all Gateways managed by this
414440
# instance of NGINX Gateway Fabric.

config/crd/bases/gateway.nginx.org_nginxproxies.yaml

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,31 @@ spec:
8181
description: Debug enables debugging for NGINX by using
8282
the nginx-debug binary.
8383
type: boolean
84+
hostPorts:
85+
description: HostPorts are the list of ports to expose
86+
on the host.
87+
items:
88+
description: HostPort exposes an nginx container port
89+
on the host.
90+
properties:
91+
containerPort:
92+
description: ContainerPort is the port on the nginx
93+
container to map to the HostPort.
94+
format: int32
95+
maximum: 65535
96+
minimum: 1
97+
type: integer
98+
port:
99+
description: Port to expose on the host.
100+
format: int32
101+
maximum: 65535
102+
minimum: 1
103+
type: integer
104+
required:
105+
- containerPort
106+
- port
107+
type: object
108+
type: array
84109
image:
85110
description: Image is the NGINX image to use.
86111
properties:
@@ -3467,6 +3492,31 @@ spec:
34673492
description: Debug enables debugging for NGINX by using
34683493
the nginx-debug binary.
34693494
type: boolean
3495+
hostPorts:
3496+
description: HostPorts are the list of ports to expose
3497+
on the host.
3498+
items:
3499+
description: HostPort exposes an nginx container port
3500+
on the host.
3501+
properties:
3502+
containerPort:
3503+
description: ContainerPort is the port on the nginx
3504+
container to map to the HostPort.
3505+
format: int32
3506+
maximum: 65535
3507+
minimum: 1
3508+
type: integer
3509+
port:
3510+
description: Port to expose on the host.
3511+
format: int32
3512+
maximum: 65535
3513+
minimum: 1
3514+
type: integer
3515+
required:
3516+
- containerPort
3517+
- port
3518+
type: object
3519+
type: array
34703520
image:
34713521
description: Image is the NGINX image to use.
34723522
properties:
@@ -6885,18 +6935,17 @@ spec:
68856935
automatically if required. The default NodePort range enforced by Kubernetes is 30000-32767.
68866936
properties:
68876937
listenerPort:
6888-
description: |-
6889-
ListenerPort is the Gateway listener port that this NodePort maps to.
6890-
kubebuilder:validation:Minimum=1
6891-
kubebuilder:validation:Maximum=65535
6938+
description: ListenerPort is the Gateway listener port
6939+
that this NodePort maps to.
68926940
format: int32
6941+
maximum: 65535
6942+
minimum: 1
68936943
type: integer
68946944
port:
6895-
description: |-
6896-
Port is the NodePort to expose.
6897-
kubebuilder:validation:Minimum=1
6898-
kubebuilder:validation:Maximum=65535
6945+
description: Port is the NodePort to expose.
68996946
format: int32
6947+
maximum: 65535
6948+
minimum: 1
69006949
type: integer
69016950
required:
69026951
- listenerPort

0 commit comments

Comments
 (0)