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
*.tar.gz
*.secret.yaml
ntwl.sublime-workspace

View File

@ -1,88 +1,67 @@
---
# ---
apiVersion: v1
kind: PersistentVolume
metadata:
name: crates-postgres-backup-pv
spec:
storageClassName: ""
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
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: v1
# metadata:
# name: crates-postgres-backup-pvc
# spec:
# volumeName: crates-postgres-backup-pv
# accessModes:
# - ReadWriteOnce
# resources:
# requests:
# storage: 1Gi
---
# ---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: crates-postgres-backup-pvc
spec:
volumeName: crates-postgres-backup-pv
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
# apiVersion: batch/v1
# kind: CronJob
# 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"
# pg_dump --dbname=$POSTGRES_URL | gzip > $DEST
# echo "Backup Complete"
apiVersion: batch/v1
kind: CronJob
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 "Removing old copies..."
# find . -type f -name "*.sql.gz" -mtime 7 | xargs rm -v
echo "Backing up to $DEST"
pg_dump --dbname=$POSTGRES_URL | gzip > $DEST
echo "Backup Complete"
# 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
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
kind: Ingress
metadata:
namespace: crates
name: crates-client
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod"
@ -14,19 +15,9 @@ spec:
ingressClassName: haproxy
tls:
- hosts:
- crates.strix.systems
secretName: crates-strix-systems-tls
- crates.ntwl.xyz
secretName: crates-ntwl-xyz-tls
rules:
- host: crates.strix.systems
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: crates-client
port:
number: 8080
- host: crates.ntwl.xyz
http:
paths:
@ -43,6 +34,7 @@ spec:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: crates
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod"
haproxy.org/path-rewrite: "/api(/)?(.*) /$2"
@ -52,19 +44,9 @@ spec:
ingressClassName: haproxy
tls:
- hosts:
- crates.strix.systems
secretName: crates-strix-systems-tls
- crates.ntwl.xyz
secretName: crates-ntwl-xyz-tls
rules:
- host: crates.strix.systems
http:
paths:
- path: /api(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: crates-api
port:
number: 41337
- host: crates.ntwl.xyz
http:
paths:

View File

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

8
ntwl.sublime-project Normal file
View File

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