fava service
This commit is contained in:
85
fava/README.md
Normal file
85
fava/README.md
Normal file
@@ -0,0 +1,85 @@
|
||||
# Fava - Beancount Web UI
|
||||
|
||||
Aquest servei desplega Fava, una interfície web per visualitzar i editar llibres de comptes de Beancount.
|
||||
|
||||
## Configuració
|
||||
|
||||
### 1. Crea el Secret amb les credencials de Gitea
|
||||
|
||||
Primer, crea un token d'accés personal a Gitea (Settings > Applications > Generate New Token).
|
||||
|
||||
Després crea el Secret amb kubectl:
|
||||
|
||||
```bash
|
||||
kubectl create secret generic gitea-credentials \
|
||||
--from-literal=username='el_teu_usuari_gitea' \
|
||||
--from-literal=password='el_teu_token_gitea' \
|
||||
--namespace=fava
|
||||
```
|
||||
|
||||
**Nota:** Assegura't de crear el namespace primer si no existeix:
|
||||
```bash
|
||||
kubectl create namespace fava
|
||||
```
|
||||
|
||||
### 2. Ajusta el fitxer Beancount
|
||||
|
||||
Si el teu fitxer principal no es diu `main.beancount`, actualitza els arguments del contenidor:
|
||||
|
||||
```yaml
|
||||
args:
|
||||
- "/data/contabilitat/el_teu_fitxer.beancount"
|
||||
```
|
||||
|
||||
### 3. Desplega el servei
|
||||
|
||||
```bash
|
||||
kubectl apply -f fava.yaml
|
||||
kubectl apply -f ingress.yaml
|
||||
```
|
||||
|
||||
**Important:** Desplega primer el namespace (que està inclòs a fava.yaml), després crea el Secret, i finalment aplica la resta dels recursos.
|
||||
|
||||
Ordre recomanat:
|
||||
```bash
|
||||
# 1. Crear namespace i recursos base
|
||||
kubectl apply -f fava.yaml
|
||||
|
||||
# 2. Crear el secret (veure pas 1)
|
||||
kubectl create secret generic gitea-credentials \
|
||||
--from-literal=username='el_teu_usuari' \
|
||||
--from-literal=password='el_teu_token' \
|
||||
--namespace=fava
|
||||
|
||||
# 3. Si cal, reinicia el deployment perquè agafi el secret
|
||||
kubectl rollout restart deployment/fava -n fava
|
||||
|
||||
# 4. Aplica l'ingress
|
||||
kubectl apply -f ingress.yaml
|
||||
```
|
||||
|
||||
### 4. Verifica l'estat
|
||||
|
||||
```bash
|
||||
kubectl get pods -n fava
|
||||
kubectl logs -n fava deployment/fava
|
||||
```
|
||||
|
||||
## Accés
|
||||
|
||||
Un cop desplegat, podràs accedir a Fava a: https://fava.rogi.casa
|
||||
|
||||
## Actualització del repositori
|
||||
|
||||
El repositori es clona a l'inici. Per actualitzar-lo amb els últims canvis:
|
||||
|
||||
```bash
|
||||
kubectl rollout restart deployment/fava -n fava
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- El init container clona el repositori de Gitea al volum persistent
|
||||
- Fava s'executa llegint el fitxer directament del repositori clonat
|
||||
- Les credencials es guarden com a Secret de Kubernetes
|
||||
- Usa un token d'accés personal de Gitea en lloc de la teva contrasenya
|
||||
137
fava/fava.yaml
Normal file
137
fava/fava.yaml
Normal file
@@ -0,0 +1,137 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: fava
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: fava-data
|
||||
namespace: fava
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: fava-init-script
|
||||
namespace: fava
|
||||
data:
|
||||
init.sh: |
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# Clone or update the repository
|
||||
if [ ! -d "/data/contabilitat/.git" ]; then
|
||||
echo "Cloning repository..."
|
||||
git clone https://${GITEA_USERNAME}:${GITEA_PASSWORD}@gitea.gitea.svc.cluster.local:3000/${GITEA_USERNAME}/contabilitat.git /data/contabilitat
|
||||
else
|
||||
echo "Repository exists, pulling latest changes..."
|
||||
cd /data/contabilitat
|
||||
git pull
|
||||
fi
|
||||
|
||||
echo "Repository ready at /data/contabilitat"
|
||||
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: fava
|
||||
namespace: fava
|
||||
labels:
|
||||
app: fava
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: fava
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: fava
|
||||
spec:
|
||||
initContainers:
|
||||
- name: git-sync
|
||||
image: alpine/git:latest
|
||||
command: ["/bin/sh", "/scripts/init.sh"]
|
||||
env:
|
||||
- name: GITEA_USERNAME
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: gitea-credentials
|
||||
key: username
|
||||
- name: GITEA_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: gitea-credentials
|
||||
key: password
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data
|
||||
- name: init-script
|
||||
mountPath: /scripts
|
||||
containers:
|
||||
- name: fava
|
||||
image: yegle/fava:latest
|
||||
args:
|
||||
- "/data/contabilitat/main.beancount"
|
||||
- "-H"
|
||||
- "0.0.0.0"
|
||||
- "-p"
|
||||
- "5000"
|
||||
ports:
|
||||
- containerPort: 5000
|
||||
name: http
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data
|
||||
resources:
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
limits:
|
||||
cpu: 500m
|
||||
memory: 512Mi
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: 5000
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: 5000
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: fava-data
|
||||
- name: init-script
|
||||
configMap:
|
||||
name: fava-init-script
|
||||
defaultMode: 0755
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: fava-service
|
||||
namespace: fava
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: fava
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
targetPort: 5000
|
||||
28
fava/ingress.yaml
Normal file
28
fava/ingress.yaml
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: fava-ingress
|
||||
namespace: fava
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: "traefik"
|
||||
traefik.ingress.kubernetes.io/redirect-entry-point: https
|
||||
cert-manager.io/issuer: prod-issuer
|
||||
cert-manager.io/issuer-kind: OriginIssuer
|
||||
cert-manager.io/issuer-group: cert-manager.k8s.cloudflare.com
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- fava.rogi.casa
|
||||
secretName: fava-tls
|
||||
rules:
|
||||
- host: fava.rogi.casa
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: fava-service
|
||||
port:
|
||||
number: 80
|
||||
Reference in New Issue
Block a user