Skip to content

Commit 881e2b5

Browse files
yongfengdushaohef
andauthored
Add helm chart for 3 components (#458)
* Add helm chart for 3 components Co-authored-by: Shaohe Feng <[email protected]> Signed-off-by: Dolpher Du <[email protected]>
1 parent bd6f76c commit 881e2b5

26 files changed

+1136
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
apiVersion: v2
5+
name: chathistory-usvc
6+
description: The Helm chart for deploying chat history as microservice
7+
type: application
8+
version: 1.0.0
9+
# The chat history microservice server version
10+
appVersion: "v1.0"
11+
dependencies:
12+
- name: mongodb
13+
version: 1.0.0
14+
repository: file://../mongodb
15+
condition: autodependency.enabled
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# chathistory-usvc
2+
3+
Helm chart for deploying chathistory-usvc microservice.
4+
5+
chathistory-usvc will use redis and tei service, please specify the endpoints.
6+
7+
## (Option1): Installing the chart separately
8+
9+
First, you need to install the mongodb chart, please refer to the [mongodb](../mongodb) for more information.
10+
11+
After you've deployted the mongodb chart successfully, run `kubectl get svc` to get the service endpoint and URL respectively, i.e. `mongodb:27017`.
12+
13+
To install chathistory-usvc chart, run the following:
14+
15+
```console
16+
cd GenAIInfra/helm-charts/common/chathistory-usvc
17+
export MONGO_HOST="mongodb"
18+
export MONGO_PORT="27017"
19+
helm dependency update
20+
helm install chathistory-usvc . --set MONGO_HOST=${MONGO_HOST} --set MONGO_PORT=${MONGO_PORT}
21+
```
22+
23+
## (Option2): Installing the chart with dependencies automatically
24+
25+
```console
26+
cd GenAIInfra/helm-charts/common/chathistory-usvc
27+
helm dependency update
28+
helm install chathistory-usvc . --set autodependency.enabled=true
29+
```
30+
31+
## Verify
32+
33+
To verify the installation, run the command `kubectl get pod` to make sure all pods are running.
34+
35+
Then run the command `kubectl port-forward svc/chathistory-usvc 6012:6012` to expose the chathistory-usvc service for access.
36+
37+
Open another terminal and run the following command to verify the service if working:
38+
39+
```console
40+
curl -X 'POST' \
41+
http://localhost:6012/v1/chathistory/create \
42+
-H 'accept: application/json' \
43+
-H 'Content-Type: application/json' \
44+
-d '{"data": {"messages": "test Messages", "user": "test"}}'
45+
```
46+
47+
## Values
48+
49+
| Key | Type | Default | Description |
50+
| ---------------- | ------ | --------------------------------- | ----------- |
51+
| image.repository | string | `"opea/chathistory-mongo-server"` | |
52+
| service.port | string | `"6012"` | |
53+
| MONGO_HOST | string | `""` | |
54+
| MONGO_PORT | string | `""` | |
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "chathistory-usvc.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "chathistory-usvc.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "chathistory-usvc.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "chathistory-usvc.labels" -}}
37+
helm.sh/chart: {{ include "chathistory-usvc.chart" . }}
38+
{{ include "chathistory-usvc.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "chathistory-usvc.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "chathistory-usvc.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "chathistory-usvc.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "chathistory-usvc.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
apiVersion: v1
5+
kind: ConfigMap
6+
metadata:
7+
name: {{ include "chathistory-usvc.fullname" . }}-config
8+
labels:
9+
{{- include "chathistory-usvc.labels" . | nindent 4 }}
10+
data:
11+
{{- if .Values.MONGO_HOST }}
12+
MONGO_HOST: {{ .Values.MONGO_HOST | quote}}
13+
{{- else }}
14+
MONGO_HOST: "{{ .Release.Name }}-mongodb"
15+
{{- end }}
16+
{{- if .Values.MONGO_PORT }}
17+
MONGO_PORT: {{ .Values.MONGO_PORT | quote }}
18+
{{- else }}
19+
MONGO_PORT: "27017"
20+
{{- end }}
21+
DB_NAME: {{ .Values.DB_NAME | quote }}
22+
COLLECTION_NAME: {{ .Values.COLLECTION_NAME | quote }}
23+
http_proxy: {{ .Values.global.http_proxy | quote }}
24+
https_proxy: {{ .Values.global.https_proxy | quote }}
25+
{{- if and (not .Values.MONGO_HOST) (or .Values.global.http_proxy .Values.global.https_proxy) }}
26+
no_proxy: "{{ .Release.Name }}-mongodb,{{ .Values.global.no_proxy }}"
27+
{{- else }}
28+
no_proxy: {{ .Values.global.no_proxy | quote }}
29+
{{- end }}
30+
LOGFLAG: {{ .Values.LOGFLAG | quote }}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
apiVersion: apps/v1
5+
kind: Deployment
6+
metadata:
7+
name: {{ include "chathistory-usvc.fullname" . }}
8+
labels:
9+
{{- include "chathistory-usvc.labels" . | nindent 4 }}
10+
spec:
11+
replicas: {{ .Values.replicaCount }}
12+
selector:
13+
matchLabels:
14+
{{- include "chathistory-usvc.selectorLabels" . | nindent 6 }}
15+
template:
16+
metadata:
17+
{{- with .Values.podAnnotations }}
18+
annotations:
19+
{{- toYaml . | nindent 8 }}
20+
{{- end }}
21+
labels:
22+
{{- include "chathistory-usvc.selectorLabels" . | nindent 8 }}
23+
spec:
24+
{{- with .Values.imagePullSecrets }}
25+
imagePullSecrets:
26+
{{- toYaml . | nindent 8 }}
27+
{{- end }}
28+
securityContext:
29+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
30+
containers:
31+
- name: {{ .Release.Name }}
32+
envFrom:
33+
- configMapRef:
34+
name: {{ include "chathistory-usvc.fullname" . }}-config
35+
{{- if .Values.global.extraEnvConfig }}
36+
- configMapRef:
37+
name: {{ .Values.global.extraEnvConfig }}
38+
optional: true
39+
{{- end }}
40+
securityContext:
41+
{{- toYaml .Values.securityContext | nindent 12 }}
42+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
43+
imagePullPolicy: {{ .Values.image.pullPolicy }}
44+
ports:
45+
- name: port
46+
containerPort: 6012
47+
protocol: TCP
48+
volumeMounts:
49+
- mountPath: /tmp
50+
name: tmp
51+
{{- if .Values.livenessProbe }}
52+
livenessProbe:
53+
{{- toYaml .Values.livenessProbe | nindent 12 }}
54+
{{- end }}
55+
{{- if .Values.readinessProbe }}
56+
readinessProbe:
57+
{{- toYaml .Values.readinessProbe | nindent 12 }}
58+
{{- end }}
59+
{{- if .Values.startupProbe }}
60+
startupProbe:
61+
{{- toYaml .Values.startupProbe | nindent 12 }}
62+
{{- end }}
63+
resources:
64+
{{- toYaml .Values.resources | nindent 12 }}
65+
volumes:
66+
- name: tmp
67+
emptyDir: {}
68+
{{- with .Values.nodeSelector }}
69+
nodeSelector:
70+
{{- toYaml . | nindent 8 }}
71+
{{- end }}
72+
{{- with .Values.affinity }}
73+
affinity:
74+
{{- toYaml . | nindent 8 }}
75+
{{- end }}
76+
{{- with .Values.tolerations }}
77+
tolerations:
78+
{{- toYaml . | nindent 8 }}
79+
{{- end }}
80+
{{- if .Values.evenly_distributed }}
81+
topologySpreadConstraints:
82+
- maxSkew: 1
83+
topologyKey: kubernetes.io/hostname
84+
whenUnsatisfiable: ScheduleAnyway
85+
labelSelector:
86+
matchLabels:
87+
{{- include "chathistory-usvc.selectorLabels" . | nindent 14 }}
88+
{{- end }}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
apiVersion: v1
5+
kind: Service
6+
metadata:
7+
name: {{ include "chathistory-usvc.fullname" . }}
8+
labels:
9+
{{- include "chathistory-usvc.labels" . | nindent 4 }}
10+
spec:
11+
type: {{ .Values.service.type }}
12+
ports:
13+
- port: {{ .Values.service.port }}
14+
targetPort: 6012
15+
protocol: TCP
16+
name: port
17+
selector:
18+
{{- include "chathistory-usvc.selectorLabels" . | nindent 4 }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
apiVersion: v1
5+
kind: Pod
6+
metadata:
7+
name: {{ include "chathistory-usvc.fullname" . }}-testpod
8+
labels:
9+
{{- include "chathistory-usvc.labels" . | nindent 4 }}
10+
annotations:
11+
"helm.sh/hook": test
12+
#"helm.sh/hook-delete-policy": "hook-succeeded, hook-failure"
13+
spec:
14+
containers:
15+
- name: curl
16+
image: python:3.10.14
17+
command: ['bash', '-c']
18+
args:
19+
- |
20+
set -x
21+
max_retry=20;
22+
for ((i=1; i<=max_retry; i++)); do
23+
curl -X 'POST' \
24+
http://{{ include "chathistory-usvc.fullname" . }}:{{ .Values.service.port }}/v1/chathistory/create -sS --fail-with-body \
25+
-H 'accept: application/json' \
26+
-H 'Content-Type: application/json' \
27+
-d '{"data": {"messages": "test Messages", "user": "test"}}' && break;
28+
curlcode=$?
29+
if [[ $curlcode -eq 7 ]]; then sleep 10; else echo "curl failed with code $curlcode"; exit 1; fi;
30+
done;
31+
if [ $i -gt $max_retry ]; then echo "test failed with maximum retry"; exit 1; fi
32+
restartPolicy: Never

0 commit comments

Comments
 (0)