Compare commits
3 Commits
aa42b86833
...
a3809d57a4
| Author | SHA1 | Date | |
|---|---|---|---|
| a3809d57a4 | |||
| 3a8012e694 | |||
| 93400ff998 |
@@ -0,0 +1,108 @@
|
||||
# AGENTS.md
|
||||
|
||||
Guidance for OpenCode agents working in this repo. Read this before editing manifests.
|
||||
|
||||
## What this repo is
|
||||
|
||||
Plain Kubernetes manifests (no Helm, no kustomize, no build step) for a homelab
|
||||
cluster on Hetzner Cloud. Cilium is the CNI/LB; Hetzner CSI (`hcloud-volumes`)
|
||||
and a SMB CSI (`slow`) provide storage. There is no application source code —
|
||||
every file is YAML/TXT applied with `kubectl apply -f`.
|
||||
|
||||
## Commands
|
||||
|
||||
- Apply a manifest: `kubectl apply -f <path>`
|
||||
- No lint/typecheck/test pipeline exists. Verify changes by applying against the
|
||||
cluster and checking `kubectl get/describe/logs`.
|
||||
- Monitoring stack only: install/upgrade via Helm (see `README.md` for exact
|
||||
commands and the pinned chart version `87.3.0`). Do not re-apply the Grafana
|
||||
manifests via `kubectl apply` and Helm together — Grafana is hand-managed
|
||||
(`Monitoring/Grafana/`), Prometheus is Helm-managed.
|
||||
|
||||
## Storage — gotchas that bit us
|
||||
|
||||
- **`slow` is the default StorageClass** (SMB CSI). `hcloud-volumes` is *not*
|
||||
default. PVCs that omit `storageClassName` land on SMB, not Hetzner volumes —
|
||||
set it explicitly when you want Hetzner block storage.
|
||||
- `local-storage` (`no-provisioner`) requires a matching manual `PersistentVolume`
|
||||
with `nodeAffinity`; it only binds on the node hosting the PV. Used by the
|
||||
legacy postgres StatefulSet.
|
||||
- Only one default StorageClass may exist. If `kubectl get sc` shows two
|
||||
`(default)`, patch the unwanted one:
|
||||
`kubectl patch sc <name> -p '{"metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'`
|
||||
|
||||
## Network / IP layout (non-obvious)
|
||||
|
||||
- Cilium `LoadBalancerIPPool`s hand out LB IPs from two pools:
|
||||
- `lan-pool` `10.1.0.101–10.1.0.199` — Cilium ingresses.
|
||||
- `postgres-pool` `10.2.0.0/24` — dedicated postgres LB, stable IP `10.2.0.122`.
|
||||
- A LB IP is pinned via annotation `lbipam.cilium.io/ips: <ip>` on the Service,
|
||||
backed by a matching `CiliumLoadBalancerIPPool`. Keep both in sync or the IP
|
||||
won't allocate.
|
||||
- Node IPs have moved (`10.0.2.x` → `10.1.0.x`). Any manifest referencing the
|
||||
old registry `10.0.2.119:5000` is unreachable from current nodes; use the
|
||||
public image `pgvector/pgvector:pg18-trixie` instead (see PostgreSQL migration).
|
||||
|
||||
## Secrets are gitignored
|
||||
|
||||
`.gitignore` drops `Secrets/` and any `*secret*.yaml`. Secret manifests in the
|
||||
tree are expected to be created out-of-band and are **not committed**. Do not
|
||||
`git add` a `*_secret.yaml`/`*_secret.yml`. Read existing secret values from the
|
||||
cluster with `kubectl get secret` if you need them for a migration step.
|
||||
|
||||
## PostgreSQL directory — read the runbook first
|
||||
|
||||
`PostgreSQL/MIGRATION_RUNBOOK.md` is the source of truth for the postgres
|
||||
StatefulSet → `postgres-hetzner` Deployment migration (logical dump/restore,
|
||||
downtime required, IP repoint `10.0.2.116 → 10.2.0.122`). Do not edit
|
||||
`PostgreSQL/` manifests without reading it.
|
||||
|
||||
Layout:
|
||||
- `PostgreSQL/Old/` — legacy StatefulSet manifests (`postgress_deplay.yaml`
|
||||
keeps the original typo'd filename deliberately; used as rollback reference).
|
||||
- `PostgreSQL/hetzner/` — new Deployment/PVC/Service on `hcloud-volumes`.
|
||||
- `PostgreSQL/postgres_service.yaml`, `postgres_lb_service.yaml` — the two
|
||||
Services repointed at `app: postgres-hetzner` after cutover.
|
||||
|
||||
## Monitoring directory
|
||||
|
||||
- Prometheus is managed by the **kube-prometheus-stack** Helm release; values in
|
||||
`Monitoring/kube-prometheus-stack.values.yaml`. Bundled Grafana is disabled
|
||||
(`grafana.enabled: false`); the Grafana in `Monitoring/Grafana/` is
|
||||
hand-managed and points its datasource at
|
||||
`prometheus-operated.monitoring.svc.cluster.local:9090`.
|
||||
- `Monitoring/Prometheus/` is empty — the old hand-rolled Prometheus manifests
|
||||
were removed when the Helm chart replaced them. Don't recreate them.
|
||||
- To add a scrape target, create a `ServiceMonitor`/`PodMonitor` CR anywhere;
|
||||
the Prometheus CR selects all (`serviceMonitorSelector: {}`).
|
||||
|
||||
## Docker directory
|
||||
|
||||
- `Docker/PostgreSQL/` holds the custom PostgreSQL image build (base
|
||||
`postgres:18.4` + `pgvector` v0.8.2 built from source, plus rclone/python
|
||||
helpers). The image is built and pushed by `Docker/PostgreSQL/PostgreSQL_Build.sh`
|
||||
to the private registry `rg.mariushome.lt/custom-postgres`.
|
||||
- This is the only build step in the repo; everything else is plain manifests.
|
||||
Run the shell script from the `Docker/PostgreSQL/` directory so the Docker
|
||||
build context is correct.
|
||||
- The registry `rg.mariushome.lt` is the public-facing name for the image
|
||||
formerly served from `10.0.2.119:5000`. Prefer pulling
|
||||
`rg.mariushome.lt/custom-postgres` over the legacy `10.0.2.119:5000/...` path
|
||||
(the latter is unreachable from current nodes — see Network / IP layout).
|
||||
|
||||
## Cluster admin notes (operational, not manifests)
|
||||
|
||||
- `Cluster_admin/nodes_restart_commands.txt` — drain/reboot/uncordon sequence
|
||||
per node. Follow that order; node names are real hostnames.
|
||||
- `Cluster_admin/move _data_example.txt` — one-line `kubectl cp` example (the
|
||||
leading space in the filename is intentional).
|
||||
|
||||
## Editing conventions
|
||||
|
||||
- Keep filenames as committed, including typos (`postgress_deplay.yaml`,
|
||||
`move _data_example.txt`). Other docs and the runbook reference them by name.
|
||||
- Manifests use `app` label selectors; do not introduce `app.kubernetes.io/*`
|
||||
labels mid-stream without updating every consumer (Services, ServiceMonitors).
|
||||
- Prefer editing existing files over creating new ones; new manifests should
|
||||
follow the per-directory pattern (e.g. `<thing>_deployment.yaml`,
|
||||
`<thing>_service.yaml`, `<thing>_pvc.yaml`).
|
||||
@@ -0,0 +1,22 @@
|
||||
# Use the official PostgreSQL image as base
|
||||
FROM postgres:18.4
|
||||
|
||||
# Install build dependencies and pgvector
|
||||
RUN apt-get update && apt-get install -y \
|
||||
build-essential \
|
||||
git \
|
||||
postgresql-server-dev-18 \
|
||||
python3 \
|
||||
python3-pip \
|
||||
python3-psycopg2 \
|
||||
rclone \
|
||||
&& git clone --branch v0.8.2 https://github.com/pgvector/pgvector.git \
|
||||
&& cd pgvector \
|
||||
&& make \
|
||||
&& make install \
|
||||
&& cd .. \
|
||||
&& rm -rf pgvector \
|
||||
&& apt-get remove -y build-essential git postgresql-server-dev-18 \
|
||||
&& apt-get autoremove -y \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")"
|
||||
docker build -t custom-postgres .
|
||||
docker tag custom-postgres rg.mariushome.lt/custom-postgres
|
||||
docker push rg.mariushome.lt/custom-postgres
|
||||
@@ -24,10 +24,25 @@ spec:
|
||||
value: /var/lib/registry
|
||||
- name: REGISTRY_HTTP_RELATIVEURLS
|
||||
value: "true"
|
||||
- name: REGISTRY_AUTH
|
||||
value: htpasswd
|
||||
- name: REGISTRY_AUTH_HTPASSWD_REALM
|
||||
value: "registry.mariushome.lt"
|
||||
- name: REGISTRY_AUTH_HTPASSWD_PATH
|
||||
value: /auth/htpasswd
|
||||
volumeMounts:
|
||||
- name: registry-storage
|
||||
mountPath: /var/lib/registry
|
||||
- name: registry-htpasswd
|
||||
mountPath: /auth
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: registry-storage
|
||||
persistentVolumeClaim:
|
||||
claimName: registry-pvc
|
||||
- name: registry-htpasswd
|
||||
secret:
|
||||
secretName: registry-htpasswd
|
||||
items:
|
||||
- key: htpasswd
|
||||
path: htpasswd
|
||||
@@ -0,0 +1,60 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: postgres-hetzner-config
|
||||
namespace: database
|
||||
data:
|
||||
postgresql.conf: |
|
||||
# PostgreSQL configuration file
|
||||
# Managed via Kubernetes ConfigMap (PostgreSQL/hetzner/postgres_configmap.yaml)
|
||||
# Edit here, then: kubectl apply -f postgres_configmap.yaml
|
||||
# Restart the Deployment to pick up changes: kubectl rollout restart deploy/postgres-hetzner -n database
|
||||
|
||||
# -----------------------------
|
||||
# Connection settings
|
||||
# -----------------------------
|
||||
listen_addresses = '*'
|
||||
port = 5432
|
||||
max_connections = 100
|
||||
|
||||
# -----------------------------
|
||||
# Memory / resource tuning
|
||||
# -----------------------------
|
||||
shared_buffers = 512MB
|
||||
work_mem = 16MB
|
||||
maintenance_work_mem = 256MB
|
||||
effective_cache_size = 4GB
|
||||
|
||||
# -----------------------------
|
||||
# WAL / replication
|
||||
# -----------------------------
|
||||
wal_level = replica
|
||||
max_wal_size = 4GB
|
||||
min_wal_size = 128MB
|
||||
checkpoint_completion_target = 0.9
|
||||
|
||||
# -----------------------------
|
||||
# Query planner
|
||||
# -----------------------------
|
||||
random_page_cost = 1.1
|
||||
effective_io_concurrency = 200
|
||||
|
||||
# -----------------------------
|
||||
# Autovacuum
|
||||
# -----------------------------
|
||||
autovacuum_max_workers = 3
|
||||
autovacuum_naptime = 60s
|
||||
|
||||
# -----------------------------
|
||||
# Logging
|
||||
# -----------------------------
|
||||
log_destination = 'stderr'
|
||||
logging_collector = off
|
||||
log_min_duration_statement = -1
|
||||
log_connections = off
|
||||
log_disconnections = off
|
||||
|
||||
# -----------------------------
|
||||
# Extensions (pgvector)
|
||||
# -----------------------------
|
||||
shared_preload_libraries = ''
|
||||
@@ -15,13 +15,21 @@ spec:
|
||||
labels:
|
||||
app: postgres-hetzner
|
||||
spec:
|
||||
imagePullSecrets:
|
||||
- name: registry-creds
|
||||
containers:
|
||||
- name: postgres
|
||||
image: pgvector/pgvector:pg18-trixie
|
||||
image: rg.mariushome.lt/custom-postgres
|
||||
imagePullPolicy: IfNotPresent
|
||||
args:
|
||||
- -c
|
||||
- config_file=/etc/postgresql/postgresql.conf
|
||||
volumeMounts:
|
||||
- name: postgres-data
|
||||
mountPath: /var/lib/postgresql
|
||||
- name: postgres-config
|
||||
mountPath: /etc/postgresql
|
||||
readOnly: true
|
||||
env:
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
@@ -37,3 +45,6 @@ spec:
|
||||
- name: postgres-data
|
||||
persistentVolumeClaim:
|
||||
claimName: postgres-hetzner-pvc
|
||||
- name: postgres-config
|
||||
configMap:
|
||||
name: postgres-hetzner-config
|
||||
@@ -69,3 +69,40 @@ points at `prometheus-operated.monitoring.svc.cluster.local:9090`).
|
||||
--docker-email=<email>
|
||||
```
|
||||
- Review every manifest before applying it to a production cluster.
|
||||
|
||||
## Private registry authentication
|
||||
|
||||
`rg.mariushome.lt` requires htpasswd auth. Two out-of-band secrets must be
|
||||
created before applying `DockerRegistry/docker_registry_deploy.yaml` and any
|
||||
workload pulling from the registry (e.g. `postgres-hetzner`).
|
||||
|
||||
1. **Registry htpasswd file** (consumed by the registry pod). Generate the
|
||||
htpasswd entry, then create the Secret in the `registry` namespace:
|
||||
|
||||
```bash
|
||||
htpasswd -Bbn <user> <password> > htpasswd
|
||||
kubectl create secret generic registry-htpasswd \
|
||||
--namespace=registry \
|
||||
--from-file=htpasswd=htpasswd
|
||||
rm htpasswd
|
||||
```
|
||||
|
||||
The deployment mounts this Secret at `/etc/docker/registry/htpasswd` and
|
||||
configures the registry with `REGISTRY_AUTH=htpasswd`.
|
||||
|
||||
2. **`registry-creds` imagePullSecret** — one per namespace that pulls from
|
||||
`rg.mariushome.lt`. Create it in every namespace that runs workloads
|
||||
referencing the registry (e.g. `database`):
|
||||
|
||||
```bash
|
||||
kubectl create secret docker-registry registry-creds \
|
||||
--namespace=<ns> \
|
||||
--docker-server=rg.mariushome.lt \
|
||||
--docker-username=<user> \
|
||||
--docker-password=<password> \
|
||||
--docker-email=<email>
|
||||
```
|
||||
|
||||
Manifests reference it as `imagePullSecrets: [{ name: registry-creds }]`.
|
||||
Rebuild/repush the image per `Docker/PostgreSQL/PostgreSQL_Build.sh` after
|
||||
rotating credentials.
|
||||
Reference in New Issue
Block a user