restic: Add restic-prune CronJob
This CronJob schedules a periodic run of `restic forget`, which deletes snapshots according to the specified retention period (14 daily, 4 weekly, 12 monthly). This task used to run on my workstation, scheduled by a systemd timer unit. I've kept the same schedule and retention period as before. Now, instead of relying on my PC to be on and awake, the cleanup will occur more regularly. There's also the added benefit of getting the logs into Loki.
This commit is contained in:
2
restic/.gitignore
vendored
Normal file
2
restic/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
credentials
|
||||
password
|
||||
50
restic/kustomization.yaml
Normal file
50
restic/kustomization.yaml
Normal file
@@ -0,0 +1,50 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
namespace: restic
|
||||
|
||||
labels:
|
||||
- pairs:
|
||||
app.kubernetes.io/instance: restic
|
||||
includeSelectors: true
|
||||
- pairs:
|
||||
app.kubernetes.io/part-of: restic
|
||||
includeTemplates: true
|
||||
|
||||
resources:
|
||||
- namespace.yaml
|
||||
- network-policy.yaml
|
||||
- restic-prune.yaml
|
||||
- secrets.yaml
|
||||
- ../dch-root-ca
|
||||
|
||||
configMapGenerator:
|
||||
- name: restic-env
|
||||
envs:
|
||||
- restic.env
|
||||
|
||||
patches:
|
||||
- patch: |-
|
||||
apiVersion: batch/v1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: restic-prune
|
||||
spec:
|
||||
jobTemplate:
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: restic-prune
|
||||
env:
|
||||
- name: RESTIC_CACERT
|
||||
value: /run/dch-ca/dch-root-ca.crt
|
||||
volumeMounts:
|
||||
- mountPath: /run/dch-ca
|
||||
name: dch-ca
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: dch-ca
|
||||
configMap:
|
||||
name: dch-root-ca
|
||||
|
||||
6
restic/namespace.yaml
Normal file
6
restic/namespace.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: restic
|
||||
labels:
|
||||
app.kubernetes.io/name: restic
|
||||
24
restic/network-policy.yaml
Normal file
24
restic/network-policy.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: restic
|
||||
labels:
|
||||
app.kubernetes.io/name: restic
|
||||
app.kubernetes.io/component: restic
|
||||
spec:
|
||||
egress:
|
||||
- to:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
kubernetes.io/metadata.name: kube-system
|
||||
ports:
|
||||
- port: 53
|
||||
protocol: UDP
|
||||
- port: 53
|
||||
protocol: TCP
|
||||
- to:
|
||||
- ipBlock:
|
||||
cidr: 172.30.0.15/32
|
||||
ports:
|
||||
- port: 443
|
||||
podSelector: {}
|
||||
60
restic/restic-prune.yaml
Normal file
60
restic/restic-prune.yaml
Normal file
@@ -0,0 +1,60 @@
|
||||
apiVersion: batch/v1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: restic-prune
|
||||
labels:
|
||||
app.kubernetes.io/name: restic-prune
|
||||
app.kubernetes.io/component: restic
|
||||
spec:
|
||||
schedule: 38 9 * * 5
|
||||
timeZone: America/Chicago
|
||||
concurrencyPolicy: Forbid
|
||||
jobTemplate:
|
||||
metadata:
|
||||
labels: &labels
|
||||
app.kubernetes.io/name: restic-prune
|
||||
app.kubernetes.io/component: restic
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
labels: *labels
|
||||
spec:
|
||||
restartPolicy: Never
|
||||
containers:
|
||||
- name: restic-prune
|
||||
image: ghcr.io/restic/restic
|
||||
args:
|
||||
- forget
|
||||
- --keep-daily=14
|
||||
- --keep-weekly=4
|
||||
- --keep-monthly=12
|
||||
env:
|
||||
- name: XDG_CACHE_HOME
|
||||
value: /var/cache
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: restic-env
|
||||
securityContext:
|
||||
readOnlyRootFilesystem: true
|
||||
volumeMounts:
|
||||
- mountPath: /run/secrets/restic
|
||||
name: secrets
|
||||
readOnly: true
|
||||
- mountPath: /var/cache
|
||||
name: cache
|
||||
- mountPath: /tmp
|
||||
name: tmp
|
||||
securityContext:
|
||||
runAsUser: 32142
|
||||
runAsGroup: 32142
|
||||
fsGroup: 32142
|
||||
runAsNonRoot: true
|
||||
volumes:
|
||||
- name: cache
|
||||
emptyDir: {}
|
||||
- name: secrets
|
||||
secret:
|
||||
secretName: restic-secrets
|
||||
- name: tmp
|
||||
emptyDir:
|
||||
medium: Memory
|
||||
4
restic/restic.env
Normal file
4
restic/restic.env
Normal file
@@ -0,0 +1,4 @@
|
||||
RESTIC_REPOSITORY=s3:s3.backups.pyrocufflink.blue/restic
|
||||
RESTIC_PASSWORD_FILE=/run/secrets/restic/password
|
||||
|
||||
AWS_SHARED_CREDENTIALS_FILE=/run/secrets/restic/credentials
|
||||
17
restic/secrets.yaml
Normal file
17
restic/secrets.yaml
Normal file
@@ -0,0 +1,17 @@
|
||||
apiVersion: bitnami.com/v1alpha1
|
||||
kind: SealedSecret
|
||||
metadata:
|
||||
name: restic-secrets
|
||||
namespace: restic
|
||||
labels: &labels
|
||||
app.kubernetes.io/name: restic
|
||||
app.kubernetes.io/component: restic
|
||||
spec:
|
||||
encryptedData:
|
||||
credentials: AgBegS5P+JvhbhBb7/gZ1h+eyvqbXbj5bL5nN/MUbSjmrc/eR93ipe+kAKsfe1DCOtrEKYxO52RY2RdQHcUtgowD9LChCWPVPNZSDJnOId4nVRh9dSqSdYe+fkbp2wqHZf67AjpsP6/Ga3/3RFgNoVXmSDUmn8+5ZwTCKeC304XaCXnPj3iudpO52Wr6x+GpVfZ+yuVBMKMFHIFnnMt0AmjXCqbz+LPIUP/BKZ0/15DYTj4SO3heoSYy5y8suIiF9RZW6ne5dQ3w28V7hq18TNjATahtz+csLzUCRAKYoJfuZ0+YShqn2B/ZFItS1HbsWpoM23UwrNgx5TjSpNzTsh1wqlOztRcS47vyWu9ztDuXjDm2lSJMqoLAjb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1sY6VdV8ELHZXHFZxruAuYJnRzoZ4EjR5/Mo9BT7JKZLpRUgnLdPQTe5VwL5E1FgjMr/b3nwSyenb63ulOzLcfcy/fpBgOk5AwgOOqjDKLUMJzLppYZT7K2wAI/81IqdclRxblGTa1smyFt7nrUUc86pSWy+/lEhZ+nFrkSF9GFmf3hQDIK/OmqVoV46uMadQGi+d
|
||||
template:
|
||||
metadata:
|
||||
name: restic-secrets
|
||||
namespace: restic
|
||||
labels: *labels
|
||||
Reference in New Issue
Block a user