From 898e83d551de3e0a31cfef8b43660d0698efb887 Mon Sep 17 00:00:00 2001 From: Shubh Maheshwari Date: Fri, 1 Nov 2024 01:17:40 -0700 Subject: [PATCH] Adding YAML files to run syncthing on Nautilus clusters --- k8s/first_login.yaml | 16 +++++++ k8s/persistent-storage.yaml | 11 +++++ k8s/run_muscle_activation.yaml | 63 ++++++++++++++++++++++++++++ k8s/sync-data.sh | 45 ++++++++++++++++++++ k8s/sync-data/syncthing-config.yaml | 21 ++++++++++ k8s/sync-data/syncthing-service.yaml | 12 ++++++ k8s/sync-data/syncthing-setup.yaml | 31 ++++++++++++++ 7 files changed, 199 insertions(+) create mode 100644 k8s/first_login.yaml create mode 100644 k8s/persistent-storage.yaml create mode 100644 k8s/run_muscle_activation.yaml create mode 100644 k8s/sync-data.sh create mode 100644 k8s/sync-data/syncthing-config.yaml create mode 100644 k8s/sync-data/syncthing-service.yaml create mode 100644 k8s/sync-data/syncthing-setup.yaml diff --git a/k8s/first_login.yaml b/k8s/first_login.yaml new file mode 100644 index 0000000..79d2ed9 --- /dev/null +++ b/k8s/first_login.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Pod +metadata: + name: test-pod +spec: + containers: + - name: mypod + image: ubuntu + resources: + limits: + memory: 100Mi + cpu: 100m + requests: + memory: 100Mi + cpu: 100m + command: ["sh", "-c", "echo 'Im a new pod' && sleep infinity"] diff --git a/k8s/persistent-storage.yaml b/k8s/persistent-storage.yaml new file mode 100644 index 0000000..53129d9 --- /dev/null +++ b/k8s/persistent-storage.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: sports-analytics-database +spec: + storageClassName: rook-cephfs-central + accessModes: + - ReadWriteMany + resources: + requests: + storage: 30Gi \ No newline at end of file diff --git a/k8s/run_muscle_activation.yaml b/k8s/run_muscle_activation.yaml new file mode 100644 index 0000000..509e335 --- /dev/null +++ b/k8s/run_muscle_activation.yaml @@ -0,0 +1,63 @@ +apiVersion: batch/v1 +kind: Job +metadata: + namespace: spatiotemporal-decision-making + name: syncthing-setup +spec: + template: + spec: + affinity: + nodeAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 1 + preference: + matchExpressions: + # - key: topology.kubernetes.io/region + # operator: In + # values: + # - us-west + - key: nautilus.io/group + operator: In + values: + - ry + + containers: + - name: shubh-container + image: gitlab-registry.nrp-nautilus.io/prp/jupyter-stack/minimal + command: + - /bin/bash + - -c + args: + - "echo 'Hello, World!'" + + resources: + limits: + memory: 20Gi + cpu: 8 + nvidia.com/gpu: "1" + requests: + memory: 15Gi + cpu: 4 + nvidia.com/gpu: "1" + + volumeMounts: + - mountPath: /dev/shm + name: dshm + - mountPath: /vol + name: sports-analytics-database + + tolerations: + - key: "nautilus.io/ry-reservation" + operator: "Equal" + value: "true" + effect: "NoSchedule" + restartPolicy: Never + + volumes: + - name: dshm + emptyDir: + medium: Memory + - name: sports-analytics-database + persistentVolumeClaim: + claimName: sports-analytics-database + backoffLimit: 0 diff --git a/k8s/sync-data.sh b/k8s/sync-data.sh new file mode 100644 index 0000000..476081c --- /dev/null +++ b/k8s/sync-data.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Usage instructions +# This script deploys Syncthing to a Kubernetes cluster to synchronize data between a local machine and a Kubernetes Pod. +# It requires the DEVICE_ID environment variable to be set to the Syncthing device ID of the local machine. +# +# Usage: +# export DEVICE_ID="your-device-id" +# ./sync-data.sh + +# Check if DEVICE_ID is set +if [ -z "$DEVICE_ID" ]; then + echo "Error: DEVICE_ID environment variable is not set. Used by Syncthing to identify the master machine." + echo "Set: export DEVICE_ID=\"your-device-id\"" + exit 1 +fi + +# Delete the existing Pod if it exists +kubectl delete pod data-transfer-pod --ignore-not-found + +# Apply the ConfigMap +kubectl apply -f sync-data/syncthing-config.yaml + +# Apply the Pod +kubectl apply -f sync-data/syncthing-setup.yaml + +# Wait for the Pod to be running +echo "Waiting for the Pod to be running..." +sleep 20 + +# Check Pod status +POD_STATUS=$(kubectl get pod data-transfer-pod -o jsonpath='{.status.phase}') +if [ "$POD_STATUS" != "Running" ]; then + echo "Error: Pod is not running. Current status=$POD_STATUS" + echo "Describing the Pod..." + kubectl describe pod data-transfer-pod + echo "Fetching Pod logs..." + kubectl logs data-transfer-pod + exit 1 +fi + +echo "Syncthing deployment complete." +echo "To access the Syncthing web GUI, run the following command:" +echo "kubectl port-forward pod/data-transfer-pod 32000:8384" +echo "Then open your browser and go to http://localhost:32000" \ No newline at end of file diff --git a/k8s/sync-data/syncthing-config.yaml b/k8s/sync-data/syncthing-config.yaml new file mode 100644 index 0000000..0fa94a0 --- /dev/null +++ b/k8s/sync-data/syncthing-config.yaml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: syncthing-config +data: + config.xml: | + + + basic + + + +
dynamic
+ false + false + 0 + 0 + 0 + false +
+
\ No newline at end of file diff --git a/k8s/sync-data/syncthing-service.yaml b/k8s/sync-data/syncthing-service.yaml new file mode 100644 index 0000000..18ea0cf --- /dev/null +++ b/k8s/sync-data/syncthing-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: syncthing-service # Exposes the Syncthing web GUI port. +spec: + selector: + app: syncthing + ports: + - protocol: TCP + port: 8384 + targetPort: 8384 + type: NodePort \ No newline at end of file diff --git a/k8s/sync-data/syncthing-setup.yaml b/k8s/sync-data/syncthing-setup.yaml new file mode 100644 index 0000000..33950cb --- /dev/null +++ b/k8s/sync-data/syncthing-setup.yaml @@ -0,0 +1,31 @@ +apiVersion: v1 +kind: Pod +metadata: + name: data-transfer-pod + labels: + app: syncthing +spec: + containers: + - name: syncthing + image: syncthing/syncthing:latest + ports: + - containerPort: 8384 # Syncthing web GUI port + - containerPort: 22000 # Syncthing sync port + - containerPort: 21027 # Syncthing discovery port + env: + - name: DEVICE_ID + value: "${DEVICE_ID}" + volumeMounts: + - mountPath: /mnt/data + name: sports-analytics-database + - mountPath: /var/syncthing/config + name: syncthing-config + command: ["/bin/sh"] + args: ["-c", "mkdir -p /mnt/data/MCS_DATA && /bin/syncthing -home=/var/syncthing/config"] + volumes: + - name: sports-analytics-database + persistentVolumeClaim: + claimName: sports-analytics-database + - name: syncthing-config + emptyDir: {} + restartPolicy: Never \ No newline at end of file