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."

All Security Tools questions Roadmap: Trivy — image, file system & IaC scanning

More on Trivy