Skip to content

Commit 8a07b62

Browse files
authored
docs: Various Kubernetes deployment improvements (hoarder-app#862)
* changed the secrets from configmap to secret object, create ingress instead of loadbalancer. Implemented the generation of a secret from the .env file and then put as environment variables into the deployments. Nextauth_URL is now set in the kustomization file and is then generated into a configmap and put as an env into the deployments. Opionated change: the web service is now a clusterIP Service and an ingress object is included. * changed the tls secret name in kustomize to a more example name * fixed image name in kustomization so the version tag gets replaced properly * tags are without v, otherwise we get an imagepullerror * removed unneccessary parts of the .env.sample * split env and secrets, added documentation, created sample ingress. changed the default from ingress back to Loadbalancer. Added Documentation on how to change to ingress and add TLS Support. split env to secret and env file which have to be configured before deploying.
1 parent cddaefd commit 8a07b62

7 files changed

+86
-17
lines changed

docs/docs/02-Installation/04-kubernetes.md

+45-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@
1010

1111
You can clone the repository and copy the `/kubernetes` directory into another directory of your choice.
1212

13-
### 2. Populate the environment variables
13+
### 2. Populate the environment variables and secrets
1414

15-
To configure the app, edit the configuration in `.env`.
15+
To configure the app, copy the `.env_sample` to `.env` and change to your specific needs.
1616

17-
18-
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.
17+
You should also change the `NEXTAUTH_URL` variable to point to your server address.
1918

2019
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).
2120

21+
To see all available configuration options check the [documentation](https://docs.hoarder.app/configuration).
22+
23+
To configure the neccessary secrets for the application copy the `.secrets_sample` file to `.secrets` and change the sample secrets to your generated secrets.
24+
25+
> Note: You **should** change the random strings. You can use `openssl rand -base64 36` to generate the random strings.
26+
2227
### 3. Setup OpenAI
2328

2429
To enable automatic tagging, you'll need to configure OpenAI. This is optional though but highly recommended.
@@ -56,16 +61,52 @@ make deploy
5661

5762
### 5. Access the service
5863

64+
#### via LoadBalancer IP
65+
5966
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.
6067

6168
Then visit `http://<loadbalancer-ip>:3000` and you should be greated with the Sign In page.
6269

6370
> Note: Depending on your setup you might want to expose the service via an Ingress, or have a different means to access it.
6471
72+
#### Via Ingress
73+
74+
If you want to use an ingress, you can customize the sample ingress in the kubernetes folder and change the host to the DNS name of your choice.
75+
76+
After that you have to configure the web service to the type ClusterIP so it is only reachable via the ingress.
77+
78+
If you have already deployed the service you can patch the web service to the type ClusterIP with the following command:
79+
80+
` kubectl -n hoarder patch service web -p '{"spec":{"type":"ClusterIP"}}' `
81+
82+
Afterwards you can apply the ingress and access the service via your chosen URL.
83+
84+
#### Setting up HTTPS access to the Service
85+
86+
To access hoarder securely you can configure the ingress to use a preconfigured TLS certificate. This requires that you already have the needed files, namely your .crt and .key file, on hand.
87+
88+
After you have deployed the hoarder manifests you can deploy your certificate for hoarder in the `hoarder` namespace with this example command. You can name the secret however you want. But be aware that the secret name in the ingress definition has to match the secret name.
89+
90+
` $ kubectl --namespace hoarder create secret tls hoarder-web-tls --cert=/path/to/crt --key=/path/to/key `
91+
92+
If the secret is successfully created you can now configure the Ingress to use TLS via this changes to the spec:
93+
94+
```` yaml
95+
spec:
96+
tls:
97+
- hosts:
98+
- hoarder.example.com
99+
secretName: hoarder-web-tls
100+
````
101+
102+
> Note: Be aware that the hosts have to match between the tls spec and the HTTP spec.
103+
65104
### [Optional] 6. Setup quick sharing extensions
66105

67106
Go to the [quick sharing page](/quick-sharing) to install the mobile apps and the browser extensions. Those will help you hoard things faster!
68107

69108
## Updating
70109

71110
Edit the `HOARDER_VERSION` variable in the `kustomization.yaml` file and run `make clean deploy`.
111+
112+
If you have chosen `release` as the image tag you can also destroy the web pod, since the deployment has an ImagePullPolicy set to always the pod always pulls the image from the registry, this way we can ensure that the newest release image is pulled.

kubernetes/.env_sample

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
HOARDER_VERSION=release
2-
# Use `openssl rand -base64 36` to generate the random strings
3-
NEXTAUTH_SECRET=generated_secret
4-
MEILI_MASTER_KEY=generated_secret
1+
# Put your configuration options here
52
NEXTAUTH_URL=http://localhost:3000
6-
NEXT_PUBLIC_SECRET="my-super-duper-secret-string"
3+
HOARDER_VERSION=release

kubernetes/.secrets_sample

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Use `openssl rand -base64 36` to generate the random strings
2+
NEXTAUTH_SECRET=generated_secret
3+
MEILI_MASTER_KEY=generated_secret
4+
NEXT_PUBLIC_SECRET="my-super-duper-secret-string"

kubernetes/ingress_sample.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: hoarder-web-ingress
5+
namespace: hoarder
6+
spec:
7+
rules:
8+
- host: "hoarder.example.com"
9+
http:
10+
paths:
11+
- path: "/"
12+
pathType: Prefix
13+
backend:
14+
service:
15+
name: "web"
16+
port:
17+
number: 3000

kubernetes/kustomization.yaml

+10-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ kind: Kustomization
33

44
namespace: hoarder
55

6-
configMapGenerator:
6+
secretGenerator:
77
- envs:
8-
- .env
9-
name: hoarder-env
8+
- .secrets
9+
name: hoarder-secrets
10+
11+
configMapGenerator:
12+
- envs:
13+
- .env
14+
name: hoarder-configuration
1015

1116
resources:
1217
- namespace.yaml
@@ -23,7 +28,7 @@ replacements:
2328
- source:
2429
fieldPath: data.HOARDER_VERSION
2530
kind: ConfigMap
26-
name: hoarder-env
31+
name: hoarder-configuration
2732
version: v1
2833
targets:
2934
- fieldPaths:
@@ -35,4 +40,4 @@ replacements:
3540
group: apps
3641
kind: Deployment
3742
name: web
38-
version: v1
43+
version: v1

kubernetes/meilisearch-deployment.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ spec:
2222
- mountPath: /meili_data
2323
name: meilisearch
2424
envFrom:
25+
- secretRef:
26+
name: hoarder-secrets
2527
- configMapRef:
26-
name: hoarder-env
28+
name: hoarder-configuration
2729
volumes:
2830
- name: meilisearch
2931
persistentVolumeClaim:

kubernetes/web-deployment.yaml

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ spec:
1414
spec:
1515
containers:
1616
- name: web
17-
image: ghcr.io/hoarder-app/hoarder:HOARDER_VERSION_PLACEHOLDER
17+
image: ghcr.io/hoarder-app/hoarder
18+
imagePullPolicy: Always
1819
ports:
1920
- containerPort: 3000
2021
env:
@@ -29,8 +30,10 @@ spec:
2930
- mountPath: /data
3031
name: data
3132
envFrom:
33+
- secretRef:
34+
name: hoarder-secrets
3235
- configMapRef:
33-
name: hoarder-env
36+
name: hoarder-configuration
3437
volumes:
3538
- name: data
3639
persistentVolumeClaim:

0 commit comments

Comments
 (0)