Skip to content

Commit b77960b

Browse files
nic-6443Copilot
andauthored
feat: support auto assign node port for stream subsystem (#258)
Signed-off-by: Nic <qianyong@api7.ai> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent a62d266 commit b77960b

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

charts/gateway/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type: application
1414
# This is the chart version. This version number should be incremented each time you make changes
1515
# to the chart and its templates, including the app version.
1616
# Versions are expected to follow Semantic Versioning (https://semver.org/)
17-
version: 0.2.53
17+
version: 0.2.54
1818

1919
# This is the version number of the application being deployed. This version number should be
2020
# incremented each time you make changes to the application. Versions are not expected to

charts/gateway/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ The command removes all the Kubernetes components associated with the chart and
192192
| gateway.labelsOverride | object | `{}` | Override default labels assigned to API7 Gateway gateway resources |
193193
| gateway.livenessProbe | object | `{}` | kubernetes liveness probe. |
194194
| gateway.readinessProbe | object | `{}` | kubernetes readiness probe, we will provide a probe based on tcpSocket to gateway's HTTP port by default. |
195-
| gateway.stream | object | `{"enabled":false,"only":false,"tcp":[],"udp":[]}` | API7 Gateway service settings for stream. L4 proxy (TCP/UDP) |
195+
| gateway.stream | object | `{"autoAssignNodePort":false,"enabled":false,"only":false,"tcp":[],"udp":[]}` | API7 Gateway service settings for stream. L4 proxy (TCP/UDP) |
196+
| gateway.stream.autoAssignNodePort | bool | `false` | Whether to set nodePort to the same value as the TCP/UDP port when gateway.type is NodePort, make sure the nodePort to be in the valid NodePort range of kubernetes service. |
196197
| gateway.tls | object | `{"additionalContainerPorts":[],"certCAFilename":"","containerPort":9443,"enabled":true,"existingCASecret":"","fallbackSNI":"","http2":{"enabled":true},"ip":"0.0.0.0","nodePort":null,"servicePort":443,"sslProtocols":"TLSv1.2 TLSv1.3"}` | API7 Gateway service settings for tls |
197198
| gateway.tls.additionalContainerPorts | list | `[]` | Support multiple https ports, See [Configuration](https://github.com/apache/apisix/blob/0bc65ea9acd726f79f80ae0abd8f50b7eb172e3d/conf/config-default.yaml#L99) |
198199
| gateway.tls.certCAFilename | string | `""` | Filename be used in the gateway.tls.existingCASecret |
@@ -234,7 +235,7 @@ The command removes all the Kubernetes components associated with the chart and
234235
| serviceAccount.annotations | object | `{}` | |
235236
| serviceAccount.create | bool | `false` | |
236237
| serviceAccount.name | string | `""` | |
237-
| serviceMonitor | object | `{"annotations":{},"containerPort":9091,"enabled":false,"interval":"15s","labels":{},"metricPrefix":"apisix_","name":"","namespace":"","path":"/apisix/prometheus/metrics"}` | Observability configuration. ref: https://apisix.apache.org/docs/apisix/plugins/prometheus/ |
238+
| serviceMonitor | object | `{"annotations":{},"containerPort":9091,"enabled":false,"interval":"15s","labels":{},"metricPrefix":"apisix_","name":"","namespace":"","nodePort":null,"path":"/apisix/prometheus/metrics"}` | Observability configuration. ref: https://apisix.apache.org/docs/apisix/plugins/prometheus/ |
238239
| serviceMonitor.annotations | object | `{}` | @param serviceMonitor.annotations ServiceMonitor annotations |
239240
| serviceMonitor.containerPort | int | `9091` | container port where the metrics are exposed |
240241
| serviceMonitor.enabled | bool | `false` | Enable or disable API7 Gateway serviceMonitor |
@@ -243,6 +244,7 @@ The command removes all the Kubernetes components associated with the chart and
243244
| serviceMonitor.metricPrefix | string | `"apisix_"` | prefix of the metrics |
244245
| serviceMonitor.name | string | `""` | name of the serviceMonitor, by default, it is the same as the apisix fullname |
245246
| serviceMonitor.namespace | string | `""` | namespace where the serviceMonitor is deployed, by default, it is the same as the namespace of the apisix |
247+
| serviceMonitor.nodePort | int | `nil` | The nodePort of kubernetes service, only used if gateway.type is NodePort. If not set, a random port will be assigned by Kubernetes. |
246248
| serviceMonitor.path | string | `"/apisix/prometheus/metrics"` | path of the metrics endpoint |
247249
| soapProxy.enabled | bool | `false` | Enable or disable the SOAP proxy, this component is disabled by default, when use soap-proxy plugin in API7, you need to enable this component. |
248250
| soapProxy.image.pullPolicy | string | `"IfNotPresent"` | SOAP proxy image pull policy |

charts/gateway/templates/service-gateway.yaml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ spec:
7777
- name: prometheus
7878
port: {{ .Values.serviceMonitor.containerPort }}
7979
targetPort: {{ .Values.serviceMonitor.containerPort }}
80+
{{- if (and (eq .Values.gateway.type "NodePort") (not (empty .Values.serviceMonitor.nodePort))) }}
81+
nodePort: {{ .Values.serviceMonitor.nodePort }}
82+
{{- end }}
8083
protocol: TCP
8184
{{- end }}
8285
{{- if .Values.api7ee.status_endpoint.enabled }}
@@ -94,12 +97,23 @@ spec:
9497
{{- if kindIs "map" $port }}
9598
port: {{ splitList ":" ($port.addr | toString) | last }}
9699
targetPort: {{ splitList ":" ($port.addr | toString) | last }}
97-
{{- if (and (eq $global.Values.gateway.type "NodePort") (not (empty $port.nodePort))) }}
100+
{{- if eq $global.Values.gateway.type "NodePort" }}
101+
{{- if $global.Values.gateway.stream.autoAssignNodePort }}
102+
nodePort: {{ splitList ":" ($port.addr | toString) | last }}
103+
{{- else }}
104+
{{- if not (empty $port.nodePort) }}
98105
nodePort: {{ $port.nodePort }}
99106
{{- end }}
107+
{{- end }}
108+
{{- end }}
100109
{{- else }}
101110
port: {{ $port }}
102111
targetPort: {{ $port }}
112+
{{- if eq $global.Values.gateway.type "NodePort" }}
113+
{{- if $global.Values.gateway.stream.autoAssignNodePort }}
114+
nodePort: {{ $port }}
115+
{{- end }}
116+
{{- end }}
103117
{{- end }}
104118
{{- end }}
105119
{{- end }}
@@ -110,12 +124,23 @@ spec:
110124
{{- if kindIs "map" $port }}
111125
port: {{ splitList ":" ($port.addr | toString) | last }}
112126
targetPort: {{ splitList ":" ($port.addr | toString) | last }}
113-
{{- if (and (eq $global.Values.gateway.type "NodePort") (not (empty $port.nodePort))) }}
127+
{{- if eq $global.Values.gateway.type "NodePort" }}
128+
{{- if $global.Values.gateway.stream.autoAssignNodePort }}
129+
nodePort: {{ splitList ":" ($port.addr | toString) | last }}
130+
{{- else }}
131+
{{- if not (empty $port.nodePort) }}
114132
nodePort: {{ $port.nodePort }}
115133
{{- end }}
134+
{{- end }}
135+
{{- end }}
116136
{{- else }}
117137
port: {{ $port }}
118138
targetPort: {{ $port }}
139+
{{- if eq $global.Values.gateway.type "NodePort" }}
140+
{{- if $global.Values.gateway.stream.autoAssignNodePort }}
141+
nodePort: {{ $port }}
142+
{{- end }}
143+
{{- end }}
119144
{{- end }}
120145
{{- end }}
121146
{{- end }}

charts/gateway/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ gateway:
358358
stream:
359359
enabled: false
360360
only: false
361+
# -- Whether to set nodePort to the same value as the TCP/UDP port when gateway.type is NodePort, make sure the nodePort to be in the valid NodePort range of kubernetes service.
362+
autoAssignNodePort: false
361363
tcp: []
362364
# - addr: 192.168.31.10:5432
363365
# - addr: 3302
@@ -592,6 +594,8 @@ serviceMonitor:
592594
metricPrefix: apisix_
593595
# -- container port where the metrics are exposed
594596
containerPort: 9091
597+
# -- (int) The nodePort of kubernetes service, only used if gateway.type is NodePort. If not set, a random port will be assigned by Kubernetes.
598+
nodePort:
595599
# -- @param serviceMonitor.labels ServiceMonitor extra labels
596600
labels: {}
597601
# -- @param serviceMonitor.annotations ServiceMonitor annotations

0 commit comments

Comments
 (0)