first commit

This commit is contained in:
Jack Halford 2024-02-17 13:58:36 +01:00
commit 6c7d14a7c9
No known key found for this signature in database
GPG key ID: A427D956E8E67679
2 changed files with 128 additions and 0 deletions

30
README.md Normal file
View file

@ -0,0 +1,30 @@
Inspired by [linkding on fly.io](https://github.com/fspoettel/linkding-on-fly)
## Storing the state in s3
You'll an s3 compatible bucket, like backblaze, aws, cloudflare or any compatible provider. Litestream will restore the bucket in an `emptyDir`. Then during operation a `litestream` sidecar will live replicate the changes to s3.
## Contents of `manifest.yaml`
- a `Namespace` for the project
- a `ConfigMap` containing `litestream.yml` config
- replace `$S3_ENDPOINT` with your bucket config
- a `StatefulSet` containing
- an `initContainer` to restore the sqlite db
- a `Pod` with `linkding` + `litestream` official images
- a `Service` to expose the pods
- I'm using tailscale annotations, replace these with traefik or your favorite ingress controller stuff.
## Setup
```
$ export S3_ENDPOINT=<REPLACE ME>
$ export S3_BUCKET=<REPLACE ME>
$ export S3_PATH=<REPLACE ME>
$ export S3_ACCESS_KEY_ID=<REPLACE ME>
$ export S3_SECRET_ACCESS_KEY=<REPLACE ME>
$ envsubst <manifest.yaml | kubectl apply -f -
$ kubectl create secret -n linkding generic litestream-s3 \
--from-literal=LITESTREAM_ACCESS_KEY_ID=$S3_ACCESS_KEY_ID \
--from-literal=LITESTREAM_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY
```

98
manifest.yaml Normal file
View file

@ -0,0 +1,98 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: linkding
---
apiVersion: v1
kind: ConfigMap
metadata:
name: litestream
namespace: linkding
data:
litestream.yml: |
dbs:
- path: '/etc/linkding/data/db.sqlite3'
replicas:
- type: s3
bucket: '$S3_BUCKET'
path: '$S3_PATH'
endpoint: '$S3_ENDPOINT'
force-path-style: true
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: linkding
namespace: linkding
labels:
app: linkding
spec:
replicas: 1
selector:
matchLabels:
app: linkding
template:
metadata:
labels:
app: linkding
spec:
volumes:
- name: data
emptyDir: {}
- name: litestream-config
configMap:
name: litestream
items:
- key: litestream.yml
path: litestream.yml
initContainers:
- name: init-litestream
image: litestream/litestream:latest
args: ['restore', '/etc/linkding/data/db.sqlite3']
envFrom:
- secretRef:
name: litestream-s3
volumeMounts:
- name: data
mountPath: /etc/linkding/data
- name: litestream-config
mountPath: /etc/litestream.yml
subPath: litestream.yml
containers:
- name: litestream
image: litestream/litestream:latest
args: ['replicate']
envFrom:
- secretRef:
name: litestream-s3
volumeMounts:
- name: data
mountPath: /etc/linkding/data
- name: litestream-config
mountPath: /etc/litestream.yml
subPath: litestream.yml
- name: linkding
image: sissbruecker/linkding:latest
ports:
- containerPort: 9090
name: http
volumeMounts:
- name: data
mountPath: /etc/linkding/data
---
apiVersion: v1
kind: Service
metadata:
name: linkding
namespace: linkding
annotations:
tailscale.com/expose: "true"
tailscale.com/hostname: "linkding"
spec:
selector:
app: linkding
ports:
- name: http
port: 80
targetPort: http