Skip to content

Commit

Permalink
multi-port service support for prefect-server
Browse files Browse the repository at this point in the history
  • Loading branch information
baisystems committed Apr 4, 2024
1 parent d73ef8c commit aab4d5e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 24 deletions.
10 changes: 5 additions & 5 deletions charts/prefect-server/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ spec:
- server
- start
- --port
- {{ .Values.service.targetPort | quote }}
- {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") | quote }}
{{- range .Values.server.extraArgs }}
- {{ . | toString }}
{{- end }}
workingDir: /home/prefect
ports:
- containerPort: {{ int .Values.service.targetPort }}
- containerPort: {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") }}
env:
- name: HOME
value: /home/prefect
Expand All @@ -84,7 +84,7 @@ spec:
- name: PREFECT_SERVER_API_HOST
value: {{ .Values.server.prefectApiHost | quote }}
- name: PREFECT_SERVER_API_PORT
value: {{ .Values.service.targetPort | quote }}
value: {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") | quote }}
- name: PREFECT_UI_ENABLED
value: {{ .Values.server.uiConfig.enabled | quote }}
{{- if .Values.server.uiConfig.prefectUiApiUrl }}
Expand Down Expand Up @@ -126,14 +126,14 @@ spec:
livenessProbe:
httpGet:
path: /api/health
port: {{ .Values.service.targetPort }}
port: {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") }}
{{- toYaml .Values.server.livenessProbe.config | nindent 12 }}
{{- end }}
{{- if .Values.server.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: /api/ready
port: {{ .Values.service.targetPort }}
port: {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") }}
{{- toYaml .Values.server.readinessProbe.config | nindent 12 }}
{{- end }}
volumeMounts:
Expand Down
4 changes: 2 additions & 2 deletions charts/prefect-server/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ spec:
{{- if eq "true" (include "common.ingress.supportsPathType" .) }}
pathType: {{ .Values.ingress.host.pathType }}
{{- end }}
backend: {{- include "common.ingress.backend" (dict "serviceName" (include "common.names.fullname" .) "servicePort" "server-svc-port" "context" $) | nindent 14 }}
backend: {{- include "common.ingress.backend" (dict "serviceName" (include "common.names.fullname" .) "servicePort" .Values.ingress.servicePort "context" $) | nindent 14 }}
{{- end }}
{{- range .Values.ingress.extraHosts }}
- host: {{ .name | quote }}
Expand All @@ -45,7 +45,7 @@ spec:
{{- if eq "true" (include "common.ingress.supportsPathType" $) }}
pathType: {{ default "ImplementationSpecific" .pathType }}
{{- end }}
backend: {{- include "common.ingress.backend" (dict "serviceName" (include "common.names.fullname" $) "servicePort" "server-svc-port" "context" $) | nindent 14 }}
backend: {{- include "common.ingress.backend" (dict "serviceName" (include "common.names.fullname" $) "servicePort" .Values.ingress.servicePort "context" $) | nindent 14 }}
{{- end }}
{{- if .Values.ingress.extraRules }}
{{- include "common.tplvalues.render" (dict "value" .Values.ingress.extraRules "context" $) | nindent 4 }}
Expand Down
15 changes: 9 additions & 6 deletions charts/prefect-server/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ spec:
{{- if eq .Values.service.type "NodePort" }}
externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy | quote }}
{{- end }}
{{- $serviceType := .Values.service.type }}
ports:
- name: server-svc-port
port: {{ .Values.service.port }}
{{- range .Values.service.ports }}
- name: {{ .name }}
protocol: TCP
targetPort: {{ .Values.service.targetPort }}
{{- if and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort)) }}
nodePort: {{ .Values.service.nodePort }}
{{- else if eq .Values.service.type "ClusterIP" }}
port: {{ .port }}
targetPort: {{ .targetPort }}
{{- if and (eq $serviceType "NodePort") (not (empty .nodePort)) }}
nodePort: {{ .nodePort }}
{{- else if eq $serviceType "ClusterIP" }}
nodePort: null
{{- end }}
{{- end }}
selector: {{- include "common.labels.matchLabels" . | nindent 4 }}
app.kubernetes.io/component: server
14 changes: 14 additions & 0 deletions charts/prefect-server/templates/target-port.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- define "target-port" }}
{{- $ports := .ports }}
{{- $targetPortName := .name }}
{{- $targetPortNumber := 0 }}

{{- range $ports }}
{{- if eq .name $targetPortName }}
{{- $targetPortNumber = .targetPort }}
{{- end }}
{{- end }}

{{- $targetPortNumber }}

{{- end }}
28 changes: 23 additions & 5 deletions charts/prefect-server/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,23 @@
"description": "service type",
"form": true
},
"port": {
"type": "integer",
"title": "Port",
"description": "service port",
"form": true
"ports": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"port": {
"type": "integer"
},
"targetPort": {
"type": "integer"
}
},
"required": ["name", "port", "targetPort"]
}
},
"clusterIP": {
"type": "string",
Expand Down Expand Up @@ -575,6 +587,12 @@
"description": "enable ingress record generation for server",
"form": true
},
"servicePort": {
"type": "string",
"title": "Service Port Name",
"description": "service port name",
"form": true
},
"className": {
"type": "string",
"title": "Class Name",
Expand Down
20 changes: 14 additions & 6 deletions charts/prefect-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,20 @@ serviceAccount:

## Service configuration
service:
ports:
- name: server-svc-port
# -- service port
port: 4200
# -- target port of the server pod; also sets PREFECT_SERVER_API_PORT
targetPort: 4200
# -- service port if defining service as type nodeport
nodePort: ""

Check failure on line 196 in charts/prefect-server/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test (1.26.0)

196:1 [trailing-spaces] trailing spaces

Check failure on line 196 in charts/prefect-server/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test (1.27.0)

196:1 [trailing-spaces] trailing spaces

Check failure on line 196 in charts/prefect-server/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test (1.28.0)

196:1 [trailing-spaces] trailing spaces

Check failure on line 196 in charts/prefect-server/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test (1.29.0)

196:1 [trailing-spaces] trailing spaces
# -- service type
type: ClusterIP
# -- service port
port: 4200
# -- target port of the server pod; also sets PREFECT_SERVER_API_PORT
targetPort: 4200
# -- service Cluster IP
clusterIP: ""
# -- service port if defining service as type nodeport
nodePort: ""

Check failure on line 201 in charts/prefect-server/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test (1.26.0)

201:1 [trailing-spaces] trailing spaces

Check failure on line 201 in charts/prefect-server/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test (1.27.0)

201:1 [trailing-spaces] trailing spaces

Check failure on line 201 in charts/prefect-server/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test (1.28.0)

201:1 [trailing-spaces] trailing spaces

Check failure on line 201 in charts/prefect-server/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test (1.29.0)

201:1 [trailing-spaces] trailing spaces

## ref http://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip
# -- service external traffic policy
Expand All @@ -206,6 +210,10 @@ service:
ingress:
# -- enable ingress record generation for server
enabled: false

# -- port for the ingress' main path

Check failure on line 214 in charts/prefect-server/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test (1.26.0)

214:39 [trailing-spaces] trailing spaces

Check failure on line 214 in charts/prefect-server/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test (1.27.0)

214:39 [trailing-spaces] trailing spaces

Check failure on line 214 in charts/prefect-server/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test (1.28.0)

214:39 [trailing-spaces] trailing spaces

Check failure on line 214 in charts/prefect-server/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test (1.29.0)

214:39 [trailing-spaces] trailing spaces
servicePort: server-svc-port

## This is supported in Kubernetes 1.18+ and required if you have more than one IngressClass marked as the default for your cluster .
## ref: https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/
# -- IngressClass that will be used to implement the Ingress (Kubernetes 1.18+)
Expand Down

0 comments on commit aab4d5e

Please sign in to comment.