Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Added some docs to run on Kubernetes

Chris Cowley98c445690b40
diff --git a/docs/SELF_HOSTING_KUBERNETES.md b/docs/SELF_HOSTING_KUBERNETES.md
new file mode 100644
index 000000000..45a8c83f0
--- /dev/null
+++ b/docs/SELF_HOSTING_KUBERNETES.md
@@ -0,0 +1,25 @@
+# Self-hosting openGym on Kubernetes
+
+
+openGym is pretty simple - a frontend and an API backend. The API keeps everything in a plain JSON file on a volume. The Docker Compose file also has a third container that syncs a bunch of media files. I only have a few resources to create:
+
+- 2 PVCs: data and media
+- 1 deployment for the API and web interface: I decided to keep them in a single pod for simplicity.
+- An HTTPRoute or an Ingress - you really should be using an HTTPRoute nowadays.
+
+There are example manifests available:
+
+```bash
+git clone https://github.com/DuarteSantos8/openGym # or https://gitlab.com/DuarteSantos8/opengym — same repo
+cd openGym
+# edit the soec.template.env.containers["api"].env with at least your URL
+kubectl apply -k kubernetes/
+```
+```
+
+
+You will also need an API Gateway, that is configured to work with TLS. It has been tested with [Envoy Gateway](https://gateway.envoyproxy.io) and [Cert-Manager](https://cert-manager.io).
+
+One slight difference compared to the [Docker Compose example](./SELFHOSTING.md) is that the "media" container runs as an initContainer.
+
+
diff --git a/kubernetes/deployment.yaml b/kubernetes/deployment.yaml
new file mode 100644
index 000000000..39d44cce4
--- /dev/null
+++ b/kubernetes/deployment.yaml
@@ -0,0 +1,113 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ labels:
+ app: opengym
+ name: opengym
+spec:
+ replicas: 1
+ strategy:
+ type: Recreate
+ selector:
+ matchLabels:
+ app: opengym
+ template:
+ metadata:
+ labels:
+ app: opengym
+ spec:
+ initContainers:
+ - name: media-download
+ image: alpine/git
+ command: ["/bin/sh", "-c"]
+ args:
+ - |
+ mkdir -p /out/img /out/gif
+ if [ -z "$(ls -A /out/img 2>/dev/null)" ]; then
+ git clone --depth 1 https://github.com/hasaneyldrm/exercises-dataset /tmp/ds
+ cp /tmp/ds/images/*.jpg /out/img/ && cp /tmp/ds/videos/*.gif /out/gif/
+ fi
+ volumeMounts:
+ - name: opengym-media
+ mountPath: /out
+ resources:
+ requests:
+ memory: 128Mi
+ limits:
+ memory: 256Mi
+ containers:
+ - name: api
+ image: ghcr.io/duartesantos8/opengym-api:latest
+ imagePullPolicy: Always
+ env:
+ - name: PORT
+ value: "3000"
+ - name: DATA_DIR
+ value: /data
+ - name: RP_ID
+ value: opengym.example.com
+ - name: ORIGIN
+ value: https://opengym.example.com
+ ports:
+ - containerPort: 3000
+ name: http
+ protocol: TCP
+ readinessProbe:
+ httpGet:
+ path: /api/health
+ port: 3000
+ livenessProbe:
+ httpGet:
+ path: /api/health
+ port: 3000
+ initialDelaySeconds: 30
+ volumeMounts:
+ - name: opengym-data
+ mountPath: /data
+ resources:
+ requests:
+ memory: 128Mi
+ limits:
+ memory: 512Mi
+ - name: web
+ image: ghcr.io/duartesantos8/opengym-web:latest
+ imagePullPolicy: Always
+ env:
+ - name: NGINX_PORT
+ value: "80"
+ - name: BACKEND
+ value: 127.0.0.1
+ - name: PORT
+ value: "3000"
+ ports:
+ - containerPort: 80
+ name: web
+ protocol: TCP
+ readinessProbe:
+ httpGet:
+ path: /
+ port: 80
+ livenessProbe:
+ httpGet:
+ path: /
+ port: 80
+ initialDelaySeconds: 30
+ volumeMounts:
+ - name: opengym-media
+ mountPath: /usr/share/nginx/html/img
+ subPath: img
+ - name: opengym-media
+ mountPath: /usr/share/nginx/html/gif
+ subPath: gif
+ resources:
+ requests:
+ memory: 32Mi
+ limits:
+ memory: 128Mi
+ volumes:
+ - name: opengym-data
+ persistentVolumeClaim:
+ claimName: opengym-data
+ - name: opengym-media
+ persistentVolumeClaim:
+ claimName: opengym-media
diff --git a/kubernetes/httproute.yaml b/kubernetes/httproute.yaml
new file mode 100644
index 000000000..ca7ae0500
--- /dev/null
+++ b/kubernetes/httproute.yaml
@@ -0,0 +1,46 @@
+---
+apiVersion: cert-manager.io/v1
+kind: Certificate
+metadata:
+ name: opengym-tls
+ namespace: fitness
+spec:
+ dnsNames:
+ - opengym.example.com
+ issuerRef:
+ kind: ClusterIssuer
+ name: letsencrypt
+ secretName: opengym-tls
+---
+apiVersion: gateway.networking.k8s.io/v1beta1
+kind: ReferenceGrant
+metadata:
+ name: allow-gateway
+spec:
+ from:
+ - group: gateway.networking.k8s.io
+ kind: Gateway
+ namespace: envoy-gateway-system
+ to:
+ - group: ""
+ kind: Service
+---
+apiVersion: gateway.networking.k8s.io/v1
+kind: HTTPRoute
+metadata:
+ name: opengym
+spec:
+ parentRefs:
+ - name: eg
+ namespace: envoy-gateway-system
+ sectionName: https
+ hostnames:
+ - opengym.example.com
+ rules:
+ - matches:
+ - path:
+ type: PathPrefix
+ value: /
+ backendRefs:
+ - name: opengym
+ port: 80
diff --git a/kubernetes/kustomization.yaml b/kubernetes/kustomization.yaml
new file mode 100644
index 000000000..112d20caa
--- /dev/null
+++ b/kubernetes/kustomization.yaml
@@ -0,0 +1,9 @@
+---
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+namespace: fitness
+resources:
+ - pvc.yaml
+ - deployment.yaml
+ - service.yaml
+ - httproute.yaml
\ No newline at end of file
diff --git a/kubernetes/pvc.yaml b/kubernetes/pvc.yaml
new file mode 100644
index 000000000..263fe8d34
--- /dev/null
+++ b/kubernetes/pvc.yaml
@@ -0,0 +1,22 @@
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+ name: opengym-data
+spec:
+ accessModes:
+ - ReadWriteOnce
+ resources:
+ requests:
+ storage: 2Gi
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+ name: opengym-media
+spec:
+ accessModes:
+ - ReadWriteOnce
+ resources:
+ requests:
+ storage: 2Gi
diff --git a/kubernetes/service.yaml b/kubernetes/service.yaml
new file mode 100644
index 000000000..2b5d9c31e
--- /dev/null
+++ b/kubernetes/service.yaml
@@ -0,0 +1,14 @@
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: opengym
+spec:
+ type: ClusterIP
+ ports:
+ - name: web
+ port: 80
+ protocol: TCP
+ targetPort: web
+ selector:
+ app: opengym