-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2472 from GiganticMinecraft/add-proxmox-backup-so…
…lution デバッグサーバにproxmox-backup-clientを使用した定期バックアップの仕組みを構築する
- Loading branch information
Showing
6 changed files
with
238 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
...ichi-kubernetes/apps/seichi-debug-minecraft/mcserver--debug-s1/argo-workflows-backup.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: CronWorkflow | ||
metadata: | ||
name: argo-workflows-backup | ||
namespace: seichi-debug-minecraft | ||
spec: | ||
schedule: "0 4 * * *" | ||
timezone: Asia/Tokyo | ||
concurrencyPolicy: "Forbid" | ||
workflowSpec: | ||
ttlStrategy: | ||
secondsAfterCompletion: 86400 | ||
serviceAccountName: mcserver--debug-s1-workflow-sa | ||
entrypoint: stop-backup-and-boot | ||
templates: | ||
- name: stop-backup-and-boot | ||
steps: | ||
- - name: patch-statefulset-to-0 | ||
template: patch-statefulset-to-0 | ||
- - name: wait-for-scale-to-0 | ||
template: wait-for-scale-to-0 | ||
- - name: run-backup | ||
template: run-backup | ||
- - name: patch-statefulset-to-1 | ||
template: patch-statefulset-to-1 | ||
- - name: wait-for-scale-to-1 | ||
template: wait-for-scale-to-1 | ||
|
||
- name: patch-statefulset-to-0 | ||
script: | ||
image: bitnami/kubectl:1.32.1 | ||
command: ["/bin/sh", "-c"] | ||
source: | | ||
kubectl patch statefulset mcserver--debug-s1 -n seichi-debug-minecraft --type='merge' -p '{"spec": {"replicas": 0}}' | ||
- name: wait-for-scale-to-0 | ||
script: | ||
image: bitnami/kubectl:1.32.1 | ||
command: ["/bin/sh", "-c"] | ||
source: | | ||
echo "Waiting for StatefulSet to scale down..." | ||
while [ "$(kubectl get statefulset mcserver--debug-s1 -n seichi-debug-minecraft -o jsonpath='{.status.availableReplicas}')" != "0" ]; do | ||
echo "Still scaling down..." | ||
sleep 5 | ||
done | ||
echo "Scale-down confirmed!" | ||
- name: run-backup | ||
script: | ||
image: debian:12 | ||
command: ["/bin/sh", "-c"] | ||
source: | | ||
set -e | ||
echo "Updating package lists..." | ||
apt update | ||
echo "Installing curl..." | ||
apt install -y curl | ||
echo "Adding Proxmox Backup Client repository..." | ||
echo "deb http://download.proxmox.com/debian/pbs-client bookworm main" > /etc/apt/sources.list.d/pbs-client.list | ||
curl -fsSL https://enterprise.proxmox.com/debian/proxmox-release-bookworm.gpg -o /etc/apt/trusted.gpg.d/proxmox-release-bookworm.gpg | ||
echo "Updating package lists..." | ||
apt update | ||
echo "Installing proxmox-backup-client version 3.3.2-1..." | ||
apt install -y proxmox-backup-client=3.3.2-1 | ||
echo "Running backup..." | ||
proxmox-backup-client backup "${BACKUP_NAME}" \ | ||
--repository "${PBS_USER}@${PBS_HOST}:${PBS_DATASTORE}" \ | ||
--backup-id "${BACKUP_ID}" | ||
env: | ||
- name: BACKUP_NAME | ||
value: "data.pxar:/data" | ||
# proxmox-backup-server側でどのサーバのバックアップかを識別するためにサーバごとに異なるbackup-idを指定する | ||
- name: BACKUP_ID | ||
value: "mcserver--debug-s1" | ||
- name: PBS_USER | ||
valueFrom: | ||
secretKeyRef: | ||
name: pbs-credentials | ||
key: user | ||
- name: PBS_HOST | ||
valueFrom: | ||
secretKeyRef: | ||
name: pbs-credentials | ||
key: host | ||
- name: PBS_DATASTORE | ||
valueFrom: | ||
secretKeyRef: | ||
name: pbs-credentials | ||
key: datastore | ||
- name: PBS_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: pbs-credentials | ||
key: password | ||
- name: PBS_FINGERPRINT | ||
valueFrom: | ||
secretKeyRef: | ||
name: pbs-credentials | ||
key: fingerprint | ||
volumeMounts: | ||
- name: backup-target-volume | ||
mountPath: /data | ||
|
||
# FIXME ここにMariaDBのメンテ完了を待つ処理を入れる必要がある | ||
|
||
- name: patch-statefulset-to-1 | ||
script: | ||
image: bitnami/kubectl:1.32.1 | ||
command: ["/bin/sh", "-c"] | ||
source: | | ||
kubectl patch statefulset mcserver--debug-s1 -n seichi-debug-minecraft --type='merge' -p '{"spec": {"replicas": 1}}' | ||
- name: wait-for-scale-to-1 | ||
activeDeadlineSeconds: 300 # 5分待っても上がってこない場合は諦める | ||
script: | ||
image: bitnami/kubectl:1.32.1 | ||
command: ["/bin/sh", "-c"] | ||
source: | | ||
echo "Waiting for StatefulSet to scale up..." | ||
while [ "$(kubectl get statefulset mcserver--debug-s1 -n seichi-debug-minecraft -o jsonpath='{.status.availableReplicas}')" != "1" ]; do | ||
echo "Still scaling up..." | ||
sleep 5 | ||
done | ||
echo "Scale-up confirmed!" | ||
volumes: | ||
- name: backup-target-volume | ||
persistentVolumeClaim: | ||
claimName: minecraft-server-data-mcserver--debug-s1-0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...nifests/seichi-kubernetes/apps/seichi-debug-minecraft/mcserver--debug-s1/workflow-sa.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: mcserver--debug-s1-workflow-sa | ||
namespace: seichi-debug-minecraft | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: mcserver--debug-s1-workflow-role | ||
namespace: seichi-debug-minecraft | ||
rules: | ||
- apiGroups: ["apps"] | ||
resources: ["statefulsets"] | ||
verbs: ["get", "patch"] | ||
- apiGroups: [""] | ||
resources: ["pods"] | ||
verbs: ["get"] | ||
- apiGroups: ["argoproj.io"] | ||
resources: ["workflowtaskresults"] | ||
verbs: ["create", "patch"] | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: mcserver--debug-s1-workflow-binding | ||
namespace: seichi-debug-minecraft | ||
subjects: | ||
- kind: ServiceAccount | ||
name: mcserver--debug-s1-workflow-sa | ||
namespace: seichi-debug-minecraft | ||
roleRef: | ||
kind: Role | ||
name: mcserver--debug-s1-workflow-role | ||
apiGroup: rbac.authorization.k8s.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters