# Deploy Jarvix on Kubernetes

#### Kubernets prerequest:
- kubernetes version
- pv set up (nfs/cbs/so on )
- ingress nameing
- namespaces
- docker repo : reg.sis.ai:31443
- private docker repo :* Optional *
### Deployment:
├── algo-api-deployment.yaml
├── automl-deployment.yaml
├── external-api-deployment.yaml
├── frontend-deployment.yaml
├── h2o-deployment.yaml
├── nginx-deployment.yaml
├── private-api-deployment.yaml
├── public-api-deployment.yaml
└── task-api-deployment.yaml
:::info
in order to pull docker images from reg.sis.ai:31443 please use secrets list below
regcred created by kubectl with `kubectl create secret generic regcred \
--from-file=.dockerconfigjson=<path/to/.docker/config.json> \
--type=kubernetes.io/dockerconfigjson`
:::
* for frontend/borabora needs configMap to addjust the config.js in volume
etc : `kubectl create cm borabora-config --from-file=/tmp/config.js`
code define in deployment for both borabora & frontend
```
spec:
containers:
- image: reg.sis.ai:8443/jarvix/frontend:release-v3.1.0
name: frontend
ports:
- containerPort: 8097
volumeMounts:
- name: frontend-conf
mountPath: /opt/sygps/borabora/dist/static/config.js
subPath: config.js
volumes:
- name: frontend-conf
configMap:
name: frontend-config
```
---
### Persistent Volume Claim
.
├── elastic-pv.yaml
├── kafka-pv.yaml
├── postgres-pv.yaml
└── sftp-pv.yaml
:::warning
the pvc are written in NFS usages only
:::
---
### Optional private docker repo
please prepear a docker repo inorder to store and pull the docker images
:::info
if like to change to private docker registry may need to create secrets for imagePullSecrets:
Ref: https://kubernetes.io/zh-cn/docs/tasks/configure-pod-container/pull-image-private-registry/
:::
## install stpes
### 1 helm install
* `https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash` *
#### 1.1 helm repo add
`helm repo add bitnami https://charts.bitnami.com/bitnami`
`helm pull bitnami/kafka`
`helm pull bitnami/postgresql-ha`
`helm repo add emberstack https://emberstack.github.io/helm-charts`
`helm pull emberstack/sftp`
`helm repo add elastic https://helm.elastic.co`
`helm pull elastic/elasticsearch-7.17.3`
#### 1.2 untar the downloaded charts
`tar -zxvf <charts-name>.tar.gz `
#### 1.3 install helm charts
`kubectl create ns jarvix`
`helm install "sis-sftp|postgres|kafka" -n jarvix . `
| charts | repo | version |
| ------ | ---- | ----|
| kafka/zookeeper | https://charts.bitnami.com/bitnami | kafka-18.0.3|
| postgresql | https://charts.bitnami.com/bitnami | postgresql-11.6.19|
| sis-sftp | https://emberstack.github.io/helm-charts | sftp-5.1.5|
| elastic | https://helm.elastic.co | elasticsearch-7.17.3|
#### Helm usage ref: https://helm.sh/docs/intro/install/ *
:::danger
may need to edit directly statefulset for postgres-postgresql / kafka/ kafka-zookeeper / elastaticsearch
addjust terminationGracePeriodSeconds to '0', if would like to having auto-failover for statefulsets , please keep in mind the data consistency
:::
#### step 2 delpoy each jarvix micro-services
`kubectl apply -f deployments/ -n jarvix `
:::info
it will apply and create all the deployment in deployment folder
:::
#### step3 expose 3 deployment to NodePort service
```
kubectl expose deploy public-api --port=8081 --target-port=8081 --type=NodePort -n jarvix
kubectl expose deploy frontend --port=8097 --target-port=8097 --type=NodePort -n jarvix
kubectl expose deploy borabora --port=8090 --target-port=8090 --type=NodePort -n jarvix
```
:::warning
Please refer to servicePort below and using kubectl to modify the services
:::
```NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
algo-api NodePort 10.244.86.253 <none> 8086:31019/TCP 32d app=algo-api
automl NodePort 10.244.73.134 <none> 22:32396/TCP 31d app=automl
elasticsearch NodePort 10.244.120.46 <none> 9200:32018/TCP 33d app=elasticsearch
external-api NodePort 10.244.85.186 <none> 8080:32186/TCP 33d app=external-api
frontend NodePort 10.244.112.41 <none> 8097:31964/TCP 33d app=frontend
h2o NodePort 10.244.83.73 <none> 9000:30389/TCP 33d app=h2o
kafka ClusterIP 10.244.87.207 <none> 9092/TCP 33d app.kubernetes.io/component=kafka,app.kubernetes.io/instance=kafka,app.kubernetes.io/name=kafka
kafka-headless ClusterIP None <none> 9092/TCP,9093/TCP 33d app.kubernetes.io/component=kafka,app.kubernetes.io/instance=kafka,app.kubernetes.io/name=kafka
kafka-zookeeper ClusterIP 10.244.83.72 <none> 2181/TCP,2888/TCP,3888/TCP 33d app.kubernetes.io/component=zookeeper,app.kubernetes.io/instance=kafka,app.kubernetes.io/name=zookeeper
kafka-zookeeper-headless ClusterIP None <none> 2181/TCP,2888/TCP,3888/TCP 33d app.kubernetes.io/component=zookeeper,app.kubernetes.io/instance=kafka,app.kubernetes.io/name=zookeeper
kubernetes ClusterIP 10.244.64.1 <none> 443/TCP 33d <none>
nginx NodePort 10.244.116.239 <none> 8090:32658/TCP 33d app=nginx
postgres-postgresql NodePort 10.244.67.0 <none> 5432:30432/TCP 32d app.kubernetes.io/component=primary,app.kubernetes.io/instance=postgres,app.kubernetes.io/name=postgresql
postgres-postgresql-hl ClusterIP None <none> 5432/TCP 32d app.kubernetes.io/component=primary,app.kubernetes.io/instance=postgres,app.kubernetes.io/name=postgresql
private-api NodePort 10.244.68.241 <none> 8082:30082/TCP 33d app=private-api
public-api NodePort 10.244.109.122 <none> 8081:30081/TCP 4h22m app=public-api
schedule-api NodePort 10.244.71.247 <none> 8086:31088/TCP 33d app=schedule-api
sis-sftp NodePort 10.244.116.144 <none> 22:30601/TCP 5d4h app.kubernetes.io/instance=sis-sftp,app.kubernetes.io/name=sftp
task-api NodePort 10.244.73.199 <none> 8083:30083/TCP 33d app=task-api
```
### Service
.
├── algo-api-service.yaml
├── automl-service.yaml
├── borabora-service.yaml
├── elasticsearch-service.yaml
├── external-api-service.yaml
├── frontend-service.yaml
├── h2o-service.yaml
├── private-api-service.yaml
├── public-api-service.yaml
├── schedule-api-service.yaml
├── sis-sftp-service.yaml
└── task-api-service.yaml
:::danger
PostgreSQL needs to volume postgresql.conf / pg_hbd.conf inorder to using custom configs or connection will be faild
:::
#### Postgres PV
by appling postgres-pv.yaml to create a NFS volume to store configs and data which store in PostgreSQL
before appling postgres-pv you may need to create nfs-share by nfs-utils and editing /etc/exports/
create a folder to place pg_hba.conf and postgresql.conf synergies privde in the share folder
#### elasticsearch PV
by appling elastic-pv.yaml to create a NFS volume to store configs and data which store in elasticsearch
#### sis-sftp PV
by appling sftp-pv.yaml to create a NFS volume to store configs and data which store in sis-sftp