Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 73 additions & 2 deletions helm-charts/common/nginx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,77 @@

Helm chart for deploying OPEA nginx service.

## Using nginx chart
## Integration with OPEA Applications

E2E charts for OPEA applications should provide ConfigMap of name `{{ .Release.Name }}-nginx-config` with the required environment variables to configure [OPEA nginx microservice](https://github.com/opea-project/GenAIComps/blob/main/comps/nginx/nginx.conf.template).
When used as a simple proxy within OPEA application charts (ChatQnA, CodeGen, etc.), parent charts should provide a ConfigMap named `{{ .Release.Name }}-nginx-config` containing environment variables for the [OPEA nginx microservice](https://github.com/opea-project/GenAIComps/blob/main/comps/third_parties/nginx/src/nginx.conf.template).

## Gateway Mode (Central Router)

The nginx chart can be configured to act as a central gateway/router for OPEA services. This mode provides:

- Service routing to multiple OPEA microservices
- Custom nginx configuration template support
- Health check endpoints
- Optional ingress and monitoring support

### How to Use Gateway Mode

Gateway mode is designed to be used within E2E (end-to-end) charts. The pattern is:

1. **Create an E2E chart** that includes nginx as a dependency
2. **Define environment variables** in your E2E chart's `{{ .Release.Name }}-nginx-config` ConfigMap
3. **Use custom nginx template** with environment variable substitution

### Example Implementation

```yaml
# In your E2E chart's templates/nginx-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-nginx-config
data:
FRONTEND_SERVICE_IP: "ui.ui.svc.cluster.local"
FRONTEND_SERVICE_PORT: "5173"
CHATQNA_SERVICE_IP: "chatqna.chatqna.svc.cluster.local"
CHATQNA_SERVICE_PORT: "8888"
EMBEDDING_SERVICE_IP: "embedding-usvc.default.svc.cluster.local"
EMBEDDING_SERVICE_PORT: "6000"
DATAPREP_SERVICE_IP: "data-prep.default.svc.cluster.local"
DATAPREP_SERVICE_PORT: "6007"
# ... other service endpoints
```

```yaml
# In your E2E chart's values.yaml
nginx:
nginxConfig:
enabled: true
template: |
server {
location / {
proxy_pass http://${FRONTEND_SERVICE_IP}:${FRONTEND_SERVICE_PORT};
}
location /v1/chatqna {
proxy_pass http://${CHATQNA_SERVICE_IP}:${CHATQNA_SERVICE_PORT}/v1/chatqna;
}
location /v1/embeddings {
proxy_pass http://${EMBEDDING_SERVICE_IP}:${EMBEDDING_SERVICE_PORT}/v1/embeddings;
}
location /v1/dataprep {
proxy_pass http://${DATAPREP_SERVICE_IP}:${DATAPREP_SERVICE_PORT}/v1/dataprep;
}
# ... other routes
}
```

See `gateway-values.yaml` for a complete example template.

## Deployment Modes

This chart supports two deployment modes:

- **Simple Proxy Mode** (default): Acts as a reverse proxy within OPEA application charts
- **Gateway Mode**: Central router providing unified access to multiple OPEA services (used within E2E charts)

All existing deployments continue to work unchanged. Gateway mode requires creating an E2E chart that follows the pattern shown above.
14 changes: 14 additions & 0 deletions helm-charts/common/nginx/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

{{- if .Values.nginxConfig.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "nginx.fullname" . }}-template-config
labels:
{{- include "nginx.labels" . | nindent 4 }}
data:
default.conf.template: |
{{- .Values.nginxConfig.template | nindent 4 }}
{{- end }}
26 changes: 24 additions & 2 deletions helm-charts/common/nginx/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ spec:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
{{- if .Values.customCommand.enabled }}
command:
{{- toYaml .Values.customCommand.command | nindent 12 }}
args:
{{- toYaml .Values.customCommand.args | nindent 12 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ .Release.Name }}-nginx-config
Expand Down Expand Up @@ -61,13 +67,29 @@ spec:
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
{{- if or .Values.volumeMounts .Values.nginxConfig.enabled }}
volumeMounts:
{{- if .Values.nginxConfig.enabled }}
- name: nginx-conf
mountPath: /etc/nginx/templates/
{{- end }}
{{- with .Values.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- with .Values.volumes }}
{{- if or .Values.volumes .Values.nginxConfig.enabled }}
volumes:
{{- if .Values.nginxConfig.enabled }}
- name: nginx-conf
configMap:
name: {{ include "nginx.fullname" . }}-template-config
items:
- key: default.conf.template
path: default.conf.template
{{- end }}
{{- with .Values.volumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
Expand Down
46 changes: 46 additions & 0 deletions helm-charts/common/nginx/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

{{- if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "nginx.fullname" . }}
labels:
{{- include "nginx.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- with .Values.ingress.className }}
ingressClassName: {{ . }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- with .pathType }}
pathType: {{ . }}
{{- end }}
backend:
service:
name: {{ include "nginx.fullname" $ }}
port:
number: {{ $.Values.service.port }}
{{- end }}
{{- end }}
{{- end }}
18 changes: 18 additions & 0 deletions helm-charts/common/nginx/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

{{- if .Values.global.monitoring }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "nginx.fullname" . }}
labels:
release: {{ .Values.global.prometheusRelease }}
spec:
selector:
matchLabels:
{{- include "nginx.selectorLabels" . | nindent 6 }}
endpoints:
- port: nginx
interval: 5s
{{- end }}
22 changes: 22 additions & 0 deletions helm-charts/common/nginx/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,25 @@ global:
# If set, it will overwrite serviceAccount.name.
# If set, and serviceAccount.create is false, it will assume this service account is already created by others.
sharedSAName: ""

# Custom nginx configuration (optional)
# Allows overriding the default nginx configuration template
nginxConfig:
enabled: false
template: ""

# Custom container startup commands (optional)
# Allows overriding default container startup behavior
customCommand:
enabled: false
command: []
args: []


# Ingress configuration (optional, disabled by default)
ingress:
enabled: false
className: ""
annotations: {}
hosts: []
tls: []
Loading