Trivy Operator in Kubernetes: continuous vulnerability scanning
Published: 2026-02-26
trivy image in CI catches vulnerabilities at build time. But what about images that already run in production and were clean last month? Trivy Operator scans every workload in the cluster all the time. It stores the results as Kubernetes resources and exports Prometheus metrics, so you can alert on them.
Install via Helm / FluxCD
yamlapiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: trivy-operator
spec:
interval: 1h
chart:
spec:
chart: trivy-operator
version: "0.x"
sourceRef:
kind: HelmRepository
name: aquasecurity
namespace: flux-system
values:
operator:
vulnerabilityScannerEnabled: true
configAuditScannerEnabled: true
rbacAssessmentScannerEnabled: true
infraAssessmentScannerEnabled: true
metricsVulnIdEnabled: true
scanJobsConcurrentLimit: 2
trivy:
ignoreUnfixed: true
mode: Standalone
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
serviceMonitor:
enabled: true
labels:
release: kube-prom-stack
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 1000m
memory: 2048Mi
ignoreUnfixed: true matters a lot in practice. If a vulnerability has no fix, there is nothing you can do about it. Without this flag, dashboards fill up with thousands of such CVEs, and soon nobody looks at them.
scanJobsConcurrentLimit: 2 limits how many scans run in parallel. Without a limit, the operator starts a job for every workload at the same time. On the first install, this can overload the nodes.
With mode: Standalone, Trivy downloads its vulnerability database inside the scan job pod and does not use a central Trivy server. For air-gapped environments, use ClientServer mode and fill the Trivy server cache in advance.
What gets scanned
The operator runs scan jobs for these reports:
- VulnerabilityReport: CVEs in container images (one report for each container in a pod)
- ConfigAuditReport: insecure Kubernetes settings (missing
securityContext, privileged containers, etc.) - RbacAssessmentReport: RBAC roles with too many permissions
- InfraAssessmentReport: hardening checks for the control plane
To see them:
bashkubectl get vulnerabilityreport -A
kubectl get configauditreport -A
kubectl get rbacassessmentreport -A
kubectl get infraassessmentreport -A
The results are stored as Kubernetes custom resources in the same namespace as the workload. They survive pod restarts. The operator updates them on every rescan (by default, every 24 hours).
Reading a VulnerabilityReport
bash# Summary
kubectl get vulnerabilityreport -n app my-app-deployment-my-container \
-o jsonpath='{.report.summary}'
Output:
json{"criticalCount":0,"highCount":3,"lowCount":47,"mediumCount":12,"noneCount":0,"unknownCount":2}
Details for HIGH CVEs:
bashkubectl get vulnerabilityreport -n app my-app-deployment-my-container \
-o json | jq '.report.vulnerabilities[] | select(.severity=="HIGH") | {id: .vulnerabilityID, pkg: .resource, fixed: .fixedVersion}'
Prometheus metrics and alerting
With metricsVulnIdEnabled: true, the operator exports a metric for each CVE:
promql# Count of CRITICAL CVEs across all workloads
sum(trivy_image_vulnerabilities{severity="CRITICAL"}) by (namespace, resource_name)
Alerts for new HIGH and CRITICAL CVEs:
yaml- alert: TrivyCriticalVulnerabilities
expr: sum(trivy_image_vulnerabilities{severity="CRITICAL"}) by (namespace, resource_name) > 0
for: 10m
labels:
severity: high
annotations:
summary: "{{ $labels.resource_name }} in {{ $labels.namespace }} has {{ $value }} CRITICAL CVEs"
description: "Update the base image or add .trivyignore for accepted risks"
- alert: TrivyConfigAuditFailed
expr: trivy_resource_configaudits{severity="CRITICAL"} > 0
for: 5m
labels:
severity: warning
annotations:
summary: "Critical config audit finding in {{ $labels.resource_name }}"
Grafana: import the dashboard with ID 17813 (Trivy Operator - Vulnerabilities Dashboard).
CI scanning vs Trivy Operator
CI scanning finds problems before they reach production. The operator finds problems that appear after the deploy:
- A new CVE is found in the base image OS, and nobody rebuilt the image
- A dependency in a running image was just added to NVD
- Someone deployed a new workload without CI (a hotfix, a manual
kubectl apply)
One does not replace the other. Run both.
Trivy in GitLab CI
yamltrivy-scan:
image: aquasec/trivy:latest
script:
- trivy image
--format json
--output trivy-report.json
--severity HIGH,CRITICAL
--exit-code 1
registry.example.com/myapp:$CI_COMMIT_SHORT_SHA
artifacts:
reports:
container_scanning: trivy-report.json
when: always
--exit-code 1 fails the pipeline if Trivy finds HIGH or CRITICAL issues. --format json lets GitLab read the report and show the vulnerabilities in the Security tab of the merge request.
To hide a known false positive, create a .trivyignore file:
# Known false-positive, no fix available as of 2026-02-26
CVE-2023-12345
Commit it next to the Dockerfile. Then everyone can see what is ignored, and it is easy to check during an audit.
Excluding namespaces
Skip system namespaces:
yamlvalues:
operator:
excludeNamespaces: "kube-system,flux-system,cert-manager"
This means less noise and fewer scan jobs for infrastructure components that you don't control.
Trivy Operator + OPA Gatekeeper
You can combine Trivy Operator with OPA Gatekeeper to enforce a rule like "no pods with CRITICAL CVEs in production".
yaml# OPA ConstraintTemplate checks VulnerabilityReport before admission
# (requires creating a custom constraint)
Admission webhook policies can use Trivy Operator reports and block vulnerable images before they are deployed.