Skip to content

Commit

Permalink
chatbot-rag-app: adds Kubernetes manifest and instructions
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
codefromthecrypt committed Feb 17, 2025
1 parent 2868e7d commit 9f0bb96
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docker/docker-compose-elastic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: elastic-stack

services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.2
container_name: elasticsearch
ports:
- 9200:9200
Expand Down Expand Up @@ -30,7 +30,7 @@ services:
depends_on:
elasticsearch:
condition: service_healthy
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.2
container_name: elasticsearch_settings
restart: 'no'
command: >
Expand All @@ -42,7 +42,7 @@ services:
'
kibana:
image: docker.elastic.co/kibana/kibana:8.17.0
image: docker.elastic.co/kibana/kibana:8.17.2
container_name: kibana
depends_on:
elasticsearch_settings:
Expand All @@ -66,7 +66,7 @@ services:
interval: 1s

apm-server:
image: docker.elastic.co/apm/apm-server:8.17.0
image: docker.elastic.co/apm/apm-server:8.17.2
container_name: apm-server
depends_on:
elasticsearch:
Expand Down
43 changes: 43 additions & 0 deletions example-apps/chatbot-rag-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,49 @@ Clean up when finished, like this:
docker compose down
```

### Run with Kubernetes

Our Kubernetes manifest will run similar to Docker, using host networking by
default to eliminate the need to forward ports or use special hostnames to
access localhost. Unless you change [k8s-manifest.yml](k8s-manifest.yml), the
app chatbot-rag-app will do the following:
* The init-container named "ingest-data" ingests data into elasticsearch
* The container named "api-frontend", listens on http://localhost:4000

**Double-check you have a `.env` file with all your variables set first!**

Then, import your .env file as a configmap like this:
```bash
kubectl create configmap chatbot-rag-app-env --from-env-file=.env
```

If you are using Vertex AI, make a secret for authentication:
```bash
kubectl create secret generic gcloud-credentials \
--from-file=application_default_credentials.json=$HOME/.config/gcloud/application_default_credentials.json
```

Now, apply the manifest:
```bash
kubectl apply -f k8s-manifest.yml
```

*Note*: First time creating the index can fail on timeout. You can verify that
like this:
```bash
kubectl logs -l app=chatbot-rag-app -c ingest-data
```

If you need to retry, do a rolling restart like this:
```bash
kubectl rollout restart deployment/chatbot-rag-app
```

Clean up when finished, like this:
```bash
kubectl delete -f k8s-manifest.yml
```

### Run locally

If you want to run this example with Python and Node.js, you need to do a few
Expand Down
61 changes: 61 additions & 0 deletions example-apps/chatbot-rag-app/k8s-manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: chatbot-rag-app
spec:
replicas: 1
selector:
matchLabels:
app: chatbot-rag-app
template:
metadata:
labels:
app: chatbot-rag-app
spec:
# Simplify networking so that it can look for elasticsearch on localhost
hostNetwork: true
# The below will recreate your secret based on the gcloud credentials file
# kubectl create secret generic gcloud-credentials \
# --from-file=application_default_credentials.json=$HOME/.config/gcloud/application_default_credentials.json
volumes:
- name: gcloud-credentials
secret:
secretName: gcloud-credentials
initContainers:
- name: ingest-data
image: &image ghcr.io/elastic/elasticsearch-labs/chatbot-rag-app:latest
imagePullPolicy: &imagePullPolicy IfNotPresent
args: ["flask", "create-index"]
env:
- name: FLASK_APP
value: api/app.py
# The below will recreate your configmap based on the .env file
# kubectl create configmap chatbot-rag-app-env --from-env-file=.env
envFrom: &envFrom
- configMapRef:
name: chatbot-rag-app-env
volumeMounts: &volumeMounts
- name: gcloud-credentials
mountPath: /root/.config/application_default_credentials.json
readOnly: true
containers:
- name: api-frontend
image: *image
imagePullPolicy: *imagePullPolicy
ports:
- containerPort: 4000
envFrom: *envFrom
volumeMounts: *volumeMounts
---
apiVersion: v1
kind: Service
metadata:
name: api
spec:
selector:
app: chatbot-rag-app
ports:
- protocol: TCP
port: 4000
targetPort: 4000

0 comments on commit 9f0bb96

Please sign in to comment.