Skip to content

CDN-AI deployment and pilot status

CDN-AI answers natural-language questions about the real JASTV/3BB CDN telemetry. It runs as two services, the ai-agent (FastAPI, :8082) and the ai-mcp MCP server (:8085), in the ai namespace of the private staging k3s cluster, publicly reachable at castai.castis.io. The LLM is the llama.cpp 30B model (typhoon2.5-qwen3-30b-a3b) at <LLM_HOST_IP>:8001, outside the cluster.

This page covers how the stack is deployed and wired, plus the pilot status. For what the services do, see the other CDN-AI pages instead of repeating them here:

Topic Page
System overview, model, settings we use, ports AI
The agent: /chat loop, tool scoping, REST endpoints, UI pages FastAPI agent
The 27 MCP tools and how to add one MCP server
cdn_ai tables, DDL and column reference ClickHouse schema
Audit log, known issues, operational gotchas Logging & known issues
The Mac mini that hosts the LLM Local AI infrastructure

Live-changing pilot state (real node IPs, VPN and network paths, ArgoCD sync snapshots, Ansible workflows, ClickHouse audit scripts) stays in the cdn-ai repo, in docs/production-reference/real-infra-onboarding.md. The source warns it "will go stale", so it is not copied here.

Architecture

[Public]  castai.castis.io
                │
          APISIX (staging ns)
          ApisixRoute + ApisixTls
                │
          ApisixUpstream "upstream"
          <PRIVATE_CLUSTER_TAILSCALE_IP>:80 (Tailscale)
                │ (Tailscale mesh)
                ▼
[Private] castai.castis.io
                │
          APISIX gateway (apisix ns)
          HTTPRoute (Gateway API)
                │
                ▼
          ai-agent (ai ns, :8082)
                │
          ai-mcp (ai ns, :8085)
          MCP_STREAMER_URL: http://ai-mcp:8085/mcp
                │
          ClickHouse (analytic-stg, cdn_ai DB)
                │
          Vector DaemonSet (monitoring ns, kubernetes_logs)
                │
          cproxy-nuc / streamer pods (cdn ns)
Namespace What runs there
ai ai-agent and ai-mcp deployments
cdn cproxy and streamer workloads
staging APISIX public routes and certificates
analytic-stg ClickHouse
monitoring Vector DaemonSet

elb runs on the DigitalOcean cluster, not here, so the staging Vector can't collect it (see Cross-cluster collection gaps).

How it is deployed

All paths below are in playtelly-iac unless the section says otherwise.

cproxy and streamer log to stdout, and Vector collects them with its kubernetes_logs source. No hostPath volume or node-level mount is needed. Earlier setups used a hostPath volume and a Vector file source.

Both binaries write to a fixed log filename (size-based rotation, no date suffix), so one symlink from that path to /dev/stdout is enough:

# In the container command
mkdir -p /path/to/log/dir
ln -sf /dev/stdout /path/to/log/dir/app.log
./binary

cproxy, in services/cdn/cproxy/deployment.yaml (the logs volumeMount and the hostPath volume for /var/log/castis/cproxy were removed):

command:
  - bash
  - -c
  - |
    mkdir -p /data/log/cproxy &&
    ln -sf /dev/stdout /data/log/cproxy/cproxy.log &&
    ln -sf /dev/stdout /data/log/cproxy/stats.log &&
    cp /tmp/cproxy-init.yml /castis/bin/cproxy/cproxy.yml &&
    ./cproxy

streamer, in services/cdn/streamer/staging/deployment.yaml (the logs volumeMount and hostPath volume were removed; log.directory: /var/log/castis/streamer stays in the ConfigMap because the binary still writes there):

command:
  - bash
  - -c
  - |
    mkdir -p /var/log/castis/streamer &&
    ln -sf /dev/stdout /var/log/castis/streamer/streamer.log &&
    ./streamer

Vector pipelines

The pipelines are in services/monitoring/vector/configs/cdn/pipelines/. Each one fans out from the shared staging_logs kubernetes_logs source (defined in configs/staging/pipelines/logs.toml) by filtering on namespace and pod label, then parses in two branches (A/B) that both read from that filter:

[transforms.<name>_pods]
type = "filter"
inputs = ["staging_logs"]
condition = '''
  .kubernetes.pod_namespace == "cdn" &&
  (get(.kubernetes.pod_labels, ["app"]) ?? "") == "<app-label>"
'''

A broken VRL transform fails the whole Vector config, not just the new logic: check the Vector pod logs first when rows stop landing.

Agent and MCP kustomize stacks

The original services/ai/cdn-ai/ folder was split into two independent kustomize stacks, one per image:

services/ai/
├── agent/
│   ├── base/
│   │   ├── deployment.yaml      # ai-agent, port 8082
│   │   ├── service.yaml         # ClusterIP :8082
│   │   └── kustomization.yaml
│   └── overlays/staging/
│       ├── kustomization.yaml
│       ├── configmap.yaml       # ai-agent-config
│       └── secret.yaml          # ai-agent-secret
└── mcp/
    ├── base/
    │   ├── deployment.yaml      # ai-mcp, port 8085
    │   ├── service.yaml         # ClusterIP :8085
    │   └── kustomization.yaml
    └── overlays/staging/
        ├── kustomization.yaml
        ├── configmap.yaml       # ai-mcp-config
        └── secret.yaml          # ai-mcp-secret

The agent and ClickHouse settings and their values are in Settings we use. The deployment-only keys not listed there:

Object Key Value or content
ai-agent-config STREAMER_API_URL http://streamer.cdn.svc.cluster.local:18081
ai-agent-config CLICKHOUSE_PORT 8123
ai-agent-secret keys LLM_BASE_URL, CLICKHOUSE_PASSWORD
ai-mcp-config keys MCP_PORT (8085), STREAMER_API_URL, MAX_ROWS_RETURNED, the same CLICKHOUSE_* values as the agent
ai-mcp-secret keys CLICKHOUSE_PASSWORD

MAX_ITERATIONS is 4; earlier setups used 12 (lowered in 6f6fb80, 2026-09-20). A ConfigMap-only change does not restart the pods: see Operational gotchas.

Note

The implementation record set CLICKHOUSE_USER to analytics, while Settings we use says ai_readonly. Check services/ai/agent/overlays/staging/configmap.yaml for the live value.

ArgoCD apps

The apps are in argocd/apps/ai/. The old cdn-ai-staging.yml and cdn-ai-vector-staging.yml were replaced by:

App file Path Sync
ai-agent-staging.yml services/ai/agent/overlays/staging automated + selfHeal
ai-mcp-staging.yml services/ai/mcp/overlays/staging automated + selfHeal

Vector stays under the monitoring ArgoCD app.

ClickHouse

  • Database cdn_ai in the analytic-stg namespace; the password is in the agent and MCP secrets.
  • Migration job 07-cdn-ai-migration.yaml in services/monitoring/clickhouse/staging/ holds the DDL (readable copy: ClickHouse schema). Two records disagree on how it runs: the pilot log says it was registered and versioned so ArgoCD runs it (3e01078 / a4dee06, 2026-09-19); the staging implementation record says it was removed from kustomization.yaml and is run manually against the cluster when needed. Check that kustomization before relying on either.
  • Vector writes with its own credentials from services/monitoring/vector/ch-write-secret.yaml, which is gitignored. To deploy fresh, copy the example, fill in the credentials and apply it:
cp ch-write-secret.example.yaml ch-write-secret.yaml
# edit credentials, then apply manually
kubectl apply -f ch-write-secret.yaml -n monitoring

The command prints secret/<SECRET_NAME> created (or configured when it already exists).

APISIX routing

Public route. In apisix/staging/public/, namespace staging. All staging public routes share one ApisixUpstream. Traffic goes internet → APISIX (staging ns) → Tailscale <PRIVATE_CLUSTER_TAILSCALE_IP>:80 → private cluster → ai-agent.

File Resource Purpose
upstream/staging-upstream.yaml ApisixUpstream (name upstream) Routes to <PRIVATE_CLUSTER_TAILSCALE_IP>:80 (Tailscale/Headscale IP) through externalNodes
certificate/ai-agent-cert.yaml Certificate Let's Encrypt certificate for castai.castis.io
tls/ai-agent-tls.yaml ApisixTls Binds the certificate secret to the hostname
route/ai-agent-route.yaml ApisixRoute HTTP→HTTPS redirect, websocket, XFP headers; uses the shared upstream

Private route. apisix/staging/private/ai-agent-route.yaml, namespace ai: a Gateway API HTTPRoute on the APISIX gateway straight to the ai-agent service. There is no TLS termination or cert-manager on this path.

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: ai-agent-route
  namespace: ai
spec:
  parentRefs:
    - name: apisix-gateway
      namespace: apisix
  hostnames:
    - castai.castis.io
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /
      backendRefs:
        - name: ai-agent
          port: 8082

CI/CD (cdn-ai repo)

.gitlab-ci.yml and .gitlab-ci/.gitlab-ci-update-image-tag.yml in the cdn-ai repo build both images from the same agent/ context on every push, then bump both tags in playtelly-iac:

# Variables
GITOPS_AGENT_OVERLAY: "services/ai/agent/overlays"
GITOPS_MCP_OVERLAY:   "services/ai/mcp/overlays"

# Template
.update_tag_template:
  script:
    - kustomize edit set image .../ai-agent:$NEW_TAG   # in agent overlay
    - kustomize edit set image .../ai-mcp:$NEW_TAG     # in mcp overlay

# Jobs
build:staging       → produces ai-agent image
build:staging:mcp   → produces ai-mcp image
update_tag:staging  → extends .update_tag_template, needs both builds

ArgoCD then syncs the new tags (for example staging-769d78ba, b0a7678, 2026-09-20).

Verify

  • Agent: /health returns ok at castai.castis.io.
  • MCP: a run_query through the agent returns rows from cdn_ai. A raw GET /mcp returns 406, which only means the server is reachable.
  • Data: cproxy_events and streamer_events gain rows (see Pipelines → table).

Last live check: 2026-09-22, both passed.

Troubleshooting

Symptom Where to look
Wrong or slow answer The audit log: Logging & known issues
New rows not landing in ClickHouse Vector pod logs in monitoring for VRL compile errors
elb_events stays at 0 rows Expected: elb runs on DigitalOcean (collection gaps)
ConfigMap change has no effect Pods don't restart on a ConfigMap change (Operational gotchas)
Endpoint down briefly, 500s under load, context overflow Reliability (hosted agent)

Reference: MCP tools and pipelines

Compiled from a live audit of the staging cluster on 2026-09-17, counts re-checked on 2026-09-22. The per-module tool list is on MCP server; this section is the map of which table each tool reads.

Tools → table

cdn_ai.cproxy_events (+ elb_events via UNION): security: suspicious_ip_activity, ip_request_history, top_suspicious_paths, suspicious_ip_range_activity, component_traffic_breakdown, pop_traffic_breakdown, pop_attack_summary, node_attack_summary, device_ip_correlation. QoE: cmcd_qoe_score, qoe_score_trend, ip_range_qoe_scores, device_qoe_scores, pop_qoe_scores.

cdn_ai.streamer_events: stream: find_new_streams, streams_with_recent_traffic, current_viewer_counts, stream_lifecycle_events. log: log_level_breakdown, top_source_functions. (count_active_streams and get_stream_status call the streamer REST API directly, not ClickHouse.)

cdn_ai.cproxy_events: log: find_http_errors, top_clients.

All 27 tools target cdn_ai. Security and QoE always did; the stream and log tools were retargeted in 769d78b (2026-09-20). stream_bandwidth_trend was retired rather than retargeted, because the streamer firehose filter drops its underlying log lines.

Pipelines → table

Pipeline App label Writes to Status (2026-09-22)
ai_cproxy.toml cproxy-nuc cdn_ai.cproxy_events live, 800 rows
ai_elb.toml elb/gslb cdn_ai.elb_events live, 0 rows (elb is on another cluster)
ai_streamer_events.toml not recorded cdn_ai.streamer_events live, 13,172 rows
ai_cproxy_stats.toml cproxy-nuc streamer_analytics (stats logs) legacy demo
ai_cdn_access_cproxy.toml cproxy-nuc streamer_analytics.cdn_access_logs legacy demo
ai_cdn_access_elb.toml elb/gslb streamer_analytics.cdn_access_logs legacy demo
ai_streamer.toml streamer streamer_analytics.cdn_access_logs legacy demo
ai_security.toml none (fans out from cdnai_full_cproxy_parse and cdnai_full_elb_parse) streamer_analytics legacy demo

Retire the legacy demo pipelines once cdn_ai is fully confirmed.

Pilot status

Status of the pilot OKRs as of 2026-09-22. Commit hashes and dates are from git log ((iac) means playtelly-iac, otherwise cdn-ai); row and column counts are from a live run_query on the staging cdn_ai cluster through castai.castis.io. The model backend was confirmed the same day to honor tool calls. Local and Mac mini CDN setup, initial MCP server development, anomaly tooling and QoE scoring are tracked elsewhere.

Item Status
Two images, CI/CD, live on staging k3s Complete
Persistent device identity and device-sharing detection Complete
Standardized ClickHouse schema and Vector collection In progress (elb not shipping)
Agent chat reliability: scoped tools, retarget to new schema Complete
Real client IP / XFF through the edge Not started
Production demo data from a JASTV node Not started (tentative target 2026-09-30)

Two images, CI/CD, live on staging k3s

  • Split one image into Dockerfile.mcp + Dockerfile.agent: d6ab8b6, 2026-09-16.
  • GitLab CI builds ai-agent and ai-mcp as separate images: 7dd7666, 2026-09-16 (agent job f6a12c1).
  • CI update_image_tag bumps both tags in playtelly-iac per push: cc2579d, 2026-09-16.
  • ArgoCD deployed staging-769d78ba: b0a7678 (iac), 2026-09-20.
  • Verified live 2026-09-22: agent /health ok, MCP run_query runs against cdn_ai.

Device identity and device-sharing detection

A persistent per-device ID (X-Device-Id header, distinct from the per-playback CMCD session ID) reaches ClickHouse, and the device_ip_correlation tool flags one device seen from many IPs, the credential-sharing signal.

  • X-Device-Id capture end to end + device_ip_correlation: 654c7e7, 2026-09-16.
  • device_id column in the standardized cproxy schema: 8c14598 (iac), 2026-09-19.
  • Tool live on staging in the security category, verified 2026-09-22.
  • The signal is only as good as device_id coverage: rows without X-Device-Id are excluded, and real viewer traffic stays sparse (800 cproxy rows) until the real-IP work lands.

Standardized schema and Vector collection

The ad-hoc single-table demo schema became three per-component tables (cproxy, elb, streamer) with response-outcome fields and streamer lifecycle events. All three tables are deployed; collection is live for cproxy and streamer only.

  • Response/outcome + device/txn columns + streamer_events table: 8c14598 (iac), 2026-09-19.
  • DROP and recreate cproxy_events / elb_events on the clean schema: ba5e732 (iac), 2026-09-19.
  • Migration job registered and versioned for ArgoCD: 3e01078 / a4dee06 (iac), 2026-09-19.
  • Streamer lifecycle pipeline → cdn_ai.streamer_events: c038336 (iac), 2026-09-20 (crash fix d9250da).
  • Live 2026-09-22: 25 / 22 / 12 columns; cproxy 800 rows, streamer 13,172 rows (latest 2026-09-21 17:18).
  • Open: elb collection (table exists, 0 rows: elb runs on DigitalOcean and log shipping is not wired); gslb and cproxy-shield are not instrumented (design gap only).
  • Fixed in the cdn-ai repo while verifying: COLLECTION-DESIGN.md said the streamer was not built, and AI-PIPELINE-REFERENCE.md still called the stream/log tools orphaned.

Agent chat reliability

The slow "reached max steps" chat loop is fixed: the agent routes each question to a small tool subset instead of all 27 (Tool scoping), and every stream/log tool moved off the retired cdn_access_logs table.

  • MAX_ITERATIONS 12 → 4: 6f6fb80 (iac), 2026-09-20.
  • Tool scoping + retarget + retire stream_bandwidth_trend: 769d78b, 2026-09-20; deployed as staging-769d78ba.
  • Verified 2026-09-22: stream_lifecycle_events reads streamer_events with no dead-table error.
  • Open gap: on high-volume streamer_events, stream_lifecycle_events can overflow the 40k context window (43,695 tokens on a 30-minute query, 2026-09-22). The tool needs a row/char cap or aggregation before demos.

Real client IP / XFF through the edge

Real viewer IPs are needed for POP, IP-range and sharing analysis, but the client IP doesn't survive APISIX's SNAT/XFF stripping. Researched only (84b0659, 2026-09-17): no externalTrafficPolicy: Local or dedicated L4 LB change, and the custom X-Real-Viewer-Ip header path is documented but not implemented. The network-path investigation is in the cdn-ai onboarding doc.

Production demo data from a JASTV node

Drive real playback (manifests, CMCD, anomalies) at a JASTV production node so demos use production traffic. Nothing is built; it is blocked by the elb collection gap and the real-IP work. Day-to-day blocker status is in the cdn-ai repo's STAGING-DEVOPS-TODO.md.