From fafd38a800ef129e25919b69b8bdbf20f71e1046 Mon Sep 17 00:00:00 2001 From: sd109 Date: Tue, 11 Jun 2024 15:33:32 +0100 Subject: [PATCH 1/4] Add backend ingress functionality Refactors the ingress configuration and adds the option to expose both the UI and the backend API via separate ingress resources. This allows the OpenAI-compatible backend API to be exposed to external tooling. --- chart/templates/api/ingress.yml | 32 +++++++++++++++++++++++ chart/templates/api/service.yml | 2 +- chart/templates/ui/ingress.yml | 32 +++++++++++++++++++++++ chart/templates/ui/service.yml | 26 ------------------- chart/values.yaml | 45 +++++++++++++++++++++------------ 5 files changed, 94 insertions(+), 43 deletions(-) create mode 100644 chart/templates/api/ingress.yml create mode 100644 chart/templates/ui/ingress.yml diff --git a/chart/templates/api/ingress.yml b/chart/templates/api/ingress.yml new file mode 100644 index 0000000..24bb50d --- /dev/null +++ b/chart/templates/api/ingress.yml @@ -0,0 +1,32 @@ +{{- if .Values.ingress.api.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + {{ if .Values.ingress.ui.annotations -}} + annotations: + {{- .Values.ingress.api.annotations | toYaml | nindent 4 }} + {{ end -}} + name: {{ default (printf "%s-api" .Release.Name) .Values.ingress.api.name }} +spec: + ingressClassName: nginx + rules: + - http: + paths: + - path: /v1 + pathType: Prefix + backend: + service: + name: {{ .Values.api.service.name }} + port: + # Must match Service resource + number: 80 + {{ if .Values.ingress.host -}} + host: {{ .Values.ingress.host | quote }} + {{- end -}} + {{- if .Values.ingress.tls }} + tls: + - hosts: + - {{ (required "ingress.host is required when ingress.tls is true" .Values.ingress.host) | quote }} + secretName: {{ .Release.Name }}-tls + {{- end -}} +{{- end -}} diff --git a/chart/templates/api/service.yml b/chart/templates/api/service.yml index b977164..f432145 100644 --- a/chart/templates/api/service.yml +++ b/chart/templates/api/service.yml @@ -12,4 +12,4 @@ spec: targetPort: api type: {{ .Values.api.service.type }} selector: - {{- include "azimuth-llm.api-selectorLabels" . | nindent 4 }} \ No newline at end of file + {{- include "azimuth-llm.api-selectorLabels" . | nindent 4 }} diff --git a/chart/templates/ui/ingress.yml b/chart/templates/ui/ingress.yml new file mode 100644 index 0000000..8b943d7 --- /dev/null +++ b/chart/templates/ui/ingress.yml @@ -0,0 +1,32 @@ +{{- if and .Values.ui.enabled .Values.ingress.ui.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + {{ if .Values.ingress.ui.annotations -}} + annotations: + {{- .Values.ingress.ui.annotations | toYaml | nindent 4 }} + {{ end -}} + name: {{ default (printf "%s-ui" .Release.Name) .Values.ingress.ui.name }} +spec: + ingressClassName: nginx + rules: + - http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: {{ .Values.ui.service.name }} + port: + # Must match Service resource + number: 80 + {{ if .Values.ingress.host -}} + host: {{ .Values.ingress.host | quote }} + {{- end -}} + {{- if .Values.ingress.tls }} + tls: + - hosts: + - {{ (required "ingress.host is required when ingress.tls is true" .Values.ingress.host) | quote }} + secretName: {{ .Release.Name }}-tls + {{- end -}} +{{- end -}} diff --git a/chart/templates/ui/service.yml b/chart/templates/ui/service.yml index 5e96d95..bbdc42f 100644 --- a/chart/templates/ui/service.yml +++ b/chart/templates/ui/service.yml @@ -15,30 +15,4 @@ spec: type: {{ .Values.ui.service.type }} selector: {{- include "azimuth-llm.ui-selectorLabels" . | nindent 4 }} ---- -{{- if .Values.ui.ingress.host -}} -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - annotations: - {{- .Values.ui.ingress.annotations | toYaml | nindent 4 }} - name: {{ .Values.ui.ingress.name | default .Release.Name }} -spec: - ingressClassName: nginx - rules: - - host: {{ .Values.ui.ingress.host | quote }} - http: - paths: - - backend: - service: - name: {{ .Values.ui.service.name }} - port: - number: 80 # Must match Service resource - path: / - pathType: Prefix - tls: - - hosts: - - {{ .Values.ui.ingress.host | quote }} - secretName: {{ .Release.Name }}-tls {{- end -}} -{{- end -}} \ No newline at end of file diff --git a/chart/values.yaml b/chart/values.yaml index 47a3510..118b145 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -112,27 +112,40 @@ ui: iconUrl: https://raw.githubusercontent.com/gradio-app/gradio/5524e590577769b0444a5332b8d444aafb0c5c12/js/app/public/static/img/logo.svg description: | A web-based user inferface for interacting with the deployed LLM. - # Optional config for an ingress resource to expose the UI - ingress: - # The name of the ingress resource to create (default: Release.Name) - name: - # Any annotations to apply to the ingress resource - # (e.g. for cert-manager TLS integration) - annotations: {} - # The domain name to use for the ingress resource. - # If host is not set then ingress support will be disabled and - # no ingress resource will be created. - # NOTE: If ingress is enabled, an ingress controller must be installed - # on the target cluster before installing this chart. - # For example, see https://kubernetes.github.io/ingress-nginx/deploy/ - # TODO: Check what happens if ingress is enabled without a controller deployed - # (probably nothing, just an unused ingress resource will be created) - host: # The update strategy to use for the deployment updateStrategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% +# Settings for configuring ingress resources +# to make the UI and/or backend API accessible +# outside the cluster. +# NOTE: An ingress controller must be installed +# on the target cluster. +ingress: + host: + tls: true + api: + enabled: false + # Defaults to "{{ .Release.name }}"-api + name: + # This is required to be /v1 for an OpenAI API + # unless we add URL rewrite functionality to the + # Ingress resource templates in the future. + path: /v1 + # Annotations to apply to the ingress resource + # e.g. for cert-manager integration + annotations: + ui: + enabled: false + # Defaults to "{{ .Release.name }}"-ui + name: + # For a Gradio app this must be the root + path: / + # Annotations to apply to the ingress resource + # e.g. for cert-manager integration + annotations: + reloader: watchGlobally: false From 07e31fe02b6732c0a40981871cadfd0d91d779e6 Mon Sep 17 00:00:00 2001 From: sd109 Date: Tue, 11 Jun 2024 15:37:24 +0100 Subject: [PATCH 2/4] Minor fixes --- chart/templates/api/ingress.yml | 4 ++-- chart/templates/ui/ingress.yml | 2 +- chart/values.yaml | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/chart/templates/api/ingress.yml b/chart/templates/api/ingress.yml index 24bb50d..5588688 100644 --- a/chart/templates/api/ingress.yml +++ b/chart/templates/api/ingress.yml @@ -8,11 +8,11 @@ metadata: {{ end -}} name: {{ default (printf "%s-api" .Release.Name) .Values.ingress.api.name }} spec: - ingressClassName: nginx + ingressClassName: {{ .Values.ingress.className }} rules: - http: paths: - - path: /v1 + - path: {{ .Values.ingress.api.path }} pathType: Prefix backend: service: diff --git a/chart/templates/ui/ingress.yml b/chart/templates/ui/ingress.yml index 8b943d7..374787b 100644 --- a/chart/templates/ui/ingress.yml +++ b/chart/templates/ui/ingress.yml @@ -8,7 +8,7 @@ metadata: {{ end -}} name: {{ default (printf "%s-ui" .Release.Name) .Values.ingress.ui.name }} spec: - ingressClassName: nginx + ingressClassName: {{ .Values.ingress.className }} rules: - http: paths: diff --git a/chart/values.yaml b/chart/values.yaml index 118b145..10d7b6e 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -124,6 +124,8 @@ ui: # NOTE: An ingress controller must be installed # on the target cluster. ingress: + # The name of the ingress class to use + className: nginx host: tls: true api: From b6e8f765b6d2f67510763173d539252a96fe2282 Mon Sep 17 00:00:00 2001 From: sd109 Date: Tue, 11 Jun 2024 15:37:45 +0100 Subject: [PATCH 3/4] Remove --- --- chart/templates/ui/service.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/chart/templates/ui/service.yml b/chart/templates/ui/service.yml index bbdc42f..1de5c17 100644 --- a/chart/templates/ui/service.yml +++ b/chart/templates/ui/service.yml @@ -1,5 +1,4 @@ {{- if .Values.ui.enabled -}} ---- apiVersion: v1 kind: Service metadata: From 84c79f52e9145a3fe2cb988ed48c6dea5b07822f Mon Sep 17 00:00:00 2001 From: sd109 Date: Tue, 11 Jun 2024 15:39:07 +0100 Subject: [PATCH 4/4] Use correct value for UI ingress path --- chart/templates/ui/ingress.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chart/templates/ui/ingress.yml b/chart/templates/ui/ingress.yml index 374787b..a598f85 100644 --- a/chart/templates/ui/ingress.yml +++ b/chart/templates/ui/ingress.yml @@ -12,7 +12,7 @@ spec: rules: - http: paths: - - path: / + - path: {{ .Values.ingress.ui.path }} pathType: Prefix backend: service: