Hindsight-LXC: Container hindsight (pve52, HA, .185), Rolle hindsight-stack, Firewall, Prometheus-Ziel, embed-default gebunden (Auftrag 22.10.)
ci / test (push) Failing after 25s
ci / test (pull_request) Failing after 26s

Task 6.1 ist seit 19.10. in k3s live (embed-default/rerank-default in gpu-pve44/46, Adressen .186/.178);
Task 6.3 (LiteLLM-Slots) läuft als PR im Workflows-Repo. Entscheidungen und offene Schritte außerhalb des Repos
(tofu apply, Playbooks, Portainer, DHCP-Reservierung) in docs/auftraege/2026-10-22-hindsight-cluster.md,
Betrieb in docs/BETRIEB.md Abschnitt 16.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Robert Rapp
2026-10-22 19:33:29 +02:00
co-authored by Claude Fable 5.1
parent 3108ca4739
commit 7d889344bd
14 changed files with 452 additions and 3 deletions
+6
View File
@@ -39,6 +39,12 @@ all:
infra: {}
vars:
ansible_user: root
# LXC hindsight (22.10., Rolle hindsight-stack, playbooks/hindsight.yml); Adresse aus inventory.generated.yml
hindsight:
hosts:
hindsight: {}
vars:
ansible_user: root
# Dienst-VMs ohne GPU (D6): k3s-Steuerung. Adresse aus inventory.generated.yml (Gruppe service_vms).
service_vms:
hosts:
@@ -0,0 +1,12 @@
# LXC hindsight (Auftrag docs/auftraege/2026-10-22-hindsight-cluster.md): Docker, Compose-Stack nex-hindsight,
# Firewall, Cron. Reihenfolge auf ops (Verzeichnis platform/proxmox):
# 1. LXC anlegen: cd tofu && . /root/.config/knaster/tofu.env && tofu plan && tofu apply
# 2. Zugang: bash ../scripts/refresh-vm-access.sh # Adresse + Hostschlüssel, inventory.generated.yml
# 3. HA/Replikation: cd ../ansible && ansible-playbook playbooks/site.yml --limit pve52 # Rolle pve-host auf dem Heimatknoten
# 4. Stack: ansible-playbook playbooks/hindsight.yml
# 5. Monitoring: ansible-playbook playbooks/monitoring.yml --limit infra # Prometheus-Ziel + Alert nachziehen
# Voraussetzungen auf ops: /root/nex-hindsight (Clone, privat), /root/.config/knaster/hindsight-litellm.env
# (HINDSIGHT_LLM_API_KEY, LITELLM_API_KEY), /root/.config/knaster/gitea-registry.env (Pull des privaten Images).
- name: LXC hindsight – Docker und Stack nex-hindsight
hosts: hindsight
roles: [docker-host, hindsight-stack]
@@ -0,0 +1,66 @@
# Compose-Stack nex-hindsight im LXC hindsight (Auftrag docs/auftraege/2026-10-22-hindsight-cluster.md; Repo
# mygodel/nex-hindsight: Spec §5/§6/§10, docs/BETRIEB.md, deploy/compose/hindsight). Muster wie infra-stack:
# hindsight_repo_dir Kopie des Repos nex-hindsight von ops (bei jedem Lauf abgeglichen, --delete)
# hindsight_state_dir .env (0600, Geheimnisse), postgres/, backup/, export/, logs/ – nie im Repo, nie überschrieben
hindsight_repo_src: /root/nex-hindsight # Clone auf ops; das Repo ist privat, ein Mensch klont mit eigenem Zugang
hindsight_state_dir: /opt/knaster/hindsight
hindsight_repo_dir: "{{ hindsight_state_dir }}/repo"
hindsight_compose_project: nex-hindsight
hindsight_compose_file: "{{ hindsight_repo_dir }}/deploy/compose/hindsight/docker-compose.yml"
# Image gepinnt auf einen Build-Tag der Gitea-Registry (Build-Action in nex-hindsight: :latest und :<sha>).
# Anheben nur hier per PR; danach Playbook laufen lassen (pull + up).
hindsight_image: gitea.mindboost.team/mygodel/nex-hindsight:43469db # Build vom 20.10.2026 (= latest am 22.10.)
# Dateien auf ops mit Geheimnissen (werden nie ausgegeben):
# gitea-registry.env REGISTRY_USER, REGISTRY_TOKEN – Pull aus dem privaten Paket
# hindsight-litellm.env HINDSIGHT_LLM_API_KEY, LITELLM_API_KEY – Schlüssel des LiteLLM auf appsrv08 (Mensch legt an)
hindsight_registry: gitea.mindboost.team
hindsight_registry_env: /root/.config/knaster/gitea-registry.env
hindsight_litellm_env: /root/.config/knaster/hindsight-litellm.env
# Einstellungen in .env (keine Geheimnisse; Namen aus deploy/compose/hindsight/.env.example). Änderungen hier.
hindsight_settings:
HINDSIGHT_IMAGE: "{{ hindsight_image }}"
# LLM nur über LiteLLM mit PSE auf appsrv08 (Cluster-Regel D4); Alias hindsight-llm → verifier-small (Qwen3-4B,
# llama.cpp gpu-pve48), kein Cloud-Modell. Port 4000 ist dort nur für diesen LXC freigegeben (DOCKER-USER-Regel).
HINDSIGHT_LLM_BASE_URL: http://192.168.100.29:4000/v1
HINDSIGHT_LLM_MODEL: hindsight-llm
LITELLM_API_BASE: http://192.168.100.29:4000
# Embedding/Rerank aus dem Cluster über LiteLLM (Slots embed-default/rerank-default, registry.yaml: gebunden).
HINDSIGHT_EMBEDDINGS_MODEL: embed-default
HINDSIGHT_RERANKER_PROVIDER: litellm
HINDSIGHT_RERANKER_MODEL: rerank-default
# Rückweg laut Spec §6, falls LiteLLM /rerank nicht durchreicht: HINDSIGHT_RERANKER_PROVIDER=cohere mit dieser URL
HINDSIGHT_RERANKER_COHERE_BASE_URL: http://192.168.100.186:8082/v1/rerank
HINDSIGHT_BIND: 0.0.0.0
HINDSIGHT_MEMORY_LIMIT: 2G
HINDSIGHT_STATE_DIR: "{{ hindsight_state_dir }}"
HINDSIGHT_API_URL: http://127.0.0.1:8888
# Lastfenster der Hintergrundjobs (Spec E7): Prometheus im Infra-LXC, GPU-Auslastung aus nvidia_gpu_exporter
# (Metrik nvidia_smi_utilization_gpu_ratio, 0–1; der Spec-Default llamacpp:gpu_utilization existiert nicht).
PROMETHEUS_URL: http://192.168.100.188:9090
JOBS_WINDOW: "22:00-06:00"
JOBS_LOAD_MAX: "20"
JOBS_LOAD_QUERY: "max(avg_over_time(nvidia_smi_utilization_gpu_ratio[15m])) * 100"
# Geheimnisse, die im Container einmalig erzeugt werden (openssl rand) und danach nie geändert werden
hindsight_secrets: [POSTGRES_PASSWORD]
# Firewall im LXC (nex-hindsight Spec E16, Plan Teil 3 Task 14): Port 8888 nur von Hosts, die Agenten ausführen
# oder den Dienst prüfen. Übergangsregel bis das Gate (E14) live ist: GODE-NB-14, infra (Prometheus) und der
# Gitea-Runner (Stack gitrunner auf appsrv08, Vault-Seed-Action). Danach die k3s-Knoten und 192.168.100.0/24.
# Docker veröffentlicht Ports an ufw vorbei, deshalb greift die Liste in der Kette DOCKER-USER (Skript
# knaster-hindsight-fw), ufw schützt nur die übrigen Ports (SSH aus dem LAN).
hindsight_api_port: 8888
hindsight_api_allow_from:
- {ip: 192.168.100.181, comment: GODE-NB-14 Admin-Laptop USB-LAN}
- {ip: 192.168.100.188, comment: infra Prometheus}
- {ip: 192.168.100.29, comment: appsrv08 Gitea-Runner gitrunner (Vault-Seed)}
hindsight_ssh_from: 192.168.100.0/24
hindsight_timezone: Europe/Berlin
# Cron (nex-hindsight docs/BETRIEB.md): Jobs stündlich (laufen nur im Fenster), pg_dump täglich 03:30
hindsight_cron:
- {name: hindsight-jobs, minute: "0", hour: "*", job: "{{ hindsight_repo_dir }}/scripts/jobs-run.sh"}
- {name: hindsight-backup, minute: "30", hour: "3", job: "{{ hindsight_repo_dir }}/deploy/compose/hindsight/backup.sh"}
@@ -0,0 +1,13 @@
[Unit]
Description=Hindsight-API-Port nur von erlaubten Quellen (DOCKER-USER-Regel, Rolle hindsight-stack)
Documentation=file:///usr/local/sbin/knaster-hindsight-fw
After=docker.service
Requires=docker.service
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/knaster-hindsight-fw
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,215 @@
# Compose-Stack nex-hindsight: Hindsight-API + pgvector-Postgres im LXC hindsight. Idempotent wie infra-stack:
# Geheimnisse nur anlegen, wenn sie fehlen; compose up ändert nur, was sich geändert hat.
- name: Repo-Clone auf ops vorhanden?
ansible.builtin.stat:
path: "{{ hindsight_repo_src }}/deploy/compose/hindsight/docker-compose.yml"
delegate_to: localhost
become: false
register: repo_src
- name: Abbruch ohne Repo-Clone
ansible.builtin.assert:
that: repo_src.stat.exists
fail_msg: "{{ hindsight_repo_src }} fehlt auf ops: git clone https://gitea.mindboost.team/mygodel/nex-hindsight.git {{ hindsight_repo_src }} (privates Repo, eigener Zugang)"
- name: Schlüsseldateien auf ops vorhanden?
ansible.builtin.stat:
path: "{{ item }}"
loop: ["{{ hindsight_registry_env }}", "{{ hindsight_litellm_env }}"]
delegate_to: localhost
become: false
register: key_files
- name: Abbruch ohne Schlüsseldateien
ansible.builtin.assert:
that: key_files.results | map(attribute='stat.exists') | min
fail_msg: "Auf ops fehlt {{ hindsight_registry_env }} (REGISTRY_USER/REGISTRY_TOKEN) oder {{ hindsight_litellm_env }} (HINDSIGHT_LLM_API_KEY/LITELLM_API_KEY)"
- name: Zeitzone (Jobfenster 22:00–06:00 gilt sonst in UTC)
community.general.timezone:
name: "{{ hindsight_timezone }}"
- name: Werkzeuge (node für die Cron-Skripte, ufw, cron)
ansible.builtin.apt:
name: [rsync, openssl, curl, nodejs, ufw, cron, python3]
state: present
update_cache: true
cache_valid_time: 3600
- name: Verzeichnisse
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
mode: "{{ item.mode }}"
loop:
- {path: /opt/knaster, mode: "0755"}
- {path: "{{ hindsight_state_dir }}", mode: "0700"}
- {path: "{{ hindsight_repo_dir }}", mode: "0755"}
- {path: "{{ hindsight_state_dir }}/postgres", mode: "0700"}
- {path: "{{ hindsight_state_dir }}/backup", mode: "0700"}
- {path: "{{ hindsight_state_dir }}/export", mode: "0700"}
- {path: "{{ hindsight_state_dir }}/logs", mode: "0755"}
# Nie .git, node_modules oder .env-Dateien; Container-Benutzer müssen lesen können
- name: Repo nex-hindsight von ops abgleichen
ansible.posix.synchronize:
src: "{{ hindsight_repo_src }}/"
dest: "{{ hindsight_repo_dir }}/"
delete: true
rsync_opts:
- "--chmod=go+rX,go-w"
- "--exclude=.git"
- "--exclude=node_modules"
- "--exclude=.env"
- "--exclude=postgres/"
- name: Einstellungen in .env
ansible.builtin.lineinfile:
path: "{{ hindsight_state_dir }}/.env"
regexp: "^{{ item.key }}="
line: "{{ item.key }}={{ item.value }}"
create: true
mode: "0600"
loop: "{{ hindsight_settings | dict2items }}"
# Gibt nur Namen aus, nie Werte
- name: Fehlende Geheimnisse im Container erzeugen
ansible.builtin.shell: |
set -eu
umask 077
f={{ hindsight_state_dir }}/.env
for k in {{ hindsight_secrets | join(' ') }}; do
grep -q "^$k=" "$f" || { echo "$k=$(openssl rand -hex 24)" >> "$f"; echo "neu: $k"; }
done
chmod 0600 "$f"
args:
executable: /bin/bash
register: secrets_gen
changed_when: "'neu:' in secrets_gen.stdout"
# LiteLLM-Schlüssel aus der Datei auf ops (Zeilen KEY=WERT), nie im Protokoll
- name: LiteLLM-Schlüssel in .env
ansible.builtin.lineinfile:
path: "{{ hindsight_state_dir }}/.env"
regexp: "^{{ item.0 }}="
line: "{{ item.0 }}={{ item.1 }}"
mode: "0600"
loop: "{{ lookup('file', hindsight_litellm_env) | regex_findall('(?m)^([A-Z_]+)=(.*)$') }}"
loop_control:
label: "{{ item.0 }}"
no_log: true
- name: .env prüfen (Altnamen, CHANGE_ME-Reste)
ansible.builtin.command: node {{ hindsight_repo_dir }}/scripts/validate.mjs --env {{ hindsight_state_dir }}/.env
changed_when: false
- name: Registry-Anmeldung für das private Image
community.docker.docker_login:
registry_url: "{{ hindsight_registry }}"
username: "{{ _reg | selectattr(0, 'equalto', 'REGISTRY_USER') | map(attribute=1) | first }}"
password: "{{ _reg | selectattr(0, 'equalto', 'REGISTRY_TOKEN') | map(attribute=1) | first }}"
vars:
_reg: "{{ lookup('file', hindsight_registry_env) | regex_findall('(?m)^([A-Z_]+)=(.*)$') }}"
no_log: true
# HA-Umzug: Nach zfs receive liefert der Zielknoten veralteten Seiten-Cache (BETRIEB.md Abschnitt 7); gleicher
# Schutz wie im Infra-LXC, Dateien aus der Rolle infra-stack.
- name: Schutz gegen veralteten Seiten-Cache – Skript
ansible.builtin.copy:
src: "{{ role_path }}/../infra-stack/files/knaster-drop-stale-cache.py"
dest: /usr/local/sbin/knaster-drop-stale-cache
mode: "0755"
- name: Schutz gegen veralteten Seiten-Cache – systemd-Dienst vor containerd/docker
ansible.builtin.copy:
src: "{{ role_path }}/../infra-stack/files/knaster-drop-stale-cache.service"
dest: /etc/systemd/system/knaster-drop-stale-cache.service
mode: "0644"
register: dropcache_unit
- name: Schutz gegen veralteten Seiten-Cache – aktivieren
ansible.builtin.systemd:
name: knaster-drop-stale-cache.service
enabled: true
daemon_reload: "{{ dropcache_unit.changed }}"
# --- Firewall: ufw für SSH und alles Übrige, DOCKER-USER für den veröffentlichten Port 8888 ---
- name: ufw ohne IPv6 (unprivilegierter LXC, nur IPv4 im LAN)
ansible.builtin.lineinfile:
path: /etc/default/ufw
regexp: "^IPV6="
line: IPV6=no
- name: ufw – SSH aus dem LAN erlauben (vor dem Einschalten, sonst sperrt sich Ansible aus)
community.general.ufw:
rule: allow
from_ip: "{{ hindsight_ssh_from }}"
port: "22"
proto: tcp
comment: ssh-lan
- name: ufw – eingehend sonst ablehnen, ausgehend erlauben
community.general.ufw:
direction: "{{ item.direction }}"
default: "{{ item.policy }}"
loop:
- {direction: incoming, policy: deny}
- {direction: outgoing, policy: allow}
- name: ufw einschalten
community.general.ufw:
state: enabled
- name: DOCKER-USER-Regel für Port {{ hindsight_api_port }} – Skript
ansible.builtin.template:
src: knaster-hindsight-fw.sh.j2
dest: /usr/local/sbin/knaster-hindsight-fw
mode: "0755"
register: fw_script
- name: DOCKER-USER-Regel – systemd-Dienst nach Docker
ansible.builtin.copy:
src: knaster-hindsight-fw.service
dest: /etc/systemd/system/knaster-hindsight-fw.service
mode: "0644"
register: fw_unit
- name: DOCKER-USER-Regel – aktivieren und anwenden
ansible.builtin.systemd:
name: knaster-hindsight-fw.service
enabled: true
state: "{{ 'restarted' if (fw_script.changed or fw_unit.changed) else 'started' }}"
daemon_reload: "{{ fw_unit.changed }}"
# --- Stack ---
- name: Image ziehen (gepinnter Tag)
ansible.builtin.command: >
docker compose -p {{ hindsight_compose_project }} --env-file {{ hindsight_state_dir }}/.env
-f {{ hindsight_compose_file }} pull --quiet
changed_when: false
- name: Stack starten
ansible.builtin.command: >
docker compose -p {{ hindsight_compose_project }} --env-file {{ hindsight_state_dir }}/.env
-f {{ hindsight_compose_file }} up -d --remove-orphans
register: compose_up
changed_when: compose_up.stderr is search('Container \S+\s+(Created|Recreated|Started)')
- name: Warten, bis die API gesund ist
ansible.builtin.uri:
url: "http://127.0.0.1:{{ hindsight_api_port }}/health"
status_code: 200
register: hs_health
until: hs_health.status == 200
retries: 30
delay: 10
- name: Cron (Jobs im Lastfenster, Backup)
ansible.builtin.cron:
name: "{{ item.name }}"
minute: "{{ item.minute }}"
hour: "{{ item.hour }}"
job: "{{ item.job }}"
loop: "{{ hindsight_cron }}"
loop_control:
label: "{{ item.name }}"
@@ -0,0 +1,20 @@
#!/bin/sh
# Verwaltet von Ansible (Rolle hindsight-stack). Port {{ hindsight_api_port }} (Hindsight-API) nur von erlaubten Quellen.
# Docker veröffentlicht Ports in seiner eigenen Kette vor ufw; ufw-Regeln greifen für den Port nicht. Deshalb
# filtert diese Kette in DOCKER-USER (von Docker für genau solche Regeln vorgesehen). Idempotent, läuft nach
# docker.service (knaster-hindsight-fw.service) und bei jedem Ansible-Lauf mit geänderter Liste.
set -eu
PATH=/usr/sbin:/usr/bin:/sbin:/bin
for i in $(seq 30); do iptables -S DOCKER-USER >/dev/null 2>&1 && break; sleep 2; done
iptables -S DOCKER-USER >/dev/null 2>&1 || { echo "DOCKER-USER fehlt (Docker nicht gestartet?)" >&2; exit 1; }
iptables -N KNASTER-HINDSIGHT 2>/dev/null || iptables -F KNASTER-HINDSIGHT
{% for src in hindsight_api_allow_from %}
iptables -A KNASTER-HINDSIGHT -s {{ src.ip }} -j RETURN # {{ src.comment }}
{% endfor %}
iptables -A KNASTER-HINDSIGHT -j DROP
rule="-i eth0 -p tcp -m conntrack --ctorigdstport {{ hindsight_api_port }} -j KNASTER-HINDSIGHT"
iptables -C DOCKER-USER $rule 2>/dev/null || iptables -I DOCKER-USER 1 $rule
echo "Port {{ hindsight_api_port }} offen für: {{ hindsight_api_allow_from | map(attribute='ip') | join(' ') }}"
+5 -1
View File
@@ -32,8 +32,12 @@ output "ansible_inventory" {
all = { children = {
gpu_vms = { hosts = { for k, ip in local.gpu_vm_ipv4 : k => { ansible_host = ip } if ip != null } }
service_vms = { hosts = { for k, ip in local.svc_vm_ipv4 : k => { ansible_host = ip } if ip != null } }
# je Container eine Gruppe mit seinem Namen (infra, hindsight): site.yml spielt infra-stack nur auf infra
infra = { hosts = {
for k, v in proxmox_virtual_environment_container.infra : k => { ansible_host = v.ipv4["eth0"] } if try(v.ipv4["eth0"], null) != null
for k, v in proxmox_virtual_environment_container.infra : k => { ansible_host = v.ipv4["eth0"] } if k == "infra" && try(v.ipv4["eth0"], null) != null
} }
hindsight = { hosts = {
for k, v in proxmox_virtual_environment_container.infra : k => { ansible_host = v.ipv4["eth0"] } if k == "hindsight" && try(v.ipv4["eth0"], null) != null
} }
} }
})