Vector victorialogs
title: Vector and VictoriaLogs on k3s description: The Vector pipeline that ships k3s pod logs to VictoriaLogs and CDN AI events to ClickHouse: layout, config and operations. audience: internal type: reference owner: platform-team last_reviewed: 2026-11-19
Overview¶
This wiki documents the full observability pipeline for collecting Kubernetes pod logs using Vector and storing them in VictoriaLogs (visualized via Grafana), plus CDN AI analytics pipelines that write structured events to ClickHouse.
k3s pods (production / staging / cdn / ai namespaces)
└── Vector (DaemonSet — one pod per node)
├── VictoriaLogs ← structured log storage (Grafana)
└── ClickHouse ← CDN AI analytics (ai_cdn_access_*, events, stats)
Architecture¶
| Component | Namespace | Type |
|---|---|---|
| Vector | monitoring |
DaemonSet |
| VictoriaLogs | monitoring |
Deployment |
| Grafana | monitoring |
Deployment |
| ClickHouse | analytic-stg |
StatefulSet |
Repository Structure¶
services/monitoring/vector/
├── kustomization.yaml ← namespace: monitoring, includes ch-write-secret.yaml
├── patch-vector-volumes.yaml ← Strategic Merge Patch for DaemonSet volumes
├── 00-serviceaccount.yaml
├── 01-clusterrole.yaml
├── 02-clusterrolebinding.yaml
├── 03-daemonset.yaml
├── ch-write-secret.yaml ← ClickHouse write credentials (gitignored)
└── configs/
├── kustomization.yaml ← resources: production/, staging/, vernemq/, cdn/
├── production/ ← kubernetes_logs for production namespace → VictoriaLogs
│ ├── kustomization.yaml
│ ├── main.toml
│ ├── sinks.toml
│ └── pipelines/logs.toml
├── staging/ ← kubernetes_logs for cdn/ai namespaces → VictoriaLogs
│ ├── kustomization.yaml ← defines staging_logs source (reused by cdn pipelines)
│ ├── main.toml
│ ├── sinks.toml
│ └── pipelines/logs.toml
├── vernemq/ ← VerneMQ broker logs → VictoriaLogs
│ ├── kustomization.yaml
│ ├── main.toml
│ ├── sinks.toml
│ └── pipelines/logs.toml
└── cdn/ ← CDN AI analytics pipelines → ClickHouse
├── kustomization.yaml ← configMapGenerator: vector-config-cdn
└── pipelines/
├── ai_cproxy.toml ← cproxy access events → cdn_ai.cproxy_events
├── ai_cproxy_stats.toml ← cproxy stats logs → streamer_analytics
├── ai_elb.toml ← elb/gslb events → cdn_ai.elb_events
├── ai_cdn_access_cproxy.toml ← full cproxy access → streamer_analytics.cdn_access_logs
├── ai_cdn_access_elb.toml ← full elb access → streamer_analytics.cdn_access_logs
├── ai_streamer.toml ← streamer logs → streamer_analytics.cdn_access_logs
└── ai_security.toml ← security enrichment fan-out
Kustomize Setup¶
How the patch works¶
The DaemonSet uses a projected volume to merge multiple ConfigMaps into /etc/vector/. Each service has its own ConfigMap. The patch adds new ConfigMaps to the projected volume sources.
Critical lesson learned: Kustomize patches in a child
kustomization.yamlcannot patch resources defined in the parent. The patch MUST be at the same level as the DaemonSet — inservices/monitoring/vector/kustomization.yaml, not inconfigs/kustomization.yaml.
Root kustomization.yaml¶
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: monitoring
resources:
- 00-serviceaccount.yaml
- 01-clusterrole.yaml
- 02-clusterrolebinding.yaml
- 03-daemonset.yaml
- configs/
- ch-write-secret.yaml
patchesStrategicMerge:
- patch-vector-volumes.yaml
patch-vector-volumes.yaml¶
Add a new configmap here when adding a new service:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: vector
namespace: monitoring
spec:
template:
spec:
volumes:
- name: config
projected:
sources:
- configMap:
name: vector-config-production
- configMap:
name: vector-config-staging
- configMap:
name: vector-config-vernemq
- configMap:
name: vector-config-cdn
Why Strategic Merge Patch instead of JSON Patch? JSON patch
op: replacein a child kustomization cannot reach the DaemonSet in the parent. Strategic Merge Patch at the root level is cleaner and more reliable with ArgoCD server-side apply.
configs/kustomization.yaml¶
Resources only — no patch here:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: monitoring
resources:
- production/
- staging/
- vernemq/
- cdn/
Per-service kustomization.yaml¶
Each service generates its own ConfigMap with disableNameSuffixHash: true so the patch can reference the name without hash suffix:
# configs/production/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: monitoring
generatorOptions:
disableNameSuffixHash: true
configMapGenerator:
- name: vector-config-production
files:
- production_main.toml=main.toml
- production_sinks.toml=sinks.toml
- production_logs.toml=pipelines/logs.toml
Vector Configuration¶
03-daemonset.yaml¶
Key points:
- Uses a projected volume to merge multiple ConfigMaps into /etc/vector/
- terminationGracePeriodSeconds: 60 allows Vector to flush pending data before shutdown
- Runs as DaemonSet — one pod per node, each pod collects logs only from its own node
- ClickHouse credentials (CH_USER, CH_PASSWORD) are injected via env from the cdn-ai-ch-write Secret
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: vector
namespace: monitoring
labels:
app: vector
spec:
selector:
matchLabels:
app: vector
minReadySeconds: 1
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
template:
metadata:
labels:
app: vector
spec:
serviceAccountName: vector
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
- name: vector
image: timberio/vector:0.39.0-debian
imagePullPolicy: IfNotPresent
args:
- --config-dir
- /etc/vector/
env:
- name: VECTOR_SELF_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: PROCFS_ROOT
value: /host/proc
- name: SYSFS_ROOT
value: /host/sys
- name: CH_USER
valueFrom:
secretKeyRef:
name: cdn-ai-ch-write
key: CH_USER
- name: CH_PASSWORD
valueFrom:
secretKeyRef:
name: cdn-ai-ch-write
key: CH_PASSWORD
volumeMounts:
- name: config
mountPath: /etc/vector/
readOnly: true
- name: data
mountPath: /vector-data-dir
- name: var-log
mountPath: /var/log/
readOnly: true
- name: var-lib
mountPath: /var/lib
readOnly: true
- name: procfs
mountPath: /host/proc
readOnly: true
- name: sysfs
mountPath: /host/sys
readOnly: true
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "256Mi"
cpu: "500m"
terminationGracePeriodSeconds: 60
volumes:
- name: config
projected:
sources:
- configMap:
name: vector-config-production
- name: data
hostPath:
path: /var/lib/vector
type: DirectoryOrCreate
- name: var-log
hostPath:
path: /var/log/
- name: var-lib
hostPath:
path: /var/lib
- name: procfs
hostPath:
path: /proc
- name: sysfs
hostPath:
path: /sys
ClickHouse Write Secret (ch-write-secret.yaml)¶
Gitignored. Contains the cdn-ai-ch-write Secret with CH_USER and CH_PASSWORD. An example template is provided as ch-write-secret.example.yaml.
cp ch-write-secret.example.yaml ch-write-secret.yaml
# edit credentials, then apply manually
kubectl apply -f ch-write-secret.yaml -n monitoring
RBAC¶
00-serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: vector
namespace: monitoring
labels:
app: vector
01-clusterrole.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: vector
labels:
app: vector
rules:
- apiGroups: [""]
resources:
- namespaces
- nodes
- pods
verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
resources:
- replicasets
verbs: ["get", "list", "watch"]
02-clusterrolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: vector
labels:
app: vector
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: vector
subjects:
- kind: ServiceAccount
name: vector
namespace: monitoring
Service Pipelines¶
Production (production namespace → VictoriaLogs)¶
configs/production/main.toml
[sources.production_logs]
type = "kubernetes_logs"
self_node_name = "${VECTOR_SELF_NODE_NAME}"
exclude_paths_glob_patterns = ["/var/log/pods/monitoring_vector-*/**"]
configs/production/pipelines/logs.toml
[transforms.production_parse]
type = "remap"
inputs = ["production_logs"]
source = '''
if .kubernetes.pod_namespace != "production" {
abort
}
.namespace = .kubernetes.pod_namespace
.pod = .kubernetes.pod_name
.container = .kubernetes.container_name
.node = .kubernetes.pod_node_name
if exists(.kubernetes.pod_labels.app) {
.app = .kubernetes.pod_labels.app
} else {
.app = "unknown"
}
.level = "info"
.timestamp = format_timestamp!(now(), format: "%+")
del(.kubernetes)
del(.file)
del(.source_type)
del(.stream)
'''
configs/production/sinks.toml
[sinks.production_victoria_logs]
type = "elasticsearch"
inputs = ["production_parse"]
endpoints = ["http://victorialogs.monitoring.svc.cluster.local:9428/insert/elasticsearch"]
mode = "bulk"
compression = "gzip"
healthcheck.enabled = false
[sinks.production_victoria_logs.query]
_msg_field = "message"
_time_field = "timestamp"
_stream_fields = "namespace,pod,container,app"
Staging (cdn/ai namespaces → VictoriaLogs + shared source for CDN pipelines)¶
The staging config serves two purposes:
1. Forwards logs from the cdn and ai namespaces to VictoriaLogs
2. Defines the staging_logs source that all CDN AI ClickHouse pipelines fan out from
configs/staging/main.toml
[sources.staging_logs]
type = "kubernetes_logs"
self_node_name = "${VECTOR_SELF_NODE_NAME}"
exclude_paths_glob_patterns = ["/var/log/pods/monitoring_vector-*/**"]
configs/staging/pipelines/logs.toml — filters cdn/ai namespaces to VictoriaLogs, then each CDN pipeline (in configs/cdn/) branches from staging_logs for ClickHouse.
configs/staging/sinks.toml
[sinks.staging_victoria_logs]
type = "elasticsearch"
inputs = ["staging_parse"]
endpoints = ["http://victorialogs.monitoring.svc.cluster.local:9428/insert/elasticsearch"]
mode = "bulk"
compression = "gzip"
healthcheck.enabled = false
[sinks.staging_victoria_logs.query]
_msg_field = "message"
_time_field = "timestamp"
_stream_fields = "namespace,pod,container,app"
VerneMQ (vernemq namespace → VictoriaLogs)¶
Standard pattern — kubernetes_logs source filtered to vernemq namespace, forwarded to VictoriaLogs.
CDN AI Pipelines (ClickHouse)¶
All CDN AI pipelines live in configs/cdn/pipelines/ and fan out from the staging_logs source defined in configs/staging/. They write to ClickHouse at clickhouse.analytic-stg.svc.cluster.local:8123 using credentials from the cdn-ai-ch-write Secret (${CH_USER} / ${CH_PASSWORD}).
Fan-out Pattern¶
Each pipeline filters staging_logs by namespace and pod label:
[transforms.cdnai_cproxy_pods]
type = "filter"
inputs = ["staging_logs"]
condition = '''
.kubernetes.pod_namespace == "cdn" &&
(get(.kubernetes.pod_labels, ["app"]) ?? "") == "cproxy-nuc"
'''
Pipeline Files¶
| File | Source filter | Destination |
|---|---|---|
ai_cproxy.toml |
cproxy-nuc pods |
cdn_ai.cproxy_events in ClickHouse |
ai_cproxy_stats.toml |
cproxy-nuc pods (stats log) |
streamer_analytics in ClickHouse |
ai_elb.toml |
elb/gslb pods | cdn_ai.elb_events in ClickHouse |
ai_cdn_access_cproxy.toml |
cproxy-nuc pods (full access) |
streamer_analytics.cdn_access_logs |
ai_cdn_access_elb.toml |
elb/gslb pods (full access) | streamer_analytics.cdn_access_logs |
ai_streamer.toml |
streamer pods |
streamer_analytics.cdn_access_logs |
ai_security.toml |
fans out from cdnai_full_cproxy_parse and cdnai_full_elb_parse |
security enrichment |
ClickHouse Sink Pattern¶
[sinks.cdn_clickhouse]
type = "clickhouse"
inputs = ["<transform_name>"]
endpoint = "http://clickhouse.analytic-stg.svc.cluster.local:8123"
auth.strategy = "basic"
auth.user = "${CH_USER}"
auth.password = "${CH_PASSWORD}"
database = "cdn_ai"
table = "cproxy_events"
compression = "gzip"
healthcheck.enabled = false
VRL Type Rules (Vector 0.39.0-debian)¶
Vector 0.39.0 enforces strict type checking in VRL. The CDN AI pipelines handle several common cases:
| Situation | Correct VRL | Wrong VRL |
|---|---|---|
Regex capture group (type: string or undefined) |
split!(.field, "/") |
split(.field, "/") |
After replace!() (guaranteed string) |
split(.field, "/") |
split!(.field, "/") |
After to_string() ?? "" (guaranteed string) |
split(to_string(.x) ?? "", "/")[n] |
split(to_string(.x) ?? "", "/")[n] ?? "" (E651) |
| Named regex capture (string type) | split(.name, "/")[0] ?? "" |
— (?? "" handles null index, not an error) |
Key rules:
- split!() is required when the argument type is string or undefined (e.g., .kubernetes.pod_labels.app, regex captures like _req.path)
- split() without ! is correct when the argument is guaranteed string (e.g., after replace!(), or wrapped in to_string() ?? "")
- split(field)[0] ?? "" — the ?? "" handles null index (when the split produces fewer elements), not an error — this is valid
- After to_string(x) ?? "", split is infallible, so adding ?? "" after the index would cause E651 (unnecessary fallback on infallible expression)
Adding a New Service¶
-
Create config files:
-
Add
generatorOptionsand file list toconfigs/newservice/kustomization.yaml:apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization namespace: monitoring generatorOptions: disableNameSuffixHash: true configMapGenerator: - name: vector-config-newservice files: - newservice_main.toml=main.toml - newservice_sinks.toml=sinks.toml - newservice_logs.toml=pipelines/logs.toml -
Add to
configs/kustomization.yaml: -
Add to
patch-vector-volumes.yaml: -
Commit and push — ArgoCD syncs automatically.
-
Verify:
Troubleshooting¶
Vector pod CrashLoopBackOff¶
Common cause: VRL syntax error in transform. Check the error message for line number.
VRL syntax errors¶
Common VRL mistakes with Vector 0.39.0-debian:
# WRONG — split requires ! when field type is "string or undefined"
split(.kubernetes.pod_labels.app, "/")
# CORRECT — use split! for potentially-undefined fields
split!(.kubernetes.pod_labels.app, "/")
# WRONG — E651: unnecessary fallback on infallible expression
# (after to_string() ?? "" the split is already infallible)
split(to_string(.x) ?? "", "/")[0] ?? ""
# CORRECT — no ?? "" needed after to_string()
split(to_string(.x) ?? "", "/")[0]
# CORRECT — ?? "" is valid after split on a guaranteed string (handles null index)
split(.name, "/")[0] ?? ""
ConfigMap not mounting¶
# Check which configmaps are mounted
kubectl describe pod <vector-pod> -n monitoring | grep -A10 "Volumes"
# Check files inside pod
kubectl exec -n monitoring <vector-pod> -- ls /etc/vector/
If configmap is missing — check patch-vector-volumes.yaml includes it and ArgoCD has synced.
Vector not picking up new config after ConfigMap added¶
ArgoCD manages the deployment — kubectl apply changes get reverted. Always commit and push. ArgoCD will sync and restart Vector automatically.
Logs not appearing in VictoriaLogs¶
# Check Vector is receiving events
kubectl logs -n monitoring <vector-pod> --tail=100 | grep -iE "error|warn|<service-name>"
# Check transform is filtering correctly — verify namespace name
kubectl get pods -n <target-namespace>
# Query VictoriaLogs directly
kubectl port-forward -n monitoring svc/victorialogs 9428:9428 &
curl "http://localhost:9428/select/logsql/query?query=namespace:<target-namespace>&start=1h"
CDN AI data not appearing in ClickHouse¶
# Check Vector CDN pipeline
kubectl logs -n monitoring <vector-pod> --tail=200 | grep -iE "error|clickhouse|cdn"
# Verify ClickHouse credentials secret exists
kubectl get secret cdn-ai-ch-write -n monitoring
# Test ClickHouse connectivity from inside the pod
kubectl exec -n monitoring <vector-pod> -- curl -s \
"http://clickhouse.analytic-stg.svc.cluster.local:8123/?query=SELECT+1"
Lines too large error¶
Fix: ensure del(.kubernetes) is in every transform. The full kubernetes metadata object can be hundreds of KB.
Checkpoints causing Vector to skip logs¶
Vector stores read position in /var/lib/vector (hostPath). If logs are missed after restart:
Key Design Decisions¶
| Decision | Reason |
|---|---|
Namespace: monitoring (not observability) |
Consolidated under monitoring namespace alongside VictoriaLogs and Grafana |
| One source per service group | Cleaner separation, easier to debug |
CDN pipelines fan out from staging_logs |
Single kubernetes_logs source for cdn/ai namespace — avoids duplicate log reads |
disableNameSuffixHash: true |
Allows patch to reference configmap by stable name |
del(.kubernetes) in every transform |
Prevents log lines exceeding 262KB VictoriaLogs limit |
| Strategic Merge Patch at root level | Child kustomizations cannot patch parent resources |
elasticsearch sink type for VictoriaLogs |
VictoriaLogs officially supports elasticsearch bulk API — simpler than HTTP jsonline |
clickhouse sink type for CDN AI |
Native ClickHouse sink handles batching and retries correctly |
ch-write-secret.yaml gitignored |
ClickHouse credentials not stored in git; applied manually to cluster |
| Abort non-matching namespaces | Each source collects all pods on node — transform filters to target namespace |