Initial commit: k8s cluster manifests and scripts

This commit is contained in:
2026-04-01 15:34:02 +08:00
commit 2f04fa4473
49 changed files with 4109 additions and 0 deletions

23
apps/opengist/backup.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -e
BACKUP_DIR="./backup"
TIMESTAMP=$(date +"%Y%m%d-%H%M")
BACKUP_FILE="${BACKUP_DIR}/opengist-${TIMESTAMP}.tar.gz"
mkdir -p "${BACKUP_DIR}"
echo "📦 Creating backup: ${BACKUP_FILE}"
POD=$(kubectl get pod -l app=opengist -o jsonpath='{.items[0].metadata.name}')
if [ -z "${POD}" ]; then
echo "❌ OpenGist pod not found"
exit 1
fi
kubectl exec "${POD}" -- \
tar czf - /opengist > "${BACKUP_FILE}"
echo "✅ Backup completed: ${BACKUP_FILE}"

Binary file not shown.

18
apps/opengist/deploy.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e
MANIFESTS_DIR="./manifests"
echo "🚀 Deploying OpenGist from ${MANIFESTS_DIR} ..."
kubectl apply -f "${MANIFESTS_DIR}/opengist-pvc.yaml"
kubectl apply -f "${MANIFESTS_DIR}/opengist-deployment.yaml"
kubectl apply -f "${MANIFESTS_DIR}/opengist-svc-web.yaml"
kubectl apply -f "${MANIFESTS_DIR}/opengist-svc-ssh.yaml"
kubectl apply -f "${MANIFESTS_DIR}/opengist-ingress.yaml"
echo "⏳ Waiting for deployment to be ready..."
kubectl rollout status deployment/opengist
echo "✅ OpenGist deployed successfully"

View File

@@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: opengist
namespace: default
labels:
app: opengist
spec:
replicas: 1
selector:
matchLabels:
app: opengist
template:
metadata:
labels:
app: opengist
spec:
containers:
- name: opengist
image: ghcr.io/thomiceli/opengist:latest
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 6157
- name: ssh
containerPort: 2222
resources:
limits:
memory: "512Mi"
cpu: "500m"
volumeMounts:
- name: data-vol
mountPath: /opengist
volumes:
- name: data-vol
persistentVolumeClaim:
claimName: opengist-pvc

View File

@@ -0,0 +1,39 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: opengist-ingress
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web,websecure
spec:
ingressClassName: traefik
tls:
- hosts:
- opengist.lotimmy.com
- opengist.192.168.42.120.nip.io
secretName: nip-io-cert
rules:
- host: opengist.lotimmy.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: opengist-web
port:
number: 6157
- host: opengist.192.168.42.120.nip.io
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: opengist-web
port:
number: 6157

View File

@@ -0,0 +1,13 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: opengist-pvc
namespace: default
spec:
storageClassName: longhorn
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi

View File

@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: opengist-ssh
namespace: default
spec:
type: NodePort
selector:
app: opengist
ports:
- name: ssh
port: 2222
targetPort: 2222
protocol: TCP
nodePort: 32222

View File

@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: opengist-web
namespace: default
spec:
type: ClusterIP
selector:
app: opengist
ports:
- name: http
port: 6157
targetPort: 6157
protocol: TCP

81
apps/opengist/restore.sh Executable file
View File

@@ -0,0 +1,81 @@
#!/usr/bin/env bash
set -e
BACKUP_DIR="./backup"
if [ $# -ne 1 ]; then
echo "❌ Usage: ./restore.sh <backup-file>"
echo
echo "Example:"
echo " ./restore.sh opengist-20250101-1200.tar.gz"
exit 1
fi
BACKUP_FILE="${BACKUP_DIR}/$1"
if [ ! -f "${BACKUP_FILE}" ]; then
echo "❌ Backup file not found: ${BACKUP_FILE}"
exit 1
fi
echo "⚠️ WARNING"
echo "This will OVERWRITE data in /opengist inside the PVC."
echo "Backup file: ${BACKUP_FILE}"
echo
read -p "Type YES to continue: " CONFIRM
if [ "${CONFIRM}" != "YES" ]; then
echo "❌ Restore aborted"
exit 1
fi
echo "🛑 Scaling down OpenGist deployment..."
kubectl scale deployment opengist --replicas=0
echo "⏳ Waiting for pod termination..."
kubectl wait --for=delete pod -l app=opengist --timeout=60s || true
echo "📦 Starting restore process..."
# 使用暫時 helper pod 掛載同一顆 PVC
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: opengist-restore
spec:
restartPolicy: Never
containers:
- name: restore
image: alpine:3.20
command: ["sleep", "3600"]
volumeMounts:
- name: data-vol
mountPath: /opengist
volumes:
- name: data-vol
persistentVolumeClaim:
claimName: opengist-pvc
EOF
echo "⏳ Waiting for restore pod to be ready..."
kubectl wait --for=condition=Ready pod/opengist-restore --timeout=60s
echo "🧹 Cleaning existing data..."
kubectl exec opengist-restore -- rm -rf /opengist/*
echo "📂 Restoring backup..."
kubectl exec -i opengist-restore -- \
tar xzf - -C / < "${BACKUP_FILE}"
echo "🧹 Cleaning up restore pod..."
kubectl delete pod opengist-restore
echo "🚀 Scaling OpenGist back up..."
kubectl scale deployment opengist --replicas=1
echo "⏳ Waiting for OpenGist to be ready..."
kubectl rollout status deployment/opengist
echo "✅ Restore completed successfully"

27
apps/opengist/status.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env bash
echo
echo "=== Pod ==="
kubectl get pod -l app=opengist -o wide
echo
echo "=== Deployment ==="
kubectl get deployment opengist
echo
echo "=== Services ==="
kubectl get svc opengist-web opengist-ssh
echo
echo "=== Ingress ==="
kubectl get ingress opengist-ingress
echo
echo "=== PVC ==="
kubectl get pvc opengist-pvc
echo
echo "=== NodePort SSH ==="
kubectl get svc opengist-ssh -o jsonpath='{.spec.ports[0].nodePort}'
echo

12
apps/opengist/stop.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e
echo "🛑 Stopping OpenGist (PVC will be kept)..."
kubectl scale deployment opengist --replicas=0
echo "⏳ Waiting for pod termination..."
kubectl wait --for=delete pod -l app=opengist --timeout=60s || true
echo "✅ OpenGist stopped (data preserved)"