Skip to content

Instantly share code, notes, and snippets.

@dvcrn
Last active November 11, 2024 02:50
Show Gist options
  • Save dvcrn/14f698d6b5a7fe290e8ac591d11e268f to your computer and use it in GitHub Desktop.
Save dvcrn/14f698d6b5a7fe290e8ac591d11e268f to your computer and use it in GitHub Desktop.
Beeper Bridge K8s
# you don't really need Kustomize here but it's convenient
# I mainly use it for the configMapGenerator, basically turnint the file at my local drive under config/facebook.yml (bridge config)
# into a kubernetes config map that then gets mounted into the statefulset
resources:
- pvc.yml
- statefulset.yml
- svc.yml
configMapGenerator:
- name: matrix-facebook-config
files:
- config.yaml=config/facebook.yml
# this is specific to vultr, but any kubernetes provider has some way of getting storage mounted
# this config file is telling kubernetes to allocate a new storage volume with 10gb, with storage class 'vultr-block-storage-retain'
# Vultr (my hosting provider) is then creating a new 10gb drive and mounts it to the pod
# ('retain' here means that it stays around even if I delete the entire statefulset)
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: matrix-bridge-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: vultr-block-storage-retain
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: conduwuit-facebook
spec:
replicas: 1
selector:
matchLabels:
app: conduwuit-facebook
template:
metadata:
labels:
app: conduwuit-facebook
spec:
containers:
- name: conduwuit-facebook
imagePullPolicy: Always
image: dvcrn/matrix-meta-nodelete:latest # <- this is the docker image of what to pull
command: ["mautrix-meta", "-c", "/config/config.yaml", "--no-update"] # <- how to start the container, with custom config path
env:
- name: "TZ"
- name: "DB_DIR"
value: "/data"
volumeMounts:
# this volume mount here is the persistent volume, aka storage
# this is for the bridge to store stuff like database and what not
# basically anything that needs to be persisted
- name: "matrix-bridge-pvc"
mountPath: "/data"
subPath: "facebook-bridge-conduwuit" # <- I personally run multiple bridges on the same storage, so I use subpath to separate them
- name: config
mountPath: /config
resources:
requests:
cpu: "0"
memory: "0Mi"
limits:
cpu: "0"
memory: "0Mi"
volumes:
# this is telling to mount the pvc 'matrix-bridge-pvc'
- name: matrix-bridge-pvc
persistentVolumeClaim:
claimName: matrix-bridge-pvc
readOnly: false
# this is a virtual volume, basically we just turn the static yaml config file into a 'volume'
# then mount it under /config (see above)
- name: config
projected:
sources:
- configMap:
name: matrix-facebook-config
# this is the service for internal routing. it's not needed for beeper because beeper supports websockets
# but since I'm using my own matrix server, the server itself has to somehow communicate with the bridge
# The bridge listens on port 29319 and I use that to expose the correct port, so that the matrix server can call the bridge directly
---
apiVersion: v1
kind: Service
metadata:
name: conduwuit-facebook
spec:
selector:
app: conduwuit-facebook
ports:
- port: 29319
targetPort: 29319
name: bridge
@dvcrn
Copy link
Author

dvcrn commented Nov 11, 2024

Example of using bbctl instead of bridge container:

      containers:
        - name: matrix-gmessages
          imagePullPolicy: Always
          image: ghcr.io/beeper/bridge-manager:latest
          # command: ["printenv"]
          env:
            - name: "TZ"
              value: "Asia/Tokyo"
            - name: "BRIDGE_NAME"
              value: "sh-gmessages"
            - name: "DB_DIR"
              value: "/data"
            - name: "MATRIX_ACCESS_TOKEN"
              valueFrom:
                secretKeyRef:
                  name: matrix-bridge
                  key: MATRIX_ACCESS_TOKEN_2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment