Skip to content

Instantly share code, notes, and snippets.

@f41gh7
Last active April 28, 2024 14:29
Show Gist options
  • Save f41gh7/98ad3323cbdd46476595b6a8b753cce9 to your computer and use it in GitHub Desktop.
Save f41gh7/98ad3323cbdd46476595b6a8b753cce9 to your computer and use it in GitHub Desktop.
vmbackup as kubernetes sidecar

Snippets show example how to use vmbackup as kubernetes sidecar

Build image with cron

# copy or download dockerfile
wget  https://gist.githubusercontent.com/f41gh7/98ad3323cbdd46476595b6a8b753cce9/raw/83df07d56bf36cdba019e6663ee77c1e1649a7a1/cron-vmbackup.Dockerfile

# edit args for your vmbackup config at docker file

# build image
docker build -t my-cron-vmbackup -f cron-vmbackup.Dockerfile .
# push to own docker repo image
docker push  my-cron-vmbackup

Use it as sidecar

add cron-backup container to your vmstorage or vmsingle kubernetes configuration. Example provided at vmstorage.yaml

FROM victoriametrics/vmbackup:v1.64.0 as backup
FROM amd64/alpine:3.14.0
COPY --from=backup /vmbackup-prod /bin/vmbackup
RUN apk add tini --no-cache && \
echo '* * * * * vmbackup --dst fs://tmp/backups --snapshot.createURL=http://localhost:8482/snapshot/create --snapshot.deleteURL=http://localhost:8482/snapshot/delete_all --storageDataPath=/victoria-metrics-data' > /etc/crontabs/root
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/usr/sbin/crond", "-f"]
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: vmstorage-example namespace: default
spec:
podManagementPolicy: Parallel
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app.kubernetes.io/instance: example
app.kubernetes.io/name: vmstorage
serviceName: vmstorage-example
template:
metadata:
labels:
app.kubernetes.io/instance: example
app.kubernetes.io/name: vmstorage
spec:
containers:
- args:
- -retentionPeriod=4
- -storageDataPath=/vm-data
image: victoriametrics/vmstorage:v1.64.0-cluster
name: vmstorage
ports:
- containerPort: 8482
name: http
protocol: TCP
- containerPort: 8400
name: vminsert
protocol: TCP
- containerPort: 8401
name: vmselect
protocol: TCP
volumeMounts:
- mountPath: /vm-data
name: vmstorage-db
- image: my-cron-vmbackup
name: cron-backup
volumeMounts:
- mountPath: /victoria-metrics-data
name: vmstorage-db
volumeClaimTemplates:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: vmstorage-db
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
volumeMode: Filesystem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment