How megandil/k8s-kyverno works
Project type and purpose
• This is an infrastructure-as-code / DevOps demonstration project showing how to implement and operate the Kyverno policy engine on a lightweight Kubernetes cluster (K3s).
• It includes:
• Sample Kyverno policies (validation, mutation, generation) and test manifests in /pruebas.
• A GitOps delivery pipeline using ArgoCD to deploy Kyverno, Policy Reporter UI, and a sample “Temperaturas” app.
• A standalone JSON-to-PDF export pipeline (/json2pdf) that fetches Policy Reporter UI logs via its API, transforms them with Python + Asciidoc, and generates a PDF.
Analysis of file structure
• Top level:
• README.md – detailed architecture and workflow description.
• json2pdf/ – shell script (json2pdf.sh), Asciidoc template (logs.adoc), Python processor (py/tratar-json.py), and sample output PDF.
• pruebas/ – sample resource YAMLs for validation (validacion), mutation (mutacion), and generation (generacion) policies.
• No traditional “src” folder for an application—this is primarily a configuration and automation project.
Insights from the README
• Core components:
• K3s Kubernetes cluster
• Kyverno (as an admission controller via webhook)
• Policy Reporter UI (ingested via Helm into its own namespace)
• ArgoCD (four GitOps “Apps”: Control-apps, Kyverno-app, policy-reporter-ui-app, temp-app)
• Temperaturas application (frontend + backend containers)
• External Git repository (source of truth)
• JSON-to-PDF pipeline that calls Policy Reporter UI’s API
a. Main components
• External Git server (GitHub repo with manifests & policies)
• ArgoCD server & controller (deployed in cluster)
• K3s control plane (API server, etcd)
• Kyverno admission controller (webhook deployment)
• Policy Reporter UI service + API (with its own ingress)
• Sample app “Temperaturas” (frontend and backend Deployments + Services)
• Namespaces (e.g., kyverno, policy-reporter, temperaturas)
• JSON-to-PDF export pipeline (runs externally or via a dedicated Pod/Job)
• Ingress resources (for Policy Reporter UI and Temperaturas UI)
b. Relationships and interactions
1. Developer pushes YAMLs & policies to Git → ArgoCD detects changes (GitOps sync).
2. ArgoCD applies manifests in correct order (Sync-waves):
• Control-apps → Kyverno-app → Policy-reporter-ui-app → create temp-app’s namespace → temp-app.
3. Kubernetes API Server intercepts resource create/update requests → forwards to Kyverno webhook → Kyverno enforces or audits (validation/mutation/generation).
4. Kyverno writes results into PolicyReport CRDs.
5. Policy Reporter UI queries PolicyReport CRDs via Kubernetes API to build dashboard & logs.
6. JSON-to-PDF script calls Policy Reporter UI REST API → obtains logs in JSON → Python processes JSON → Asciidoc template → asciidoctor-pdf → output PDF.
c. Architectural patterns & design principles
• Admission-control via webhooks (separation of control plane & policy engine)
• GitOps (ArgoCD) for declarative, versioned deployments
• Micro-services layering: policy engine, reporting UI, sample application
• Automation pipeline (shell + Python + Asciidoc) for documentation generation
d. Key technologies/frameworks
• K3s (lightweight Kubernetes)
• Kyverno (Kubernetes-native policy engine)
• ArgoCD (GitOps controller)
• Policy Reporter UI (React + API server)
• Bash, Python 3.9, Asciidoc, Asciidoctor-pdf