From da4b9c25b12ad6b4df703458f1624c2faa8ee3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Fernandes?= Date: Fri, 18 Apr 2025 22:03:05 +0000 Subject: [PATCH] refactoring and documentation --- README.md | 36 ++++++++--- ingress.yml | 59 ------------------ jobs/backup/backup-cronjob.yaml | 15 +++-- jobs/backup/secret-deploy.sh | 8 --- jobs/backup/tests/mysql-client-test-pod.yaml | 63 -------------------- local/.gitignore | 2 - nexcloud/helm-up.sh | 5 -- {nexcloud => nextcloud}/.gitignore | 0 {nexcloud => nextcloud}/values.yaml | 0 9 files changed, 36 insertions(+), 152 deletions(-) delete mode 100644 ingress.yml delete mode 100755 jobs/backup/secret-deploy.sh delete mode 100644 jobs/backup/tests/mysql-client-test-pod.yaml delete mode 100644 local/.gitignore delete mode 100755 nexcloud/helm-up.sh rename {nexcloud => nextcloud}/.gitignore (100%) rename {nexcloud => nextcloud}/values.yaml (100%) diff --git a/README.md b/README.md index b62b3f4..a302563 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,16 @@ Welcome to public repository of [https://cloud.limbosolutions.com](https://cloud Using [NextCloud](https://nextcloud.com/) -## kubernetes +- [Setup](#setup) + - [kubernetes Namespace](#kubernetes-namespace) + - [Add helm chart](#add-helm-chart) + - [Update Helm chart](#update-helm-chart) + - [Install / Update](#install--update) +- [backups](#backups) -### namespace +## Setup + +### kubernetes Namespace ``` yaml apiVersion: v1 @@ -17,19 +24,34 @@ metadata: name: cloud-limbosolutions-com ``` -### helm chart - nextcloud +### Add helm chart ``` bash helm repo add nextcloud https://nextcloud.github.io/helm/ +``` + +### Update Helm chart + +```bash helm repo update ``` -Install/Upgrade Helm Chart +### Install / Update ``` bash -./nexcloud/helm-up.sh +helm upgrade --install nextcloud nextcloud/nextcloud \ +--values ./nextcloud/values.yaml \ +--values ./nextcloud/values.local.yaml \ +--namespace=cloud-limbosolutions-com ``` -## backup +## backups + +``` bash +set -a +source ./jobs/backup/.env +set +a +envsubst < ./jobs/backup/secret.yaml | kubectl apply -f - +kubectl apply -f ./jobs/backup/backup-cronjob.yaml +``` -[kubernets cron job](./jobs/backup) \ No newline at end of file diff --git a/ingress.yml b/ingress.yml deleted file mode 100644 index 7eb881e..0000000 --- a/ingress.yml +++ /dev/null @@ -1,59 +0,0 @@ -# not in use. remove and add to kb -# ingress exposing and endpoint to an docker running on another server without kubernets -apiVersion: v1 -kind: Endpoints -metadata: - name: cloud-limbosolutions-com-service - namespace: cloud-limbosolutions-com -subsets: -- addresses: - - ip: 192.168.13.2 - ports: - - name: app - port: 4000 - protocol: TCP - - ---- - -apiVersion: v1 -kind: Service -metadata: - name: cloud-limbosolutions-com-service - namespace: cloud-limbosolutions-com -spec: - ports: - - name: app - port: 4000 - protocol: TCP - targetPort: 4000 - clusterIP: None - type: ClusterIP - - ---- -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: cloud-limbosolutions-com-ingress - namespace: cloud-limbosolutions-com - # annotations: - # cert-manager.io/cluster-issuer: "letsencrypt-staging" - # traefik.ingress.kubernetes.io/router.entrypoints: websecure -spec: - ingressClassName: traefik - # tls: - # - hosts: - # - minio.example.com - # secretName: tls-example-com - rules: - - host: cloud.icharus.dev.lan - http: - paths: - - backend: - service: - name: cloud-limbosolutions-com-service - port: - number: 4000 - path: / - pathType: Prefix \ No newline at end of file diff --git a/jobs/backup/backup-cronjob.yaml b/jobs/backup/backup-cronjob.yaml index cb3f852..de55774 100644 --- a/jobs/backup/backup-cronjob.yaml +++ b/jobs/backup/backup-cronjob.yaml @@ -24,14 +24,10 @@ spec: command: ["bash", "-c"] args: - | - #while true; do sleep 30; done + set -e mkdir -p /data/mariadb-export echo "TRACE: Exporting database" mysqldump --column-statistics=0 -u ${MYSQL_USER} -h ${MYSQL_HOST} ${MYSQL_DB} > /data/mariadb-export/backup.sql - if [ $? -ne 0 ]; then - echo "ERROR: Exporting database failed" - exit 1 - fi echo "TRACE: Exporting database finished" env: @@ -90,9 +86,12 @@ spec: command: ["bash", "-c"] args: - | - proxmox-backup-client backup nextcloud-html.pxar:/data/nextcloud-html nextcloud-data.pxar:/data/nextcloud-data mariadb-data.pxar:/data/mariadb-data mariadb-export.pxar:/data/mariadb-export --include-dev /data/nextcloud-html --include-dev /data/nextcloud-data --include-dev /data/mariadb-data --include-dev /data/mariadb-export --backup-id "nextcloud-full" -ns cloud.limbosolutions.com - echo "INFO: Backup cloud.limbosolutions.com finished" - + set -e + SCRIPT_START_TIME=$(date +%s) + proxmox-backup-client backup nextcloud-html.pxar:/data/nextcloud-html nextcloud-data.pxar:/data/nextcloud-data mariadb-data.pxar:/data/mariadb-data mariadb-export.pxar:/data/mariadb-export --include-dev /data/nextcloud-html --include-dev /data/nextcloud-data --include-dev /data/mariadb-data --include-dev /data/mariadb-export --backup-id "nextcloud-full" -ns cloud.limbosolutions.com && \ + SCRIPT_DURATION=$(($(date +%s) - SCRIPT_START_TIME)) && \ + echo "INFO: Finished Backup of cloud.limbosolutions.com ($((SCRIPT_DURATION / 60 / 60)):$((SCRIPT_DURATION / 60)):$((SCRIPT_DURATION % 60)))" + volumeMounts: - name: nextcloud-html mountPath: /data/nextcloud-html diff --git a/jobs/backup/secret-deploy.sh b/jobs/backup/secret-deploy.sh deleted file mode 100755 index 2cd37b8..0000000 --- a/jobs/backup/secret-deploy.sh +++ /dev/null @@ -1,8 +0,0 @@ -#/bin/bash - -# set source env variables -. ./.env -export $(cut -d= -f1 ./.env) - - -envsubst < secret.yaml | kubectl apply -f - \ No newline at end of file diff --git a/jobs/backup/tests/mysql-client-test-pod.yaml b/jobs/backup/tests/mysql-client-test-pod.yaml deleted file mode 100644 index 43eb7cd..0000000 --- a/jobs/backup/tests/mysql-client-test-pod.yaml +++ /dev/null @@ -1,63 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: mariadb-client-test-pod - namespace: cloud-limbosolutions-com -spec: - containers: - - name: mariadb-client - resources: - limits: - memory: "512Mi" - cpu: "500m" - requests: - memory: "256Mi" - cpu: "250m" - image: bitnami/mysql:latest - command: ["bash", "-c"] - args: - - | - #while true; do sleep 30; done - mkdir -p /data/mariadb-export - echo "INFO: Exporting database" - mysqldump --column-statistics=0 -u ${DB_USER} -p${DB_PASSWORD} -h ${DB_HOST} ${DB_NAME} > /data/mariadb-export/backup.sql - if [ $? -ne 0 ]; then - echo "ERROR: Exporting database failed" - exit 1 - fi - echo "INFO: Exporting database finished" - - env: - - name: DB_USER - valueFrom: - secretKeyRef: - name: nextcloud-db - key: db-username - - - name: DB_PASSWORD - valueFrom: - secretKeyRef: - name: nextcloud-db - key: db-password - - - name: DB_NAME - valueFrom: - secretKeyRef: - name: backup-secret - key: DB_NAME - - - name: DB_HOST - valueFrom: - secretKeyRef: - name: backup-secret - key: DB_HOST - - volumeMounts: - - name: backup-var - mountPath: /data/mariadb-export - subPath: mariadb-export - - - volumes: - - name: backup-var - emptyDir: {} \ No newline at end of file diff --git a/local/.gitignore b/local/.gitignore deleted file mode 100644 index d29675e..0000000 --- a/local/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -** -!.gitignore \ No newline at end of file diff --git a/nexcloud/helm-up.sh b/nexcloud/helm-up.sh deleted file mode 100755 index 8856708..0000000 --- a/nexcloud/helm-up.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -helm upgrade --install nextcloud nextcloud/nextcloud \ ---values ./values.yaml \ ---values ./values.local.yaml \ ---namespace=cloud-limbosolutions-com diff --git a/nexcloud/.gitignore b/nextcloud/.gitignore similarity index 100% rename from nexcloud/.gitignore rename to nextcloud/.gitignore diff --git a/nexcloud/values.yaml b/nextcloud/values.yaml similarity index 100% rename from nexcloud/values.yaml rename to nextcloud/values.yaml