Skip to content

Commit

Permalink
docs: Add Kubernetes installation with Kustomize (#324)
Browse files Browse the repository at this point in the history
* Add kubernetes installation

* Add kubernetes installation docs

* Simplify config

* Remove the patch to use only amd64 nodes and add sample env file
  • Loading branch information
j-fuentes authored Jul 29, 2024
1 parent 1ca951a commit 7ddfcad
Show file tree
Hide file tree
Showing 18 changed files with 385 additions and 0 deletions.
71 changes: 71 additions & 0 deletions docs/docs/02-Installation/04-kubernetes.md
Original file line number Diff line number Diff line change
@@ -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`.
6 changes: 6 additions & 0 deletions kubernetes/.env_sample
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions kubernetes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_manifest.yaml
24 changes: 24 additions & 0 deletions kubernetes/Makefile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Kubernetes installation with Kustomize

You can:

- edit the configuration in `.env`.

Then run `make deploy`.
26 changes: 26 additions & 0 deletions kubernetes/chrome-deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions kubernetes/data-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
51 changes: 51 additions & 0 deletions kubernetes/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions kubernetes/meilisearch-deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions kubernetes/meilisearch-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: meilisearch-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
11 changes: 11 additions & 0 deletions kubernetes/meilisearch-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: meilisearch
spec:
selector:
app: meilisearch
ports:
- protocol: TCP
port: 7700
targetPort: 7700
4 changes: 4 additions & 0 deletions kubernetes/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: hoarder
24 changes: 24 additions & 0 deletions kubernetes/redis-deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions kubernetes/redis-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
11 changes: 11 additions & 0 deletions kubernetes/redis-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: redis
spec:
selector:
app: redis
ports:
- protocol: TCP
port: 6379
targetPort: 6379
38 changes: 38 additions & 0 deletions kubernetes/web-deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions kubernetes/web-service.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 7ddfcad

Please sign in to comment.