K8s + PostgreSQL + Longhorn
Environment Check Script
curl -sSfL https://raw.githubusercontent.com/longhorn/longhorn/v1.6.1/scripts/environment_check.sh | bash
Installing open-iscsi
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v1.6.1/deploy/prerequisite/longhorn-iscsi-installation.yaml
Installing NFSv4 client
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v1.6.1/deploy/prerequisite/longhorn-nfs-installation.yaml
Installing Longhorn
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v1.6.1/deploy/longhorn.yaml
git clone https://github.com/jerryshell/k8s-postgres-longhorn.git
cd k8s-postgres-longhorn
export POSTGRES_DB=postgres
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=your_password
cat k8s/configmap/configmap.yaml | envsubst | kubectl apply -f -
kubectl apply -f k8s/
kubectl delete --ignore-not-found=true -f k8s/ -f k8s/configmap/
kubectl exec -it postgres-UUID -- psql -h localhost -U postgres --password -p 5432 postgres
Backup
kubectl exec -it postgres-UUID -- pg_dump -U postgres -d postgres > db_backup.sql
Restore
kubectl cp db_backup.sql postgres-UUID:/tmp/db_backup.sql
kubectl exec -it postgres-UUID -- /bin/bash
psql -U postgres -d postgres -f /tmp/db_backup.sql