Skip to content

Commit 9f0bb96

Browse files
chatbot-rag-app: adds Kubernetes manifest and instructions
Signed-off-by: Adrian Cole <[email protected]>
1 parent 2868e7d commit 9f0bb96

File tree

3 files changed

+108
-4
lines changed

3 files changed

+108
-4
lines changed

docker/docker-compose-elastic.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: elastic-stack
22

33
services:
44
elasticsearch:
5-
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
5+
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.2
66
container_name: elasticsearch
77
ports:
88
- 9200:9200
@@ -30,7 +30,7 @@ services:
3030
depends_on:
3131
elasticsearch:
3232
condition: service_healthy
33-
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
33+
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.2
3434
container_name: elasticsearch_settings
3535
restart: 'no'
3636
command: >
@@ -42,7 +42,7 @@ services:
4242
'
4343
4444
kibana:
45-
image: docker.elastic.co/kibana/kibana:8.17.0
45+
image: docker.elastic.co/kibana/kibana:8.17.2
4646
container_name: kibana
4747
depends_on:
4848
elasticsearch_settings:
@@ -66,7 +66,7 @@ services:
6666
interval: 1s
6767

6868
apm-server:
69-
image: docker.elastic.co/apm/apm-server:8.17.0
69+
image: docker.elastic.co/apm/apm-server:8.17.2
7070
container_name: apm-server
7171
depends_on:
7272
elasticsearch:

example-apps/chatbot-rag-app/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,49 @@ Clean up when finished, like this:
6969
docker compose down
7070
```
7171

72+
### Run with Kubernetes
73+
74+
Our Kubernetes manifest will run similar to Docker, using host networking by
75+
default to eliminate the need to forward ports or use special hostnames to
76+
access localhost. Unless you change [k8s-manifest.yml](k8s-manifest.yml), the
77+
app chatbot-rag-app will do the following:
78+
* The init-container named "ingest-data" ingests data into elasticsearch
79+
* The container named "api-frontend", listens on http://localhost:4000
80+
81+
**Double-check you have a `.env` file with all your variables set first!**
82+
83+
Then, import your .env file as a configmap like this:
84+
```bash
85+
kubectl create configmap chatbot-rag-app-env --from-env-file=.env
86+
```
87+
88+
If you are using Vertex AI, make a secret for authentication:
89+
```bash
90+
kubectl create secret generic gcloud-credentials \
91+
--from-file=application_default_credentials.json=$HOME/.config/gcloud/application_default_credentials.json
92+
```
93+
94+
Now, apply the manifest:
95+
```bash
96+
kubectl apply -f k8s-manifest.yml
97+
```
98+
99+
*Note*: First time creating the index can fail on timeout. You can verify that
100+
like this:
101+
```bash
102+
kubectl logs -l app=chatbot-rag-app -c ingest-data
103+
```
104+
105+
If you need to retry, do a rolling restart like this:
106+
```bash
107+
kubectl rollout restart deployment/chatbot-rag-app
108+
```
109+
110+
Clean up when finished, like this:
111+
```bash
112+
kubectl delete -f k8s-manifest.yml
113+
```
114+
72115
### Run locally
73116

74117
If you want to run this example with Python and Node.js, you need to do a few
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: chatbot-rag-app
6+
spec:
7+
replicas: 1
8+
selector:
9+
matchLabels:
10+
app: chatbot-rag-app
11+
template:
12+
metadata:
13+
labels:
14+
app: chatbot-rag-app
15+
spec:
16+
# Simplify networking so that it can look for elasticsearch on localhost
17+
hostNetwork: true
18+
# The below will recreate your secret based on the gcloud credentials file
19+
# kubectl create secret generic gcloud-credentials \
20+
# --from-file=application_default_credentials.json=$HOME/.config/gcloud/application_default_credentials.json
21+
volumes:
22+
- name: gcloud-credentials
23+
secret:
24+
secretName: gcloud-credentials
25+
initContainers:
26+
- name: ingest-data
27+
image: &image ghcr.io/elastic/elasticsearch-labs/chatbot-rag-app:latest
28+
imagePullPolicy: &imagePullPolicy IfNotPresent
29+
args: ["flask", "create-index"]
30+
env:
31+
- name: FLASK_APP
32+
value: api/app.py
33+
# The below will recreate your configmap based on the .env file
34+
# kubectl create configmap chatbot-rag-app-env --from-env-file=.env
35+
envFrom: &envFrom
36+
- configMapRef:
37+
name: chatbot-rag-app-env
38+
volumeMounts: &volumeMounts
39+
- name: gcloud-credentials
40+
mountPath: /root/.config/application_default_credentials.json
41+
readOnly: true
42+
containers:
43+
- name: api-frontend
44+
image: *image
45+
imagePullPolicy: *imagePullPolicy
46+
ports:
47+
- containerPort: 4000
48+
envFrom: *envFrom
49+
volumeMounts: *volumeMounts
50+
---
51+
apiVersion: v1
52+
kind: Service
53+
metadata:
54+
name: api
55+
spec:
56+
selector:
57+
app: chatbot-rag-app
58+
ports:
59+
- protocol: TCP
60+
port: 4000
61+
targetPort: 4000

0 commit comments

Comments
 (0)