Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mc-backup Sidecar #93

Merged
merged 30 commits into from Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
41004f5
Squashed commit of the following:
merkinbob Jan 9, 2022
1385ed9
update version
merkinbob Jan 9, 2022
466bed7
clean up
merkinbob Jan 9, 2022
eb8f01e
test
merkinbob Jan 9, 2022
4f83778
fix if gate
merkinbob Jan 9, 2022
f773408
finish envs
merkinbob Jan 9, 2022
3161a33
try this
merkinbob Jan 9, 2022
ef757ea
still messin with or in charts
merkinbob Jan 9, 2022
7ac74b2
i think this is the one
merkinbob Jan 9, 2022
71bb2cf
fix backup name
merkinbob Jan 9, 2022
b380bf9
add mounts and volumes
merkinbob Jan 9, 2022
f851ac9
fix oopsy
merkinbob Jan 9, 2022
1c1901b
fix save
merkinbob Jan 9, 2022
f0f7db6
update
merkinbob Jan 9, 2022
a5a25eb
fix pvc case
merkinbob Jan 9, 2022
3a6241d
this the issue?
merkinbob Jan 9, 2022
0ff9072
quote all the things
merkinbob Jan 9, 2022
241bfce
discard diff
merkinbob Jan 9, 2022
fedf229
fix mounts
merkinbob Jan 9, 2022
bd531e1
add missing backup method env, so someone can test restic
merkinbob Jan 10, 2022
f9e4c25
clean up rclone settings, white space?
merkinbob Jan 11, 2022
43fbb1a
fix whitespace
merkinbob Jan 11, 2022
35834d2
attempt to finish out rclone
merkinbob Jan 11, 2022
56edfe9
add a bit of doc help
merkinbob Jan 11, 2022
d6398e5
fix rclone install issues
merkinbob Jan 11, 2022
fe7a923
fix spacing
merkinbob Jan 11, 2022
e296e5e
YAMLZ!
merkinbob Jan 11, 2022
8cf7c97
fix values.yaml file to be more clear (some values are implied from o…
merkinbob Jan 11, 2022
32cd1aa
add missing restic envs
merkinbob Jan 11, 2022
0573b74
linter fixes
merkinbob Jan 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Expand Up @@ -43,3 +43,4 @@ jobs:
charts_repo_url: https://itzg.github.io/minecraft-server-charts
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

2 changes: 1 addition & 1 deletion charts/minecraft/Chart.yaml
@@ -1,6 +1,6 @@
apiVersion: v1
name: minecraft
version: 3.6.2
version: 3.6.3
appVersion: SeeValues
home: https://minecraft.net/
description: Minecraft server
Expand Down
33 changes: 33 additions & 0 deletions charts/minecraft/templates/backupdir-pvc.yaml
@@ -0,0 +1,33 @@
{{- if and .Values.mcbackup.persistence.backupDir.enabled (not .Values.mcbackup.persistence.backupDir.existingClaim ) -}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ template "minecraft.fullname" . }}-backupdir
labels:
app: {{ template "minecraft.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
annotations:
{{- with .Values.mcbackup.persistence.annotations }}
{{ toYaml . | nindent 4 }}
{{- end }}
{{- if .Values.mcbackup.persistence.storageClass }}
volume.beta.kubernetes.io/storage-class: {{ .Values.mcbackup.persistence.storageClass | quote }}
{{- else }}
volume.alpha.kubernetes.io/storage-class: default
{{- end }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.mcbackup.persistence.backupDir.Size | quote }}
{{- if .Values.mcbackup.persistence.storageClass }}
{{- if (eq "-" .Values.mcbackup.persistence.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.mcbackup.persistence.storageClass }}"
{{- end }}
{{- end }}
{{- end -}}
104 changes: 104 additions & 0 deletions charts/minecraft/templates/deployment.yaml
Expand Up @@ -43,6 +43,88 @@ spec:
{{- toYaml .Values.initContainers | nindent 8 }}
{{- end }}
containers:
{{- if and .Values.mcbackup.enabled .Values.minecraftServer.rcon.enabled }}
- name: {{ template "minecraft.fullname" . }}-mc-backup
image: "{{ .Values.mcbackup.image }}:{{ .Values.mcbackup.imageTag }}"
imagePullPolicy: Always
resources:
{{ toYaml .Values.mcbackup.resources | indent 10 }}
env:
- name: SRC_DIR
value: "/data"
- name: BACKUP_NAME
value: {{ default "world" .Values.minecraftServer.worldSaveName | quote }}
- name: INITIAL_DELAY
value: {{ default "2m" .Values.mcbackup.initialDelay | quote }}
- name: BACKUP_INTERVAL
value: {{ default "24h" .Values.mcbackup.backupInterval | quote }}
- name: PAUSE_IF_NO_PLAYERS
value: {{ default "false" .Values.mcbackup.pauseIfNoPlayers | quote }}
- name: SERVER_PORT
value: "25565"
- name: RCON_HOST
value: "localhost"
- name: RCON_PORT
value: {{ .Values.minecraftServer.rcon.port | quote }}
- name: RCON_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.minecraftServer.rcon.existingSecret | default (include "minecraft.fullname" .) }}
key: {{ .Values.minecraftServer.rcon.secretKey | default "rcon-password" }}
- name: RCON_RETRIES
value: {{ default 5 .Values.mcbackup.rconRetries | quote }}
- name: RCON_RETRY_INTERVAL
value: {{ default "10s" .Values.mcbackup.rconRetryInterval | quote }}
- name: EXCLUDES
value: {{ default "*.jar,cache,logs" .Values.mcbackup.excludes | quote }}
- name: BACKUP_METHOD
value: {{ default "tar" .Values.mcbackup.backupMethod | quote }}
{{- if or (eq .Values.mcbackup.backupMethod "tar") (eq .Values.mcbackup.backupMethod "rclone") }}
- name: DEST_DIR
value: {{ default "/backups" .Values.mcbackup.destDir | quote }}
- name: LINK_LATEST
value: {{ default "false" .Values.mcbackup.linkLatest | quote }}
- name: TAR_COMPRESS_METHOD
value: {{ default "gzip" .Values.mcbackup.compressMethod | quote }}
- name: ZSTD_PARAMETERS
value: {{ default "-3 --long=25 --single-thread" .Values.mcbackup.zstdParameters | quote }}
{{- if eq .Values.mcbackup.backupMethod "rclone" }}
- name: RCLONE_REMOTE
value: {{ .Values.mcbackup.rcloneRemote | quote }}
- name: RCLONE_COMPRESS_METHOD
value: {{ default "gzip" .Values.mcbackup.rcloneCompressMethod | quote }}
{{- end }}
{{- end }}
{{- if eq .Values.mcbackup.backupMethod "restic" }}
- name: RESTIC_REPOSITORY
value: {{ .Values.mcbackup.resticRepository | quote }}
- name: RESTIC_ADDITIONAL_TAGS
value: {{ default "mc_backups" .Values.mcbackup.resticAdditionalTags | quote }}
- name: PRUNE_RESTIC_RETENTION
value: {{ default "--keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly" .Values.mcbackup.pruneResticRetention | quote }}
{{- range $key, $value := .Values.mcbackup.resticEnvs }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- end }}
{{- range $key, $value := .Values.mcbackup.extraEnv }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
volumeMounts:
- name: datadir
mountPath: /data
readOnly: true
- name: backupdir
mountPath: {{ default "/backups" .Values.mcbackup.destDir }}
{{- if eq .Values.mcbackup.backupMethod "rclone" }}
- name: rclone-config
mountPath: /config/rclone
{{- end }}
{{- range .Values.extraVolumes }}
{{- toYaml .volumeMounts | nindent 8 }}
{{- end }}
{{- end }}
- name: {{ template "minecraft.fullname" . }}
image: "{{ .Values.image }}:{{ .Values.imageTag }}"
imagePullPolicy: Always
Expand Down Expand Up @@ -241,6 +323,9 @@ spec:
volumeMounts:
- name: datadir
mountPath: /data
- name: backupdir
mountPath: {{ default "/backups" .Values.mcbackup.destDir }}
readOnly: true
{{- range .Values.extraVolumes }}
{{- toYaml .volumeMounts | nindent 8 }}
{{- end }}
Expand All @@ -256,6 +341,25 @@ spec:
{{- else }}
emptyDir: {}
{{- end }}
- name: backupdir
{{- if and .Values.mcbackup.persistence.backupDir.enabled .Values.mcbackup.enabled }}
persistentVolumeClaim:
{{- if .Values.mcbackup.persistence.backupDir.existingClaim }}
claimName: {{ .Values.mcbackup.persistence.backupDir.existingClaim }}
{{- else }}
claimName: {{ template "minecraft.fullname" . }}-backupdir
{{- end }}
{{- else }}
emptyDir: {}
{{- end }}
{{- if eq .Values.mcbackup.backupMethod "rclone" }}
- name: rclone-config
configMap:
name: {{ template "minecraft.fullname" . }}-rclone-config
items:
- key: rclone.conf
path: rclone.conf
{{- end }}
{{- range .Values.extraVolumes }}
{{- toYaml .volumes | nindent 6 }}
{{- end }}
Expand Down
18 changes: 18 additions & 0 deletions charts/minecraft/templates/rclone-config-map.yaml
@@ -0,0 +1,18 @@
{{- if and .Values.mcbackup.enabled .Values.minecraftServer.rcon.enabled }}
{{- if eq .Values.mcbackup.backupMethod "rclone" }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "minecraft.fullname" . }}-rclone-config
labels:
app: {{ template "minecraft.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
data:
rclone.conf: |-
{{- if .Values.mcbackup.rcloneConfig }}
{{ tpl .Values.mcbackup.rcloneConfig . | indent 4 }}
{{- end }}
{{- end }}
{{- end }}
83 changes: 83 additions & 0 deletions charts/minecraft/values.yaml
Expand Up @@ -265,3 +265,86 @@ deploymentAnnotations: {}
serviceAnnotations: {}

rconServiceAnnotations: {}

# PLEASE NOTE! rcon must be enabled above! It does NOT require a nodePort or loadBalancerIP
mcbackup:
enabled: false

image: itzg/mc-backup
imageTag: latest

# wait 2 minutes before starting
initialDelay: 2m

# ***set to 0 or smaller, script will run once and exit. DO NOT SET TO 0 or smaller, this will cause K8s to kill your pod!***
# backupInterval="1.5d" -> backup every one and a half days (36 hours)
# backupInterval="2h 30m" -> backup every two and a half hours
backupInterval: 24h

# option lets you pause backups if no players are online.
pauseIfNoPlayers: "false"

# is set to a positive number, it'll delete old .tgz backup files from DEST_DIR. By default deletes backups older than a week.
pruneBackupsDays: 7

# Set to a negative value to retry indefinitely
rconRetries: 5
rconRetryInterval: 10s

# is a comma-separated list of glob(3) patterns to exclude from backups. By default excludes all jar files (plugins, server files),
# logs folder and cache (used by i.e. PaperMC server).
excludes: "*.jar,cache,logs"

# backup methods, see https://github.com/itzg/docker-mc-backup e.g. tar, rclone, restic
backupMethod: tar
# tar and rclone methods
destDir: /backups
# is a true/false flag that creates a symbolic link to the latest backup
linkLatest: "false"
# is the compression method used by tar. Valid value: gzip bzip2 zstd
compressMethod: "gzip"
# sets the parameters for zstd compression. The --long parameter affects RAM requirements for both compression and decompression
# (the default of 25 means 2^25 bytes = 32 MB).
zstdParameters: "-3 --long=25 --single-thread"
# the name of the remote you've configured in your rclone.conf
rcloneRemote:
rcloneCompressMethod: gzip

# see https://rclone.org/ for details
# this value is evaluated as a template
rcloneConfig:

resticRepository:
# variable to define a space separated list of additional restic tags. see https://hub.docker.com/r/itzg/mc-backup
resticAdditionalTags: "mc_backups"
# see https://restic.readthedocs.io/en/latest/060_forget.html
pruneResticRetention: "--keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 75"

# At least one of RESTIC_PASSWORD* env variables need to be defined, see https://restic.readthedocs.io/en/latest/030_preparing_a_new_repo.html
resticEnvs: []
# RESTIC_PASSWORD: restic-password

extraEnvs: []
# Can be set to the timezone to use for logging
# tz:

resources:
requests:
memory: 512Mi
cpu: 500m

persistence:
annotations: {}
## minecraft data Persistent Volume Storage Class
## If defined, storageClassName: <storageClass>
## If set to "-", storageClassName: "", which disables dynamic provisioning
## If undefined (the default) or set to null, no storageClassName spec is
## set, choosing the default provisioner. (gp2 on AWS, standard on
## GKE, AWS & OpenStack)
##
# storageClass: "-"
backupDir:
# Set this to false if you don't care to persist state between restarts.
enabled: false
# existingClaim: nil
Size: 1Gi