How do you scan a Kubernetes cluster with Trivy from the command line?
IntermediateHands-onTrivy
Answer
Short answer
Use trivy k8s with your current kubeconfig. It scans workloads' images for vulnerabilities, resources for misconfigurations, RBAC and secrets, and gives a summary or detailed report — a quick security health check of a cluster.
Commands
trivy k8s --report summary # overview of the whole cluster
trivy k8s --include-namespaces shop --report all # details for one namespace
trivy k8s --scanners misconfig,rbac --report summary
trivy k8s --compliance k8s-cis-1.23 --report summary # CIS benchmark checks
Example summary
Workload Assessment
┌───────────┬──────────────────────┬───────────────────┬────────────────────┐
│ Namespace │ Resource │ Vulnerabilities │ Misconfigurations │
│ │ │ C H M L │ C H M L │
├───────────┼──────────────────────┼───────────────────┼────────────────────┤
│ shop │ Deployment/orders │ 1 6 21 9 │ 2 4 1 │
│ shop │ Deployment/web │ 2 8 3 │ 1 3 │
What to say in the interview
"trivy k8s uses the kubeconfig to scan workloads, configs, RBAC and secrets, with summary reports and compliance profiles like CIS. It's great for a one-off audit; for continuous coverage we run the Trivy Operator."
More on Trivy
What is Trivy and how do you scan an image with it?BeginnerWhat is a CVE and what do severity levels mean?BeginnerWhat is Trivy and what can it scan?BeginnerHow do you scan a Docker image with Trivy?BeginnerHow do you fail a CI build when Trivy finds HIGH or CRITICAL vulnerabilities?BeginnerWhat does trivy fs do?Beginner