diff --git a/deployment/charts/templates/fuel-core-deploy.yaml b/deployment/charts/templates/fuel-core-deploy.yaml index c3922794807..61c80363d19 100644 --- a/deployment/charts/templates/fuel-core-deploy.yaml +++ b/deployment/charts/templates/fuel-core-deploy.yaml @@ -14,6 +14,7 @@ spec: port: http {{- end }} --- +{{- if .Values.app.volume.pvc_clone_enabled }} apiVersion: v1 kind: PersistentVolumeClaim metadata: @@ -28,6 +29,26 @@ spec: requests: storage: {{ .Values.app.volume.storagerequests }} storageClassName: {{ .Values.app.volume.storageclass }} + dataSource: + name: {{ .Values.app.volume.pvc_clone_snapshot_id }} + kind: VolumeSnapshot + apiGroup: snapshot.storage.k8s.io +{{ else }} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ .Values.app.volume.claimname }} + labels: + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + accessModes: + - {{ .Values.app.volume.accessmodes }} + resources: + requests: + storage: {{ .Values.app.volume.storagerequests }} + storageClassName: {{ .Values.app.volume.storageclass }} +{{- end }} --- apiVersion: v1 kind: ConfigMap diff --git a/deployment/charts/values.yaml b/deployment/charts/values.yaml index 063e9fcc114..f5073494628 100644 --- a/deployment/charts/values.yaml +++ b/deployment/charts/values.yaml @@ -45,6 +45,8 @@ app: pvname: ${fuel_core_pv_name} mountPath: /mnt/db/ claimname: ${fuel_core_pvc_name} + pvc_clone_enabled: ${fuel_core_pvc_clone_enabled} + pvc_clone_snapshot_id: ${fuel_core_pvc_snapshot_id} storageclass: ${pvc_storage_class} storagerequests: ${pvc_storage_requests} accessmodes: ReadWriteOnce @@ -55,4 +57,4 @@ app: memory_limits: ${fuel_core_memory_limits} prometheus: enabled: ${fuel_core_prometheus_enabled} - helm_release_name: ${fuel_core_prometheus_helm_release_name} \ No newline at end of file + helm_release_name: ${fuel_core_prometheus_helm_release_name} diff --git a/deployment/scripts/.env b/deployment/scripts/.env index b10bb0e8623..7eed159ca2a 100644 --- a/deployment/scripts/.env +++ b/deployment/scripts/.env @@ -18,6 +18,9 @@ fuel_core_min_gas_price=0 fuel_core_pv_name="db-pv" fuel_core_pvc_name="db-pv-claim" fuel_core_sentry_enabled=false +fuel_core_pvc_clone_enabled=false +fuel_core_pvc_snapshot_ref="snap-06fb1faafc1409cc5" +fuel_core_pvc_snapshot_id="imported-aws-snapshot" fuel_core_cpu_requests="1m" fuel_core_memory_requests="50Mi" diff --git a/deployment/scripts/fuel-core-deploy.sh b/deployment/scripts/fuel-core-deploy.sh index 2bacd180153..af1f45969df 100755 --- a/deployment/scripts/fuel-core-deploy.sh +++ b/deployment/scripts/fuel-core-deploy.sh @@ -8,9 +8,11 @@ set -o allexport && source .env && set +o allexport if [ "${k8s_provider}" == "eks" ]; then echo "Updating your kube context locally ...." aws eks update-kubeconfig --name ${TF_VAR_eks_cluster_name} + echo "Copying chainspec into deployment context ...." cp chainspec/${chain_spec_file} ../charts/chainspec.json export fuel_core_consensus_key_secret_base64_encoded=$(echo -n $fuel_core_consensus_key_secret | base64 -w 0) + cd ../secrets/ echo "Creating the fuel-core k8s secret ...." mv fuel-core-secret.yaml fuel-core-secret.template @@ -19,6 +21,22 @@ if [ "${k8s_provider}" == "eks" ]; then kubectl create ns ${k8s_namespace} || true kubectl delete -f fuel-core-secret.yaml || true kubectl apply -f fuel-core-secret.yaml + + if [ "${fuel_core_pvc_clone_enabled}" == "true" ]; then + cd ../volume_snapshots/ + kubectl apply -f VolumeSnapshotClass.yaml || true + mv VolumeSnapshotContent.yaml VolumeSnapshotContent.template + envsubst < VolumeSnapshotContent.template > VolumeSnapshotContent.yaml + rm VolumeSnapshotContent.template + kubectl apply -f VolumeSnapshotContent.yaml + mv VolumeSnapshot.yaml VolumeSnapshot.template + envsubst < VolumeSnapshot.template > VolumeSnapshot.yaml + rm VolumeSnapshot.template + kubectl apply -f VolumeSnapshot.yaml + else + echo "Volume Snapshots will not be created ...." + fi + cd ../charts mv Chart.yaml Chart.template envsubst < Chart.template > Chart.yaml @@ -26,6 +44,7 @@ if [ "${k8s_provider}" == "eks" ]; then mv values.yaml values.template envsubst < values.template > values.yaml rm values.template + echo "Deploying ${fuel_core_service_name} helm chart to ${TF_VAR_eks_cluster_name} ...." helm upgrade ${fuel_core_service_name} . \ --values values.yaml \ diff --git a/deployment/volume_snapshots/VolumeSnapshot.yaml b/deployment/volume_snapshots/VolumeSnapshot.yaml new file mode 100644 index 00000000000..7aab565c948 --- /dev/null +++ b/deployment/volume_snapshots/VolumeSnapshot.yaml @@ -0,0 +1,9 @@ +apiVersion: snapshot.storage.k8s.io/v1 +kind: VolumeSnapshot +metadata: + name: ${fuel_core_pvc_snapshot_id} + namespace: ${k8s_namespace} +spec: + volumeSnapshotClassName: ebs-csi-aws + source: + volumeSnapshotContentName: ${fuel_core_pvc_snapshot_id} diff --git a/deployment/volume_snapshots/VolumeSnapshotClass.yaml b/deployment/volume_snapshots/VolumeSnapshotClass.yaml new file mode 100644 index 00000000000..8973892d5eb --- /dev/null +++ b/deployment/volume_snapshots/VolumeSnapshotClass.yaml @@ -0,0 +1,6 @@ +apiVersion: snapshot.storage.k8s.io/v1 +kind: VolumeSnapshotClass +metadata: + name: ebs-csi-aws +driver: ebs.csi.aws.com +deletionPolicy: Delete diff --git a/deployment/volume_snapshots/VolumeSnapshotContent.yaml b/deployment/volume_snapshots/VolumeSnapshotContent.yaml new file mode 100644 index 00000000000..9619d438b52 --- /dev/null +++ b/deployment/volume_snapshots/VolumeSnapshotContent.yaml @@ -0,0 +1,14 @@ +apiVersion: snapshot.storage.k8s.io/v1 +kind: VolumeSnapshotContent +metadata: + name: ${fuel_core_pvc_snapshot_id} +spec: + volumeSnapshotRef: + kind: VolumeSnapshot + name: ${fuel_core_pvc_snapshot_id} + namespace: ${k8s_namespace} + source: + snapshotHandle: ${fuel_core_pvc_snapshot_ref} + driver: ebs.csi.aws.com + deletionPolicy: Delete + volumeSnapshotClassName: ebs-csi-aws