aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Fuentes Castillo <j-fuentes@users.noreply.github.com>2024-07-29 06:56:31 +0200
committerGitHub <noreply@github.com>2024-07-28 21:56:31 -0700
commit7ddfcad392abf5b4c2994c03f599d3a22e51ca96 (patch)
tree602b7c1c8bb2d6f93fa99ec14ef713d8e8e6e36d
parent1ca951af8919b572ffb5b178a0286f517660ed74 (diff)
downloadkarakeep-7ddfcad392abf5b4c2994c03f599d3a22e51ca96.tar.zst
docs: Add Kubernetes installation with Kustomize (#324)
* Add kubernetes installation * Add kubernetes installation docs * Simplify config * Remove the patch to use only amd64 nodes and add sample env file
-rw-r--r--docs/docs/02-Installation/04-kubernetes.md71
-rw-r--r--kubernetes/.env_sample6
-rw-r--r--kubernetes/.gitignore1
-rw-r--r--kubernetes/Makefile24
-rw-r--r--kubernetes/README.md7
-rw-r--r--kubernetes/chrome-deployment.yaml26
-rw-r--r--kubernetes/data-pvc.yaml10
-rw-r--r--kubernetes/kustomization.yaml51
-rw-r--r--kubernetes/meilisearch-deployment.yaml30
-rw-r--r--kubernetes/meilisearch-pvc.yaml10
-rw-r--r--kubernetes/meilisearch-service.yaml11
-rw-r--r--kubernetes/namespace.yaml4
-rw-r--r--kubernetes/redis-deployment.yaml24
-rw-r--r--kubernetes/redis-pvc.yaml10
-rw-r--r--kubernetes/redis-service.yaml11
-rw-r--r--kubernetes/web-deployment.yaml38
-rw-r--r--kubernetes/web-service.yaml12
-rw-r--r--kubernetes/workers-deployment.yaml39
18 files changed, 385 insertions, 0 deletions
diff --git a/docs/docs/02-Installation/04-kubernetes.md b/docs/docs/02-Installation/04-kubernetes.md
new file mode 100644
index 00000000..2a418227
--- /dev/null
+++ b/docs/docs/02-Installation/04-kubernetes.md
@@ -0,0 +1,71 @@
+# Kubernetes
+
+### Requirements
+
+- A kubernetes cluster
+- kubectl
+- kustomize
+
+### 1. Get the deployment manifests
+
+You can clone the repository and copy the `/kubernetes` directory into another directory of your choice.
+
+### 2. Populate the environment variables
+
+To configure the app, edit the configuration in `.env`.
+
+
+You **should** change the random strings. You can use `openssl rand -base64 36` to generate the random strings. You should also change the `NEXTAUTH_URL` variable to point to your server address.
+
+Using `HOARDER_VERSION=release` will pull the latest stable version. You might want to pin the version instead to control the upgrades (e.g. `HOARDER_VERSION=0.10.0`). Check the latest versions [here](https://github.com/hoarder-app/hoarder/pkgs/container/hoarder-web).
+
+### 3. Setup OpenAI
+
+To enable automatic tagging, you'll need to configure OpenAI. This is optional though but hightly recommended.
+
+- Follow [OpenAI's help](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key) to get an API key.
+- Add the OpenAI API key to the `.env` file:
+
+```
+OPENAI_API_KEY=<key>
+```
+
+Learn more about the costs of using openai [here](/openai).
+
+<details>
+ <summary>[EXPERIMENTAL] If you want to use Ollama (https://ollama.com/) instead for local inference.</summary>
+
+ **Note:** The quality of the tags you'll get will depend on the quality of the model you choose. Running local models is a recent addition and not as battle tested as using openai, so proceed with care (and potentially expect a bunch of inference failures).
+
+ - Make sure ollama is running.
+ - Set the `OLLAMA_BASE_URL` env variable to the address of the ollama API.
+ - Set `INFERENCE_TEXT_MODEL` to the model you want to use for text inference in ollama (for example: `mistral`)
+ - Set `INFERENCE_IMAGE_MODEL` to the model you want to use for image inference in ollama (for example: `llava`)
+ - Make sure that you `ollama pull`-ed the models that you want to use.
+
+
+</details>
+
+### 4. Deploy the service
+
+Deploy the service by running:
+
+```
+make deploy
+```
+
+### 5. Access the service
+
+By default, these manifests expose the application as a LoadBalancer Service. You can run `kubectl get services` to identify the IP of the loadbalancer for your service.
+
+Then visit `http://<loadbalancer-ip>:3000` and you should be greated with the Sign In page.
+
+> Note: Depending on your setup you might want to expose the service via an Ingress, or have a different means to access it.
+
+### [Optional] 6. Setup quick sharing extensions
+
+Go to the [quick sharing page](/quick-sharing) to install the mobile apps and the browser extensions. Those will help you hoard things faster!
+
+## Updating
+
+Edit the `HOARDER_VERSION` variable in the `kustomization.yaml` file and run `make clean deploy`.
diff --git a/kubernetes/.env_sample b/kubernetes/.env_sample
new file mode 100644
index 00000000..c34a7ba9
--- /dev/null
+++ b/kubernetes/.env_sample
@@ -0,0 +1,6 @@
+HOARDER_VERSION=release
+# Use `openssl rand -base64 36` to generate the random strings
+NEXTAUTH_SECRET=generated_secret
+MEILI_MASTER_KEY=generated_secret
+NEXTAUTH_URL=http://localhost:3000
+NEXT_PUBLIC_SECRET="my-super-duper-secret-string"
diff --git a/kubernetes/.gitignore b/kubernetes/.gitignore
new file mode 100644
index 00000000..640b1b51
--- /dev/null
+++ b/kubernetes/.gitignore
@@ -0,0 +1 @@
+_manifest.yaml
diff --git a/kubernetes/Makefile b/kubernetes/Makefile
new file mode 100644
index 00000000..0ca00e2c
--- /dev/null
+++ b/kubernetes/Makefile
@@ -0,0 +1,24 @@
+# Define the output file
+OUTPUT_FILE := _manifest.yaml
+
+# Define the Kustomize build command
+KUSTOMIZE_BUILD := kustomize build .
+
+# The default target
+all: build
+
+$(OUTPUT_FILE):
+ $(KUSTOMIZE_BUILD) > $(OUTPUT_FILE)
+
+# Build the Kustomize configuration into the output file
+build: clean $(OUTPUT_FILE)
+
+# Deploy the manifest using kubectl apply
+deploy: $(OUTPUT_FILE)
+ kubectl apply -f $(OUTPUT_FILE)
+
+# Clean up the output file
+clean:
+ rm -f $(OUTPUT_FILE)
+
+.PHONY: all build deploy clean
diff --git a/kubernetes/README.md b/kubernetes/README.md
new file mode 100644
index 00000000..c589f3cf
--- /dev/null
+++ b/kubernetes/README.md
@@ -0,0 +1,7 @@
+# Kubernetes installation with Kustomize
+
+You can:
+
+- edit the configuration in `.env`.
+
+Then run `make deploy`.
diff --git a/kubernetes/chrome-deployment.yaml b/kubernetes/chrome-deployment.yaml
new file mode 100644
index 00000000..bc49fac8
--- /dev/null
+++ b/kubernetes/chrome-deployment.yaml
@@ -0,0 +1,26 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: chrome
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: chrome
+ template:
+ metadata:
+ labels:
+ app: chrome
+ spec:
+ containers:
+ - name: chrome
+ image: gcr.io/zenika-hub/alpine-chrome:123
+ command:
+ - chromium-browser
+ - --headless
+ - --no-sandbox
+ - --disable-gpu
+ - --disable-dev-shm-usage
+ - --remote-debugging-address=0.0.0.0
+ - --remote-debugging-port=9222
+ - --hide-scrollbars
diff --git a/kubernetes/data-pvc.yaml b/kubernetes/data-pvc.yaml
new file mode 100644
index 00000000..0217be5a
--- /dev/null
+++ b/kubernetes/data-pvc.yaml
@@ -0,0 +1,10 @@
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+ name: data-pvc
+spec:
+ accessModes:
+ - ReadWriteOnce
+ resources:
+ requests:
+ storage: 1Gi \ No newline at end of file
diff --git a/kubernetes/kustomization.yaml b/kubernetes/kustomization.yaml
new file mode 100644
index 00000000..4155f71f
--- /dev/null
+++ b/kubernetes/kustomization.yaml
@@ -0,0 +1,51 @@
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+
+namespace: hoarder
+
+configMapGenerator:
+- envs:
+ - .env
+ name: hoarder-env
+
+resources:
+- namespace.yaml
+- web-deployment.yaml
+- web-service.yaml
+- redis-deployment.yaml
+- redis-service.yaml
+- chrome-deployment.yaml
+- meilisearch-deployment.yaml
+- meilisearch-service.yaml
+- workers-deployment.yaml
+- redis-pvc.yaml
+- meilisearch-pvc.yaml
+- data-pvc.yaml
+
+replacements:
+- source:
+ fieldPath: data.HOARDER_VERSION
+ kind: ConfigMap
+ name: hoarder-env
+ version: v1
+ targets:
+ - fieldPaths:
+ - spec.template.spec.containers.0.image
+ options:
+ delimiter: ':'
+ index: 1
+ select:
+ group: apps
+ kind: Deployment
+ name: web
+ version: v1
+ - fieldPaths:
+ - spec.template.spec.containers.0.image
+ options:
+ delimiter: ':'
+ index: 1
+ select:
+ group: apps
+ kind: Deployment
+ name: workers
+ version: v1
diff --git a/kubernetes/meilisearch-deployment.yaml b/kubernetes/meilisearch-deployment.yaml
new file mode 100644
index 00000000..7cc90e03
--- /dev/null
+++ b/kubernetes/meilisearch-deployment.yaml
@@ -0,0 +1,30 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: meilisearch
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: meilisearch
+ template:
+ metadata:
+ labels:
+ app: meilisearch
+ spec:
+ containers:
+ - name: meilisearch
+ image: getmeili/meilisearch:v1.6
+ env:
+ - name: MEILI_NO_ANALYTICS
+ value: "true"
+ volumeMounts:
+ - mountPath: /meili_data
+ name: meilisearch
+ envFrom:
+ - configMapRef:
+ name: hoarder-env
+ volumes:
+ - name: meilisearch
+ persistentVolumeClaim:
+ claimName: meilisearch-pvc \ No newline at end of file
diff --git a/kubernetes/meilisearch-pvc.yaml b/kubernetes/meilisearch-pvc.yaml
new file mode 100644
index 00000000..379835d1
--- /dev/null
+++ b/kubernetes/meilisearch-pvc.yaml
@@ -0,0 +1,10 @@
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+ name: meilisearch-pvc
+spec:
+ accessModes:
+ - ReadWriteOnce
+ resources:
+ requests:
+ storage: 1Gi \ No newline at end of file
diff --git a/kubernetes/meilisearch-service.yaml b/kubernetes/meilisearch-service.yaml
new file mode 100644
index 00000000..373384e6
--- /dev/null
+++ b/kubernetes/meilisearch-service.yaml
@@ -0,0 +1,11 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: meilisearch
+spec:
+ selector:
+ app: meilisearch
+ ports:
+ - protocol: TCP
+ port: 7700
+ targetPort: 7700 \ No newline at end of file
diff --git a/kubernetes/namespace.yaml b/kubernetes/namespace.yaml
new file mode 100644
index 00000000..8c1a8893
--- /dev/null
+++ b/kubernetes/namespace.yaml
@@ -0,0 +1,4 @@
+apiVersion: v1
+kind: Namespace
+metadata:
+ name: hoarder
diff --git a/kubernetes/redis-deployment.yaml b/kubernetes/redis-deployment.yaml
new file mode 100644
index 00000000..b9665e15
--- /dev/null
+++ b/kubernetes/redis-deployment.yaml
@@ -0,0 +1,24 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: redis
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: redis
+ template:
+ metadata:
+ labels:
+ app: redis
+ spec:
+ containers:
+ - name: redis
+ image: redis:7.2-alpine
+ volumeMounts:
+ - mountPath: /data
+ name: redis
+ volumes:
+ - name: redis
+ persistentVolumeClaim:
+ claimName: redis-pvc \ No newline at end of file
diff --git a/kubernetes/redis-pvc.yaml b/kubernetes/redis-pvc.yaml
new file mode 100644
index 00000000..81437e5b
--- /dev/null
+++ b/kubernetes/redis-pvc.yaml
@@ -0,0 +1,10 @@
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+ name: redis-pvc
+spec:
+ accessModes:
+ - ReadWriteOnce
+ resources:
+ requests:
+ storage: 1Gi \ No newline at end of file
diff --git a/kubernetes/redis-service.yaml b/kubernetes/redis-service.yaml
new file mode 100644
index 00000000..f55ae588
--- /dev/null
+++ b/kubernetes/redis-service.yaml
@@ -0,0 +1,11 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: redis
+spec:
+ selector:
+ app: redis
+ ports:
+ - protocol: TCP
+ port: 6379
+ targetPort: 6379 \ No newline at end of file
diff --git a/kubernetes/web-deployment.yaml b/kubernetes/web-deployment.yaml
new file mode 100644
index 00000000..d4e28024
--- /dev/null
+++ b/kubernetes/web-deployment.yaml
@@ -0,0 +1,38 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: web
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: hoarder-web
+ template:
+ metadata:
+ labels:
+ app: hoarder-web
+ spec:
+ containers:
+ - name: web
+ image: ghcr.io/hoarder-app/hoarder-web:HOARDER_VERSION_PLACEHOLDER
+ ports:
+ - containerPort: 3000
+ env:
+ - name: REDIS_HOST
+ value: redis
+ - name: REDIS_PORT
+ value: '6379'
+ - name: MEILI_ADDR
+ value: http://meilisearch:7700
+ - name: DATA_DIR
+ value: /data
+ volumeMounts:
+ - mountPath: /data
+ name: data
+ envFrom:
+ - configMapRef:
+ name: hoarder-env
+ volumes:
+ - name: data
+ persistentVolumeClaim:
+ claimName: data-pvc
diff --git a/kubernetes/web-service.yaml b/kubernetes/web-service.yaml
new file mode 100644
index 00000000..1e96233b
--- /dev/null
+++ b/kubernetes/web-service.yaml
@@ -0,0 +1,12 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: web
+spec:
+ selector:
+ app: hoarder-web
+ ports:
+ - protocol: TCP
+ port: 3000
+ targetPort: 3000
+ type: LoadBalancer \ No newline at end of file
diff --git a/kubernetes/workers-deployment.yaml b/kubernetes/workers-deployment.yaml
new file mode 100644
index 00000000..ed4ef838
--- /dev/null
+++ b/kubernetes/workers-deployment.yaml
@@ -0,0 +1,39 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: workers
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: hoarder-workers
+ template:
+ metadata:
+ labels:
+ app: hoarder-workers
+ spec:
+ containers:
+ - name: workers
+ image: ghcr.io/hoarder-app/hoarder-workers:HOARDER_VERSION_PLACEHOLDER
+ env:
+ - name: REDIS_HOST
+ value: redis
+ - name: REDIS_PORT
+ value: '6379'
+ - name: MEILI_ADDR
+ value: http://meilisearch:7700
+ - name: BROWSER_WEB_URL
+ value: http://chrome:9222
+ - name: DATA_DIR
+ value: /data
+ # Add OPENAI_API_KEY to the ConfigMap if necessary
+ volumeMounts:
+ - mountPath: /data
+ name: data
+ envFrom:
+ - configMapRef:
+ name: hoarder-env
+ volumes:
+ - name: data
+ persistentVolumeClaim:
+ claimName: data-pvc