Skip to content

Commit 6a679ba

Browse files
authored
Add Nginx - k8s manifest in CodeTrans (#610)
Signed-off-by: letonghan <letong.han@intel.com>
1 parent 84a781a commit 6a679ba

File tree

4 files changed

+157
-8
lines changed

4 files changed

+157
-8
lines changed

CodeTrans/kubernetes/manifests/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
## Deploy On Xeon
1212

13-
```
13+
```bash
1414
cd GenAIExamples/CodeTrans/kubernetes/manifests/xeon
1515
export HUGGINGFACEHUB_API_TOKEN="YourOwnToken"
1616
sed -i "s/insert-your-huggingface-token-here/${HUGGINGFACEHUB_API_TOKEN}/g" codetrans.yaml
@@ -19,7 +19,7 @@ kubectl apply -f codetrans.yaml
1919

2020
## Deploy On Gaudi
2121

22-
```
22+
```bash
2323
cd GenAIExamples/CodeTrans/kubernetes/manifests/gaudi
2424
export HUGGINGFACEHUB_API_TOKEN="YourOwnToken"
2525
sed -i "s/insert-your-huggingface-token-here/${HUGGINGFACEHUB_API_TOKEN}/g" codetrans.yaml
@@ -30,12 +30,20 @@ kubectl apply -f codetrans.yaml
3030

3131
To verify the installation, run the command `kubectl get pod` to make sure all pods are running.
3232

33-
Then run the command `kubectl port-forward svc/docsum 8888:8888` to expose the CodeTrans service for access.
33+
Then run the command `kubectl port-forward svc/codetrans 7777:7777` to expose the CodeTrans service for access.
3434

3535
Open another terminal and run the following command to verify the service if working:
3636

37-
```console
37+
```bash
3838
curl http://localhost:7777/v1/codetrans \
3939
-H 'Content-Type: application/json' \
4040
-d '{"language_from": "Golang","language_to": "Python","source_code": "package main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n}"}'
4141
```
42+
43+
To consume the service using nginx, run the command below. The `${host_ip}` is the external ip of your server.
44+
45+
```bash
46+
curl http://${host_ip}:30789/v1/codetrans \
47+
-H 'Content-Type: application/json' \
48+
-d '{"language_from": "Golang","language_to": "Python","source_code": "package main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n}"}'
49+
```

CodeTrans/kubernetes/manifests/gaudi/codetrans.yaml

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ data:
2020
http_proxy: ""
2121
https_proxy: ""
2222
no_proxy: ""
23-
LANGCHAIN_TRACING_V2: "false"
24-
LANGCHAIN_API_KEY: insert-your-langchain-key-here
25-
LANGCHAIN_PROJECT: "opea-llm-uservice"
2623
---
2724
# Source: codetrans/charts/tgi/templates/configmap.yaml
2825
# Copyright (C) 2024 Intel Corporation
@@ -338,3 +335,75 @@ spec:
338335
volumes:
339336
- name: tmp
340337
emptyDir: {}
338+
---
339+
# Copyright (C) 2024 Intel Corporation
340+
# SPDX-License-Identifier: Apache-2.0
341+
342+
apiVersion: v1
343+
kind: ConfigMap
344+
metadata:
345+
name: codetrans-nginx-config
346+
data:
347+
default.conf: |
348+
server {
349+
listen 80;
350+
listen [::]:80;
351+
352+
location / {
353+
root /usr/share/nginx/html;
354+
index index.html index.htm;
355+
}
356+
357+
location /v1/codetrans {
358+
proxy_pass http://codetrans:7777;
359+
proxy_set_header Host $host;
360+
proxy_set_header X-Real-IP $remote_addr;
361+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
362+
proxy_set_header X-Forwarded-Proto $scheme;
363+
}
364+
}
365+
---
366+
# Copyright (C) 2024 Intel Corporation
367+
# SPDX-License-Identifier: Apache-2.0
368+
369+
apiVersion: apps/v1
370+
kind: Deployment
371+
metadata:
372+
name: codetrans-nginx-deployment
373+
spec:
374+
replicas: 1
375+
selector:
376+
matchLabels:
377+
app: nginx
378+
template:
379+
metadata:
380+
labels:
381+
app: nginx
382+
spec:
383+
containers:
384+
- name: nginx
385+
image: nginx:latest
386+
ports:
387+
- containerPort: 80
388+
volumeMounts:
389+
- name: nginx-config-volume
390+
mountPath: /etc/nginx/conf.d/default.conf
391+
subPath: default.conf
392+
volumes:
393+
- name: nginx-config-volume
394+
configMap:
395+
name: codetrans-nginx-config
396+
---
397+
kind: Service
398+
apiVersion: v1
399+
metadata:
400+
name: nginx-svc
401+
spec:
402+
selector:
403+
app: nginx
404+
ports:
405+
- protocol: TCP
406+
port: 80
407+
targetPort: 80
408+
nodePort: 30789
409+
type: NodePort

CodeTrans/kubernetes/manifests/xeon/codetrans.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,75 @@ spec:
336336
volumes:
337337
- name: tmp
338338
emptyDir: {}
339+
---
340+
# Copyright (C) 2024 Intel Corporation
341+
# SPDX-License-Identifier: Apache-2.0
342+
343+
apiVersion: v1
344+
kind: ConfigMap
345+
metadata:
346+
name: codetrans-nginx-config
347+
data:
348+
default.conf: |
349+
server {
350+
listen 80;
351+
listen [::]:80;
352+
353+
location / {
354+
root /usr/share/nginx/html;
355+
index index.html index.htm;
356+
}
357+
358+
location /v1/codetrans {
359+
proxy_pass http://codetrans:7777;
360+
proxy_set_header Host $host;
361+
proxy_set_header X-Real-IP $remote_addr;
362+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
363+
proxy_set_header X-Forwarded-Proto $scheme;
364+
}
365+
}
366+
---
367+
# Copyright (C) 2024 Intel Corporation
368+
# SPDX-License-Identifier: Apache-2.0
369+
370+
apiVersion: apps/v1
371+
kind: Deployment
372+
metadata:
373+
name: codetrans-nginx-deployment
374+
spec:
375+
replicas: 1
376+
selector:
377+
matchLabels:
378+
app: nginx
379+
template:
380+
metadata:
381+
labels:
382+
app: nginx
383+
spec:
384+
containers:
385+
- name: nginx
386+
image: nginx:latest
387+
ports:
388+
- containerPort: 80
389+
volumeMounts:
390+
- name: nginx-config-volume
391+
mountPath: /etc/nginx/conf.d/default.conf
392+
subPath: default.conf
393+
volumes:
394+
- name: nginx-config-volume
395+
configMap:
396+
name: codetrans-nginx-config
397+
---
398+
kind: Service
399+
apiVersion: v1
400+
metadata:
401+
name: nginx-svc
402+
spec:
403+
selector:
404+
app: nginx
405+
ports:
406+
- protocol: TCP
407+
port: 80
408+
targetPort: 80
409+
nodePort: 30789
410+
type: NodePort

CodeTrans/tests/test_manifest_on_xeon.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
set -xe
66
USER_ID=$(whoami)
77
LOG_PATH=/home/$(whoami)/logs
8-
MOUNT_DIR=/home/$USER_ID/charts-mnt
8+
MOUNT_DIR=/home/$USER_ID/.cache/huggingface/hub
99
IMAGE_REPO=${IMAGE_REPO:-}
1010
IMAGE_TAG=${IMAGE_TAG:-latest}
1111

0 commit comments

Comments
 (0)