Skip to content

Commit

Permalink
Merge pull request #13 from shubhMaheshwari/main
Browse files Browse the repository at this point in the history
Adding YAML files to run syncthing on Nautilus clusters
  • Loading branch information
shubhMaheshwari authored Nov 1, 2024
2 parents c6ff8a3 + 898e83d commit 8a8a1a8
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 0 deletions.
16 changes: 16 additions & 0 deletions k8s/first_login.yaml
Original file line number Diff line number Diff line change
@@ -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"]
11 changes: 11 additions & 0 deletions k8s/persistent-storage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: sports-analytics-database
spec:
storageClassName: rook-cephfs-central
accessModes:
- ReadWriteMany
resources:
requests:
storage: 30Gi
63 changes: 63 additions & 0 deletions k8s/run_muscle_activation.yaml
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions k8s/sync-data.sh
Original file line number Diff line number Diff line change
@@ -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"
21 changes: 21 additions & 0 deletions k8s/sync-data/syncthing-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: syncthing-config
data:
config.xml: |
<configuration version="30">
<folder id="MCS_DATA" label="MCS_DATA" path="/mnt/data/MCS_DATA" type="readwrite">
<filesystemType>basic</filesystemType>
<device id="${DEVICE_ID}"/>
</folder>
<device id="${DEVICE_ID}" name="KubernetesPod" compression="metadata" introducer="false" skipIntroductionRemovals="false">
<address>dynamic</address>
<paused>false</paused>
<autoAcceptFolders>false</autoAcceptFolders>
<maxSendKbps>0</maxSendKbps>
<maxRecvKbps>0</maxRecvKbps>
<maxRequestKiB>0</maxRequestKiB>
<untrusted>false</untrusted>
</device>
</configuration>
12 changes: 12 additions & 0 deletions k8s/sync-data/syncthing-service.yaml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions k8s/sync-data/syncthing-setup.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8a8a1a8

Please sign in to comment.