How mittwald/kube-httpcache works
Project type and purpose
• This is a Kubernetes “controller” / caching side-car component written in Go that watches Kubernetes Services and Endpoints, generates Varnish VCL on‐the‐fly, and reloads a Varnish cache cluster.
• It also embeds a “signaller” HTTP sub-service for broadcasting PURGE/BAN requests to all Varnish nodes.
• It ships with a Helm chart, Docker images, and standard Kubernetes manifests (RBAC, StatefulSet, Service, ConfigMap, Secret).
File structure
• Top-level packaging & CI:
• build/ci – GoReleaser configurations
• build/package/docker – Dockerfiles for building the image
• chart/ – Helm chart (Chart.yaml, templates/, values.yaml)
• deploy/kubernetes/ – standalone RBAC YAML
• Core application code (cmd/ & pkg/):
• cmd/kube-httpcache – entry point (main.go) and flags.go
• pkg/watcher – watches Kubernetes Endpoints & ConfigMap watches
• pkg/controller – orchestrates template rendering
• pkg/signaller – HTTP server for PURGE/BAN broadcasts
• Tests & assets:
• test/ – example YAMLs for end-to-end tests
• assets/varnish.repo – packaging resource
• GitHub workflows, CONTRIBUTING, LICENSE, SECURITY, README describe build/test/release and developer guidance.
1. Kubernetes API Server (control plane)
2. kube-httpcache Controller (Pod, single container binary)
• Watcher module
• Controller module (VCL template renderer)
• Signaller HTTP server
3. ConfigMap (VCL template) + Secret (Varnish admin secret)
4. Varnish Cache instances (StatefulSet)
5. Application Service & Pods (backend)
6. Ingress (or Ingress Controller)
7. Client (end user or external service making HTTP requests)
• Client → Ingress → Service “cache-service” → Varnish Pods (HTTP traffic)
• Controller Pod → (watches) Kubernetes API Server for:
• Frontend Service Endpoints
• Backend Service Endpoints
• ConfigMap changes
• Controller module → (renders) VCL template from ConfigMap + endpoint data → loads into Varnish via admin port
• Signaller HTTP server → receives PURGE/BAN requests → fetches current Varnish Pod IPs → issues HTTP PURGE/BAN to each pod
c. Architectural patterns & design principles:
• Operator-style pattern: separation of control plane (watchers + template rendering) vs. data plane (Varnish cache pods)
• Modular Go packages: watcher, controller, signaller
• StatefulSet for stable network identities (required for self-routed Varnish cluster)
• ConfigMap driven configuration for declarative VCL
• Helm chart for templated deployment
d. Key technologies/libraries:
• Go & client-go (Kubernetes API)
• Varnish Cache (vcl 4.0)
• Go templates for VCL
• Docker & GoReleaser for image builds
• Helm for deployment
• Kubernetes primitives: StatefulSet, Service, ConfigMap, Secret, RBAC, Ingress