Skip to main content
In this tutorial, you’ll learn how to:
  1. Build a Docker image and push it to Docker Hub.
  2. Scan Kubernetes manifests with OPA and Kubescape.
  3. Perform image vulnerability scans using Trivy.
  4. Upgrade a vulnerable dependency (Tomcat) and verify the fix.
  5. Deploy the hardened image to a Kubernetes cluster.
This end-to-end demo uses Jenkins, Docker, OPA, Kubescape, and Trivy to enforce security gates in your CI/CD pipeline.

1. Jenkins Pipeline Configuration

Define your pipeline with a reusable imageName environment variable:

1.1 Docker Build & Push


1.2 Kubernetes Manifest Scans


1.3 Trivy Scan Stage


2. Trivy Scan Script

Create trivy-k8s-scan.sh at the root of your repo:
  • --light mode skips non-OS packages for faster scans.
  • Cache volume is mapped to reuse vulnerability data between runs.

3. Initial Trivy Scan Results

Running the scan for the first time may reveal CVEs in embedded libraries:
The image shows a Jenkins dashboard displaying dependency-check results, listing vulnerabilities in various files with their severity levels and associated weaknesses.
Upon seeing these CVEs, we’ll upgrade Tomcat in our pom.xml.

4. Update Tomcat Version in pom.xml

Open your Maven POM in Spring Tool Suite and override the tomcat.version property:
The image shows a software development environment with a code editor displaying a Maven POM file and a terminal window open below. The editor is part of the Spring Tool Suite, and the file lists various dependencies and versions.
Commit and push your changes. Jenkins will automatically trigger a new pipeline run.

5. Post-Upgrade Scan

After the Tomcat upgrade, rerun Trivy to confirm no vulnerabilities remain:
With the image verified as clean, it’s now safe to proceed to the Kubernetes Deployment stage.
That’s it for this lesson—your CI/CD pipeline now enforces both manifest and image security checks before deploying to production.

Watch Video

Practice Lab