This commit is contained in:
Nathan Rashleigh 2025-04-12 21:11:40 +10:00
parent 8d43a3f28b
commit c8fb9598a6
5 changed files with 94 additions and 129 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ pvs/
*.sql *.sql
*.tar.gz *.tar.gz
*.secret.yaml *.secret.yaml
ntwl.sublime-workspace

View File

@ -1,88 +1,67 @@
--- # ---
apiVersion: v1 # kind: PersistentVolumeClaim
kind: PersistentVolume # apiVersion: v1
metadata: # metadata:
name: crates-postgres-backup-pv # name: crates-postgres-backup-pvc
spec: # spec:
storageClassName: "" # volumeName: crates-postgres-backup-pv
capacity: # accessModes:
storage: 1Gi # - ReadWriteOnce
accessModes: # resources:
- ReadWriteOnce # requests:
persistentVolumeReclaimPolicy: Retain # storage: 1Gi
claimRef:
namespace: default
name: crates-postgres-backup-pvc
hostPath:
# Into homedir so we can scp it ez
path: "/home/ntr/archives/crates-postgres"
type: DirectoryOrCreate
--- # ---
kind: PersistentVolumeClaim # apiVersion: batch/v1
apiVersion: v1 # kind: CronJob
metadata: # metadata:
name: crates-postgres-backup-pvc # name: crates-db-backup
spec: # spec:
volumeName: crates-postgres-backup-pv # schedule: "20 4 * * *"
accessModes: # jobTemplate:
- ReadWriteOnce # spec:
resources: # template:
requests: # metadata:
storage: 1Gi # labels:
# app: crates-postgres-backup
# spec:
# restartPolicy: Never
# containers:
# - name: crates-postgres-backup
# image: postgres:16
# command:
# - "/bin/sh"
# - "-c"
# -
# |
# cd /mnt/dest/
# TZ="Australia/Melbourne"
# TIMESTAMP=$(date '+%Y-%m-%d-%H-%M-%S')
# DEST=crates-$TIMESTAMP.sql.gz
--- # echo "Backing up to $DEST"
# pg_dump --dbname=$POSTGRES_URL | gzip > $DEST
# echo "Backup Complete"
apiVersion: batch/v1 # echo "Removing old copies..."
kind: CronJob # find . -type f -name "*.sql.gz" -mtime 7 | xargs rm -v
metadata:
name: crates-db-backup
spec:
schedule: "20 4 * * *"
jobTemplate:
spec:
template:
metadata:
labels:
app: crates-postgres-backup
spec:
restartPolicy: Never
containers:
- name: crates-postgres-backup
image: postgres:16
command:
- "/bin/sh"
- "-c"
-
|
cd /mnt/dest/
TZ="Australia/Melbourne"
TIMESTAMP=$(date '+%Y-%m-%d-%H-%M-%S')
DEST=crates-$TIMESTAMP.sql.gz
echo "Backing up to $DEST" # echo "Setting latest link..."
pg_dump --dbname=$POSTGRES_URL | gzip > $DEST # ln -nfs $DEST latest.sql.gz
echo "Backup Complete" # env:
# - name: POSTGRES_URL
# valueFrom:
# secretKeyRef:
# name: crates
# key: POSTGRES_URL
# volumeMounts:
# - name: crates-postgres-backup-storage
# mountPath: /mnt/dest
# volumes:
# - name: crates-postgres-backup-storage
# persistentVolumeClaim:
# claimName: crates-postgres-backup-pvc
echo "Removing old copies..." # ---
find . -type f -name "*.sql.gz" -mtime 7 | xargs rm -v
echo "Setting latest link..."
ln -nfs $DEST latest.sql.gz
env:
- name: POSTGRES_URL
valueFrom:
secretKeyRef:
name: crates
key: POSTGRES_URL
volumeMounts:
- name: crates-postgres-backup-storage
mountPath: /mnt/dest
volumes:
- name: crates-postgres-backup-storage
persistentVolumeClaim:
claimName: crates-postgres-backup-pvc
---

View File

@ -7,6 +7,7 @@
apiVersion: networking.k8s.io/v1 apiVersion: networking.k8s.io/v1
kind: Ingress kind: Ingress
metadata: metadata:
namespace: crates
name: crates-client name: crates-client
annotations: annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod" cert-manager.io/cluster-issuer: "letsencrypt-prod"
@ -14,19 +15,9 @@ spec:
ingressClassName: haproxy ingressClassName: haproxy
tls: tls:
- hosts: - hosts:
- crates.strix.systems - crates.ntwl.xyz
secretName: crates-strix-systems-tls secretName: crates-ntwl-xyz-tls
rules: rules:
- host: crates.strix.systems
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: crates-client
port:
number: 8080
- host: crates.ntwl.xyz - host: crates.ntwl.xyz
http: http:
paths: paths:
@ -43,6 +34,7 @@ spec:
apiVersion: networking.k8s.io/v1 apiVersion: networking.k8s.io/v1
kind: Ingress kind: Ingress
metadata: metadata:
namespace: crates
annotations: annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod" cert-manager.io/cluster-issuer: "letsencrypt-prod"
haproxy.org/path-rewrite: "/api(/)?(.*) /$2" haproxy.org/path-rewrite: "/api(/)?(.*) /$2"
@ -52,19 +44,9 @@ spec:
ingressClassName: haproxy ingressClassName: haproxy
tls: tls:
- hosts: - hosts:
- crates.strix.systems - crates.ntwl.xyz
secretName: crates-strix-systems-tls secretName: crates-ntwl-xyz-tls
rules: rules:
- host: crates.strix.systems
http:
paths:
- path: /api(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: crates-api
port:
number: 41337
- host: crates.ntwl.xyz - host: crates.ntwl.xyz
http: http:
paths: paths:

View File

@ -1,26 +1,13 @@
# -----------------------------------------------------------------------
# VOLUMES
# -----------------------------------------------------------------------
--- ---
apiVersion: v1 apiVersion: v1
kind: PersistentVolume kind: Namespace
metadata: metadata:
name: crates-postgres-pv name: crates
spec:
storageClassName: "" # -----------------------------------------------------------------------
capacity: # VOLUMES
storage: 1Gi # -----------------------------------------------------------------------
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
claimRef:
namespace: default
name: crates-postgres-pvc
hostPath:
path: "/var/lib/rancher/k3s/storage/crates-postgres-pv"
type: DirectoryOrCreate
--- ---
@ -28,13 +15,14 @@ kind: PersistentVolumeClaim
apiVersion: v1 apiVersion: v1
metadata: metadata:
name: crates-postgres-pvc name: crates-postgres-pvc
namespace: crates
spec: spec:
volumeName: crates-postgres-pv storageClassName: zfs-fast
accessModes: accessModes:
- ReadWriteOnce - ReadWriteOnce
resources: resources:
requests: requests:
storage: 1Gi storage: 2Gi
--- ---
@ -46,6 +34,7 @@ apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: crates-postgres name: crates-postgres
namespace: crates
spec: spec:
replicas: 1 replicas: 1
selector: selector:
@ -91,6 +80,7 @@ spec:
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
namespace: crates
name: crates-api name: crates-api
spec: spec:
replicas: 1 replicas: 1
@ -104,7 +94,7 @@ spec:
spec: spec:
containers: containers:
- name: crates-api - name: crates-api
image: registry.strix.systems/crates-api image: registry.ntwl.xyz/crates-api
imagePullPolicy: Always imagePullPolicy: Always
ports: ports:
- containerPort: 80 - containerPort: 80
@ -136,6 +126,7 @@ spec:
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
namespace: crates
name: crates-migrate name: crates-migrate
spec: spec:
replicas: 1 replicas: 1
@ -149,7 +140,7 @@ spec:
spec: spec:
containers: containers:
- name: crates-migrate - name: crates-migrate
image: registry.strix.systems/crates-api image: registry.ntwl.xyz/crates-api
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
command: ["npx"] command: ["npx"]
args: ["prisma", "migrate", "deploy"] args: ["prisma", "migrate", "deploy"]
@ -165,6 +156,7 @@ spec:
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
namespace: crates
name: crates-client name: crates-client
spec: spec:
replicas: 1 replicas: 1
@ -178,7 +170,7 @@ spec:
spec: spec:
containers: containers:
- name: crates-client - name: crates-client
image: registry.strix.systems/crates-client image: registry.ntwl.xyz/crates-client
imagePullPolicy: Always imagePullPolicy: Always
ports: ports:
- containerPort: 8080 - containerPort: 8080
@ -192,6 +184,7 @@ spec:
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
namespace: crates
name: crates-api name: crates-api
spec: spec:
selector: selector:
@ -204,6 +197,7 @@ spec:
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
namespace: crates
name: crates-postgres name: crates-postgres
spec: spec:
selector: selector:
@ -216,6 +210,7 @@ spec:
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
namespace: crates
name: crates-client name: crates-client
spec: spec:
selector: selector:

8
ntwl.sublime-project Normal file
View File

@ -0,0 +1,8 @@
{
"folders":
[
{
"path": "."
}
]
}