Skip to main content
In this lesson, we’ll walk through scanning Kubernetes resource definitions using Kubesec. Kubesec helps you enforce cluster security best practices with a simple CLI, Docker image, or HTTP API.

Table of Contents

  1. Sample Pod Specification
  2. Scanning with Kubesec
    • CLI
    • Docker Image
    • HTTP API
  3. Bash Wrapper for HTTP API
  4. Jenkins Pipeline Integration
  5. Improving Your Security Score
  6. References

Sample Pod Specification

Here’s a minimal Pod manifest that enables a read-only root filesystem:

Scanning with Kubesec

You can scan your YAML definitions in three ways:

1. CLI

Install the kubesec binary, then run:
Sample JSON output:

Bash Wrapper for HTTP API

Create a shell function to simplify HTTP scans:
Call it with:

Jenkins Pipeline Integration

Here’s a sample Jenkinsfile that builds a Docker image, pushes it, then runs parallel scans with Conftest and Kubesec:

kubesec-scan.sh

Adjust the threshold (5 points) to match your team’s security policy.

Improving Your Security Score

Based on the advice from Kubesec, let’s update our Deployment to include:
  • A dedicated service account
  • AppArmor & Seccomp annotations
  • CPU & memory limits
  • Immutable root filesystem
  • Non-root user execution
Re-running the scan:

References

Watch Video