Commit 01e4c9fc authored by Carlos Juliano Viana's avatar Carlos Juliano Viana
Browse files

Atualizando arquivo de deploymento do sga.

Adicionado arquivo de README
Adicionado script para gerar o arquivo de deployment no k8s: ainda em TODO.
Commit parcial para salvar o trabalho.

[SOMA-4444]
[SOMA-4158]
parent 3b7c5da3
Pipeline #34641 skipped
# SGA Kubernetes Deployment
## Arquivo de configuração sgad.cfg
O sgarest-daemon é executado informado um arquivo de configuração. Por padrão utilizamos o nome _sgad.cfg_. Para o deployment no Kubernetes podemos configurar o sgarest-daemon tanto pelas variáveis de ambiente do arquivo de deployment ou utilizar o recurso do ConfigMap para flexibilizar a sua configuração.
### Gerar ConfigMap
Para gerar um ConfigMap inicial a partir do arquivo de configuração da pasta Docker/posix:
```bash
$ kubectl create configmap sgarest-posix-latest-config-dev --from-file=Docker/posix/sgad.cfg --namespace soma-dev --dry-run -o yaml > sgarest-posix-latest-config-dev.yml
```
**ConfigMap**
```bash
$ cat sgarest-posix-latest-config-dev.yml
apiVersion: v1
data:
sgad.cfg: |
csbase_server = os.getenv("CSBASE_SERVER")
platform = os.getenv("SGAD_PLATFORM") or "Linux44_64"
sgad_host = os.getenv("SGAD_HOST")
sgad_port = tonumber(os.getenv("SGAD_PORT"))
sga_name = os.getenv("SGAD_NAME")
status_interval_s = 10
exec_polling_interval_s = 5
register_retry_s = 3
project_root_dir = "/sgad/projects"
algorithm_root_dir = "/sgad/algorithms"
runtime_data_dir = "/tmp/sgad"
sandbox_root_dir = "/tmp/sgad/sandbox"
driver = "sga.driver.posix"
resources = {
"docker"
}
kind: ConfigMap
metadata:
creationTimestamp: null
name: sgarest-posix-latest-config-dev
namespace: soma-dev
```
**Instalar o ConfigMap**
```bash
$ kubectl -n soma-dev -f sgarest-posix-latest-config-dev.yml apply
$ kubectl -n soma-dev label configmap sgarest-posix-latest-config-dev app=sgarest-daemon-posix --overwrite
$ kubectl -n soma-dev label configmap sgarest-posix-latest-config-dev date=$(date +'%Y-%m-%d_%H-%M-%S') --overwrite
```
**Arquivo Deployment**
O arquivo YAML do Deployment do servidor do sgarest-daemon no cluster kubernetes é gerado a partir de um arquivo de template e do script _make-sga-deployment-yml.sh_. O script gera na saída padrão o arquivo para Deployment em um determinado namespace do cluster.
```bash
$ make-sga-deployment-yml.sh <namespace> <name-resorce> <version> <configmap-name>
```
Onde:
* <namespace>: nome do namespace onde será instalado o servidor
* <name-resource>: nome do servidor que será utilizado como prefixo para os demais recursos do deployment. Ex.: "sgarest-daemon-posix"
* <version>: versão da imagem do sgarest-daemon posix que será utilizada.
* <configmap-name>: o nome do configmap que criado que contém as configurações do arquivo sgad.cfg.
**Instalar o SGA**
```bash
$ kubectl -n <namesapce> -f <sgarest-daemon-file-deployment> apply
```
\ No newline at end of file
apiVersion: apps/v1
kind: Deployment
metadata:
name: sgarest-daemon-posix-latest-dev
namespace: soma-dev
spec:
replicas: 1
selector:
matchLabels:
app: sgarest-daemon-posix-latest-dev
template:
metadata:
labels:
app: sgarest-daemon-posix-latest-dev
spec:
containers:
- name: sgarest-posix-latest
image: repo.tecgraf.puc-rio.br:18089/soma/sga-dind:1.7.0
imagePullPolicy: "Always"
ports:
- containerPort: 40100 # SGA REST
- containerPort: 40500 # CSBASE SERVER PORT TO REGISTRY
env:
- name: CSBASE_SERVER
value: "http://eras-server-latest-service.soma-dev:40500"
- name: SGAD_PLATFORM
value: "Linux44_64"
- name: SGAD_HOST
value: "sgarest-daemon-posix-latest-service.soma-dev"
- name: SGAD_PORT
value: "40100"
- name: SGAD_NAME
value: "sgarest-posix-latest-dev"
volumeMounts:
- name: sgarest-daemon-config-dev-storage
mountPath: /sgad
- name: csbase-data-dev-storage
mountPath: /sgad/projects
subPath: projects
- name: csbase-data-dev-storage
mountPath: /sgad/algorithms
subPath: algorithms
- name: csbase-data-dev-storage
mountPath: /sgad/logs
subPath: logs
volumes:
- name: sgarest-daemon-config-dev-storage
configMap:
name: sgarest-posix-latest-config-dev
- name: csbase-data-dev-storage
persistentVolumeClaim:
claimName: csbase-files-pvc
---
apiVersion: v1
kind: Service
metadata:
name: sgarest-daemon-posix-latest-service
namespace: soma-dev
labels:
app: sgarest-daemon-posix-latest-dev
spec:
ports:
- port: 40100
targetPort: 40100
name: sgarest-daemon-posix-latest-rest
- port: 40500
targetPort: 40500
name: sgarest-daemon-posix-latest-server-registry
selector:
app: sgarest-daemon-posix-latest-dev
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: sgarest-posix-latest-rest.dev.soma.k8stec.tecgraf.puc-rio.br
namespace: soma-dev
spec:
rules:
- host: sgarest-posix-latest-rest.dev.soma.k8stec.tecgraf.puc-rio.br
http:
paths:
- backend:
serviceName: sgarest-daemon-posix-latest-service
servicePort: 40100
# ---
# apiVersion: extensions/v1beta1
# kind: Ingress
# metadata:
# name: <application-name>-ingress-kong-<application-env>
# namespace: <application-context>
# annotations:
# kubernetes.io/ingress.class: kong-<application-env>
# spec:
# rules:
# - http:
# paths:
# - path: /forum
# backend:
# serviceName: <application-name>-service
# servicePort: 80
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment