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

[juno-node] feat: add chart to backup juno data and upload to cloudflare r2 #121

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ad8bf53
feat: add chart to backup juno data and upload to cloudflare r2
PhilexWong May 8, 2024
d788152
feat: add chart to backup juno data and upload to cloudflare r2 - add…
PhilexWong May 8, 2024
21ecd7c
feat: add chart to backup juno data and upload to cloudflare r2 - cha…
PhilexWong May 9, 2024
2546d2c
feat: add chart to backup juno data and upload to cloudflare r2 - aut…
PhilexWong May 9, 2024
fb69ab0
Fix: change dynamic name
PhilexWong May 15, 2024
0c633a2
Fix: enhance to replace pod with job.
PhilexWong May 27, 2024
40dd24f
Merge branch 'main' into feature/ANGKOR-X-202-v5
PhilexWong May 27, 2024
4508eee
Fix: remove tail space
PhilexWong May 27, 2024
41297ce
Fix: add space
PhilexWong May 27, 2024
fc6c459
Fix: add space to correct syntax error
PhilexWong May 27, 2024
e44e377
Fix: change rclone's secret from local file to secret managers
PhilexWong Jun 3, 2024
dfa8ba5
Fix: change schedule
PhilexWong Jun 3, 2024
da2dae9
Fix: add blank line and add externalsecret-common.yaml
PhilexWong Jun 3, 2024
6c1a19f
Fix: add relative path ofdataFromKey
PhilexWong Jun 3, 2024
7e86cd4
Fix: add relative path ofdataFromKey
PhilexWong Jun 3, 2024
9e58710
Fix: change DB size
PhilexWong Jun 14, 2024
785620c
Revert "Fix: change DB size"
PhilexWong Jun 14, 2024
109292f
Fix: change DB size -v
PhilexWong Jun 14, 2024
4669939
Fix: test purpose to exclude sst files
PhilexWong Jun 20, 2024
05f0946
Fix: test purpose to exclude sst files
PhilexWong Jun 20, 2024
b3cb753
Fix: test purpose to exclude sst files
PhilexWong Jun 20, 2024
80025c8
Update externalsecret-common.yaml
PhilexWong Jun 20, 2024
6c251b8
Update externalsecret-common.yaml
PhilexWong Jun 20, 2024
0845d6c
Update externalsecret-common.yaml
PhilexWong Jun 20, 2024
b2fb07d
Fix: test purpose to exclude sst files - revert
PhilexWong Jun 20, 2024
c56f72e
Fix: rename the jar file
PhilexWong Jul 9, 2024
8785e59
Fix: rename the jar file -exclude sst file for testing
PhilexWong Jul 9, 2024
652810b
feat: add retention function
PhilexWong Jul 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/juno-node/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: juno-chart
version: 0.1.4
version: 0.1.5
appVersion: "1"
description: A Helm chart for deploying Juno service
maintainers:
Expand Down
14 changes: 12 additions & 2 deletions charts/juno-node/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# juno-chart

![Version: 0.1.4](https://img.shields.io/badge/Version-0.1.4-informational?style=flat-square) ![AppVersion: 1](https://img.shields.io/badge/AppVersion-1-informational?style=flat-square)
![Version: 0.1.5](https://img.shields.io/badge/Version-0.1.5-informational?style=flat-square) ![AppVersion: 1](https://img.shields.io/badge/AppVersion-1-informational?style=flat-square)

A Helm chart for deploying Juno service

Expand All @@ -27,6 +27,15 @@ A Helm chart for deploying Juno service
| args.--ws | string | `"true"` | |
| args.--ws-host | string | `"0.0.0.0"` | |
| args.--ws-port | string | `"6061"` | |
| backupJunoDataJob.backupSchedule | string | `"*/20 * * * *"` | |
| backupJunoDataJob.cleanupSchedule | string | `"*/40 * * * *"` | |
| backupJunoDataJob.dataSource | string | `"juno-sepolia-pv-ssd-juno-sepolia-0"` | |
| backupJunoDataJob.enabled | bool | `true` | |
| backupJunoDataJob.endpoint | string | `"https://12345543.r2.cloudflarestorage.com"` | |
| backupJunoDataJob.key | string | `"key-1234"` | |
| backupJunoDataJob.network | string | `"sepolia"` | |
| backupJunoDataJob.secret | string | `"secret-12345"` | |
| backupJunoDataJob.storageSize | string | `"200Gi"` | |
| batchjob.enabled | bool | `false` | |
| batchjob.schedule | string | `"* */1 * * *"` | |
| deployment.healthCheck.enabled | bool | `false` | |
Expand Down Expand Up @@ -78,6 +87,7 @@ A Helm chart for deploying Juno service
| serviceAccount.enabled | bool | `false` | |
| serviceAccount.gcpServiceAccount | string | `"monitoring-sa-euw1@juno-prod-nth.iam.gserviceaccount.com"` | |
| serviceAccount.name | string | `"juno-pgo"` | |
| svc.externalTrafficPolicy | string | `""` | |
| svc.globalStaticInternalIpName | string | `""` | |
| svc.globalStaticIpName | string | `""` | |
| svc.ingress.enabled | bool | `true` | |
Expand Down Expand Up @@ -149,4 +159,4 @@ A Helm chart for deploying Juno service
| taintsToleration.tolerations.network | string | `"juno"` | |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0)
Autogenerated from chart metadata using [helm-docs v1.13.1](https://github.com/norwoodj/helm-docs/releases/v1.13.1)
215 changes: 215 additions & 0 deletions charts/juno-node/templates/juno-data-backup-cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
{{- if .Values.backupJunoDataJob.enabled -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.deployment.projectName }}-backup-junodata-sa
namespace: {{ .Values.deployment.namespace }}

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ .Values.deployment.projectName }}-backup-junodata-role
namespace: {{ .Values.deployment.namespace }}
rules:
- apiGroups: [""]
resources: ["pods", "persistentvolumeclaims"]
verbs: ["get", "list", "create", "update", "patch", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ .Values.deployment.projectName }}-backup-junodata-rolebinding
namespace: {{ .Values.deployment.namespace }}
subjects:
- kind: ServiceAccount
name: {{ .Values.deployment.projectName }}-backup-junodata-sa
namespace: {{ .Values.deployment.namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ .Values.deployment.projectName }}-backup-junodata-role
---
apiVersion: v1
kind: Secret
metadata:
name: rclone-config
PhilexWong marked this conversation as resolved.
Show resolved Hide resolved
namespace: {{ .Values.deployment.namespace }}
stringData:
rclone.conf: |
[R2]
type = s3
provider = Cloudflare
access_key_id = {{ .Values.backupJunoDataJob.key }}
secret_access_key = {{ .Values.backupJunoDataJob.secret }}
PhilexWong marked this conversation as resolved.
Show resolved Hide resolved
endpoint = {{ .Values.backupJunoDataJob.endpoint }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .Values.deployment.namespace }}-juno-data-backup-pvc
namespace: {{ .Values.deployment.namespace }}
spec:
accessModes:
- ReadWriteOnce
storageClassName: premium-rwo
resources:
requests:
storage: 200Gi
---

apiVersion: v1
kind: ConfigMap
metadata:
name: cloning-disk-manifest
PhilexWong marked this conversation as resolved.
Show resolved Hide resolved
namespace: {{ .Values.deployment.namespace }}
data:
cloning-disk-manifest.yaml: |
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ .Values.deployment.namespace }}-pv-ssd-snapshot
namespace: {{ .Values.deployment.namespace }}
spec:
dataSource:
name: {{ .Values.backupJunoDataJob.dataSource }}
kind: PersistentVolumeClaim
accessModes:
- ReadWriteOnce
storageClassName: premium-rwo
resources:
requests:
storage: {{ .Values.backupJunoDataJob.storageSize }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cloning-juno-manifest
PhilexWong marked this conversation as resolved.
Show resolved Hide resolved
namespace: {{ .Values.deployment.namespace }}
data:
cloning-juno-manifest.yaml: |
apiVersion: v1
kind: Pod
PhilexWong marked this conversation as resolved.
Show resolved Hide resolved
metadata:
name: juno-data-archival-pod-0
namespace: {{ .Values.deployment.namespace }}
spec:
serviceAccountName: {{ .Values.deployment.projectName }}-backup-junodata-sa
volumes:
- name: juno-data-volume
persistentVolumeClaim:
claimName: {{ .Values.deployment.namespace }}-pv-ssd-snapshot
- name: rclone-config
secret:
secretName: rclone-config
- name: tar-backup-volume
persistentVolumeClaim:
claimName: {{ .Values.deployment.namespace }}-juno-data-backup-pvc
initContainers:
PhilexWong marked this conversation as resolved.
Show resolved Hide resolved
- name: juno-archival-tar
image: ukemzyskywalker/archiver:v2
PhilexWong marked this conversation as resolved.
Show resolved Hide resolved
command: ["/bin/sh", "-c"]
args:
- |
rm -rf /mnt/juno-tar-backup/*.tar &&
rm -rf /mnt/data/*.tar &&
tar -czvf /mnt/juno-tar-backup/juno_{{ .Values.backupJunoDataJob.network }}_{{ .Values.deployment.imagetag }}_$(date +\%Y\%m\%d).tar --exclude=./lost+found -C /mnt/data . && sleep 10
volumeMounts:
- name: juno-data-volume
mountPath: /mnt/data
- name: tar-backup-volume
mountPath: /mnt/juno-tar-backup
containers:
- name: rclone-upload-container
image: rclone/rclone:latest
command: ["/bin/sh"]
args: ["-c", "rclone copy /mnt/juno-tar-backup/*.tar R2:/juno-snapshot/{{ .Values.backupJunoDataJob.network}}"]
volumeMounts:
- name: rclone-config
mountPath: /config/rclone
- name: tar-backup-volume
mountPath: /mnt/juno-tar-backup
restartPolicy: OnFailure
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ .Values.deployment.projectName }}-backup-junodata-cronjob
namespace: {{ .Values.deployment.namespace }}
spec:
schedule: "{{ .Values.backupJunoDataJob.backupSchedule}}"
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
jobTemplate:
spec:
completions: 1
ttlSecondsAfterFinished: 30
template:
spec:
serviceAccountName: {{ .Values.deployment.projectName }}-backup-junodata-sa
restartPolicy: Never
initContainers:
- name: copy-disk-kubectl-container
image: bitnami/kubectl:latest
command: ["/bin/sh"]
args: ["-c", "kubectl apply -f /cloning-disk-manifest/cloning-disk-manifest.yaml"]
volumeMounts:
- name: cloning-disk-manifest-volume
mountPath: /cloning-disk-manifest
containers:
- name: clone-juno-kubectl-container
image: bitnami/kubectl:latest
command: ["/bin/sh"]
args: ["-c", "kubectl apply -f /cloning-juno-manifest/cloning-juno-manifest.yaml"]
volumeMounts:
- name: cloning-juno-manifest-volume
mountPath: /cloning-juno-manifest
volumes:
- name: cloning-juno-manifest-volume
configMap:
name: cloning-juno-manifest
- name: cloning-disk-manifest-volume
configMap:
name: cloning-disk-manifest
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: delete-completed-pod-cronjob
namespace: {{ .Values.deployment.namespace }}
spec:
schedule: "{{ .Values.backupJunoDataJob.cleanupSchedule}}"
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
jobTemplate:
spec:
completions: 1
ttlSecondsAfterFinished: 30
template:
spec:
serviceAccountName: {{ .Values.deployment.projectName }}-backup-junodata-sa
restartPolicy: OnFailure
containers:
- name: kubectl-container
image: bitnami/kubectl:latest
command:
- "/bin/bash"
- "-c"
- |
kubectl delete pod --field-selector=status.phase==Succeeded
sleep 10
describe_output=$(kubectl describe pvc {{ .Values.deployment.namespace }}-pv-ssd-snapshot)
if echo "$describe_output" | grep -q "Used By:[[:space:]]*<none>"; then
echo "deleting {{ .Values.deployment.namespace }}-pv-ssd-snapshot....."
kubectl delete pvc {{ .Values.deployment.namespace }}-pv-ssd-snapshot
sleep 30
fi
describe_output=$(kubectl describe pvc {{ .Values.deployment.namespace }}-juno-data-backup-pvc)
if echo "$describe_output" | grep -q "Used By:[[:space:]]*<none>"; then
echo "deleting {{ .Values.deployment.namespace }}-juno-data-backup-pvc....."
kubectl delete pvc {{ .Values.deployment.namespace }}-juno-data-backup-pvc
sleep 30
fi
{{- end -}}
12 changes: 12 additions & 0 deletions charts/juno-node/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,15 @@ env:
data:
- name: NETWORK
value: "juno"

### Back up juno data and upload to R2 cloud
backupJunoDataJob:
enabled: true
dataSource: "juno-sepolia-pv-ssd-juno-sepolia-0"
backupSchedule: "*/20 * * * *"
cleanupSchedule: "*/40 * * * *"
network: "sepolia"
storageSize: 200Gi
key: key-1234
secret: secret-12345
endpoint: "https://12345543.r2.cloudflarestorage.com"
Loading