Skip to content

Commit afc39fa

Browse files
shaohefhteeyeoh
andauthored
Simplify the deployment ProductivitySuite on kubernetes (#919)
Signed-off-by: Shaohe Feng <shaohe.feng@intel.com> Co-authored-by: Hoong Tee, Yeoh <hoong.tee.yeoh@intel.com>
1 parent e1c476c commit afc39fa

File tree

2 files changed

+192
-4
lines changed

2 files changed

+192
-4
lines changed

ProductivitySuite/kubernetes/intel/README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,59 @@ To begin with, ensure that you have following prerequisites in place:
2525
2. 🐳 Images: Make sure you have all the images ready for the examples and components stated above. You may refer to [README](../../docker_compose/intel/cpu/xeon/README.md) for steps to build the images.
2626
3. 🔧 Configuration Values: Set the following values in all the yaml files before proceeding with the deployment:
2727

28+
Download and set up yq for YAML processing:
29+
```
30+
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
31+
sudo chmod a+x /usr/local/bin/yq
32+
33+
cd GenAIExamples/ProductivitySuite/kubernetes/intel/cpu/xeon/manifest/
34+
. ../utils
35+
```
36+
2837
a. HUGGINGFACEHUB_API_TOKEN (Your HuggingFace token to download your desired model from HuggingFace):
2938
```
3039
# You may set the HUGGINGFACEHUB_API_TOKEN via method:
3140
export HUGGINGFACEHUB_API_TOKEN="YourOwnToken"
32-
cd GenAIExamples/ProductivitySuite/kubernetes/intel/cpu/xeon/manifests/
33-
sed -i "s/insert-your-huggingface-token-here/${HUGGINGFACEHUB_API_TOKEN}/g" *.yaml
41+
set_hf_token $HUGGINGFACEHUB_API_TOKEN
3442
```
3543
3644
b. Set the proxies based on your network configuration
3745
```
3846
# Look for http_proxy, https_proxy and no_proxy key and fill up the values for all the yaml files with your system proxy configuration.
47+
set_http_proxy $http_proxy
48+
set_https_proxy $https_proxy
49+
set_no_proxy $no_proxy
3950
```
4051
4152
c. Set all the backend service endpoint for REACT UI service
4253
```
4354
# Setup all the backend service endpoint in productivity_suite_reactui.yaml for UI to consume with.
4455
# Look for ENDPOINT in the yaml and insert all the url endpoint for all the required backend service.
56+
set_services_endpoint
4557
```
4658
4759
4. MODEL_ID and model-volume **(OPTIONAL)**: You may as well customize the "MODEL_ID" to use different model and model-volume for the volume to be mounted.
48-
5. After finish with steps above, you can proceed with the deployment of the yaml file.
60+
```
61+
sudo mkdir -p /mnt/opea-models
62+
sudo chmod -R a+xwr /mnt/opea-models
63+
set_model_id
64+
```
65+
5. MODEL_MIRROR **(OPTIONAL)**: Please set the exact huggingface mirror if cannot access huggingface website directly from your country. You can set it as https://hf-mirror.com in PRC.
66+
```
67+
set_model_mirror
68+
```
69+
6. After finish with steps above, you can proceed with the deployment of the yaml file.
70+
```
71+
git diff
72+
```
4973
5074
---
5175
5276
## 🌐 Deploying ProductivitySuite
5377
You can use yaml files in xeon folder to deploy ProductivitySuite with reactUI.
5478
```
5579
cd GenAIExamples/ProductivitySuite/kubernetes/intel/cpu/xeon/manifests/
56-
kubectl apply -f *.yaml
80+
kubectl apply -f .
5781
```
5882
5983
---
@@ -77,4 +101,11 @@ productivity-suite-react-ui ClusterIP 10.96.3.236 <none> 80/TC
77101
'kubectl port-forward service/productivity-suite-react-ui 5174:80'
78102
```
79103
104+
Or simple way to forward the productivity suite service port.
105+
```
106+
label='app.kubernetes.io/name=react-ui'
107+
port=$(kubectl -n ${ns:-default} get svc -l ${label} -o jsonpath='{.items[0].spec.ports[0].port}')
108+
kubectl port-forward service/productivity-suite-react-ui 5174:$port
109+
```
110+
80111
You may open up the productivity suite react UI by using http://localhost:5174 in the browser.
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
set_model_id() {
2+
if [ -z "$1" ] && [ -z "$2" ]; then
3+
yq -o json '.| select(.data | has("MODEL_ID"))| {"ConfigMap": .metadata.name, "MODEL_ID": .data.MODEL_ID}' *.yaml
4+
echo "usage:"
5+
echo " set_model_id \${ConfigMap} \${MODEL_ID}"
6+
return
7+
fi
8+
conf=$1
9+
file=${1%%-*}
10+
sed -i '/name: '"${conf}"'/,/---/s|\(MODEL_ID:\).*|\1 "'"${2}"'"|' ${file}.yaml
11+
}
12+
13+
set_model_mirror() {
14+
if [ -z "$1" ] ; then
15+
yq -o json '.| select(.data | has("MODEL_ID"))| {"ConfigMap": .metadata.name, "MODEL_MIRROR": .data.HF_ENDPOINT}' *.yaml
16+
echo "usage:"
17+
echo " set_model_mirror \${MODEL_MIRROR}"
18+
return
19+
fi
20+
cm=$(yq -r -o json '.| select(.data | has("MODEL_ID"))| .metadata.name' *.yaml)
21+
mirror=$1
22+
for i in $cm; do
23+
conf=$i
24+
file=${i%%-*}
25+
echo "ConfigMap: $conf set mirror as $mirror"
26+
has_mirror=$(yq -r -o json '.| select(.metadata.name == "'"${conf}"'")| .data.HF_ENDPOINT' ${file}.yaml)
27+
if [ "$has_mirror" == "null" ]; then
28+
sed -i '/name: '"${conf}"'/,/---/s|\(data:\)|\1\n HF_ENDPOINT: "'"${mirror}"'"|' ${file}.yaml
29+
else
30+
sed -i '/name: '"${conf}"'/,/---/s|\(HF_ENDPOINT:\).*|\1 "'"${1}"'"|' ${file}.yaml
31+
fi
32+
done
33+
}
34+
35+
set_hf_token() {
36+
if [ -z "$1" ] ; then
37+
echo "usage:"
38+
echo " set_hf_token \${HF_TOKEN}"
39+
return
40+
fi
41+
sed -i "s/\(HF_TOKEN:\).*/\1 \"${1}\"/g" *.yaml
42+
sed -i "s/\(HUGGINGFACEHUB_API_TOKEN:\).*/\1 \"${1}\"/g" *.yaml
43+
sed -i "s/\(HUGGING_FACE_HUB_TOKEN:\).*/\1 \"${1}\"/g" *.yaml
44+
}
45+
46+
set_https_proxy() {
47+
if [ -z "$1" ] ; then
48+
echo "usage:"
49+
echo " set_https_proxy \${https_proxy}"
50+
return
51+
fi
52+
https_proxy=$1
53+
sed -i -e "s|\(https_proxy:\)\s*\"\"|\1 \"$https_proxy\"|g" *.yaml
54+
sed -i '/https_proxy/{n;s|\(value:\)\s.*""|\1 "'"$https_proxy"'"|g}' *.yaml
55+
}
56+
57+
set_http_proxy() {
58+
if [ -z "$1" ] ; then
59+
echo "usage:"
60+
echo " set_http_proxy \${http_proxy}"
61+
return
62+
fi
63+
http_proxy=$1
64+
sed -i -e "s|\(http_proxy:\)\s*\"\"|\1 \"$http_proxy\"|g" *.yaml
65+
sed -i '/http_proxy/{n;s|\(value:\)\s.*""|\1 "'"$http_proxy"'"|g}' *.yaml
66+
}
67+
68+
set_no_proxy() {
69+
if [ -z "$1" ] ; then
70+
echo "usage:"
71+
echo " set_no_proxy \${no_proxy}"
72+
return
73+
fi
74+
no_proxy=$1
75+
sed -i -e "s|\(no_proxy:\)\s*\"\"|\1 \"$no_proxy\"|g" *.yaml
76+
sed -i '/no_proxy/{n;s|\(value:\)\s.*""|\1 "'"$no_proxy"'"|g}' *.yaml
77+
}
78+
79+
set_backend_service_endpoint() {
80+
for i in $(grep -oP "(?<=APP_BACKEND_SERVICE_ENDPOINT_).*" *.yaml); do
81+
echo $i
82+
name=${i##*:}
83+
file=${name,,}.yaml
84+
svc=$(yq -o json '. | select(.metadata.name == "'"${name,,}"'" and .kind=="Service")' $file)
85+
port=$(jq .spec.ports[0].port <<< $svc)
86+
87+
url=http://${name,,}.${ns:-default}.svc.cluster.local:${port}
88+
echo $url
89+
sed -i -e '/APP_BACKEND_SERVICE_ENDPOINT_'"$name"'/{n;s|\(value:\)\s.*|\1 "'"$url"'"|}' productivity_suite_reactui.yaml
90+
done
91+
}
92+
93+
94+
set_dataprep_service_endpoint() {
95+
name=chatqna-data-prep
96+
file=chatqna.yaml
97+
svc=$(yq -o json '. | select(.metadata.name == "'"$name"'" and .kind=="Service")' $file)
98+
port=$(jq .spec.ports[0].port <<< $svc)
99+
url=http://${name}.${ns:-default}.svc.cluster.local:${port}
100+
echo $url
101+
for i in $(grep -oP "(?<=APP_)DATAPREP.*(?=_ENDPOINT)" *.yaml); do
102+
echo $i
103+
curd=${i##*:};
104+
sed -i -e '/'"$curd"'/{n;s|\(value:\)\s.*|\1 "'"$url"'"|}' productivity_suite_reactui.yaml;
105+
done
106+
}
107+
108+
109+
set_chat_history_endpoint() {
110+
for i in $(grep -oP "(?<=APP_)CHAT_HISTORY.*(?=_ENDPOINT)" *.yaml); do
111+
echo $i;
112+
curd=${i##*:};
113+
name=${curd%_*};
114+
file=${name,,}.yaml;
115+
name=${name/_/-};
116+
svc=$(yq -o json '. | select(.metadata.name == "'"${name,,}"'" and .kind=="Service")' $file)
117+
port=$(jq .spec.ports[0].port <<< $svc)
118+
url=http://${name,,}.${ns:-default}.svc.cluster.local:${port};
119+
echo $url;
120+
sed -i -e '/'"$curd"'/{n;s|\(value:\)\s.*|\1 "'"$url"'"|}' productivity_suite_reactui.yaml;
121+
done
122+
}
123+
124+
125+
set_prompt_service_endpoint() {
126+
for i in $(grep -oP "(?<=APP_)PROMPT_SERVICE.*(?=_ENDPOINT)" *.yaml); do
127+
echo $i;
128+
curd=${i##*:};
129+
curdr=${curd/SERVICE/REGISTRY};
130+
name=${curdr%_*};
131+
file=${name,,}.yaml;
132+
name=${name/_/-};
133+
svc=$(yq -o json '. | select(.metadata.name == "'"${name,,}"'" and .kind=="Service")' $file)
134+
port=$(jq .spec.ports[0].port <<< $svc)
135+
url=http://${name,,}.${ns:-default}.svc.cluster.local:${port};
136+
echo $url;
137+
sed -i -e '/'"$curd"'/{n;s|\(value:\)\s.*|\1 "'"$url"'"|}' productivity_suite_reactui.yaml ;
138+
done
139+
}
140+
141+
set_keycloak_service_endpoint() {
142+
name=keycloak
143+
file=keycloak_install.yaml
144+
svc=$(yq -o json '. | select(.metadata.name == "'"$name"'" and .kind=="Service")' $file)
145+
port=$(jq .spec.ports[0].port <<< $svc)
146+
url=http://${name}.${ns:-default}.svc.cluster.local:${port}
147+
echo $url
148+
sed -i -e '/APP_KEYCLOAK_SERVICE_ENDPOINT/{n;s|\(value:\)\s.*|\1 "'"$url"'"|}' productivity_suite_reactui.yaml
149+
}
150+
151+
set_services_endpoint() {
152+
set_backend_service_endpoint
153+
set_keycloak_service_endpoint
154+
set_chat_history_endpoint
155+
set_prompt_service_endpoint
156+
set_dataprep_service_endpoint
157+
}

0 commit comments

Comments
 (0)