How ovrdoz/k8s-job-pushgateway works
Project Type and Purpose
• This is a Kubernetes-native CronJob utility whose sole purpose is to periodically run a bash script inside a Pod to collect metrics from one or more endpoints and push them to a Prometheus Pushgateway.
• There is no frontend or persistent datastore—this is an operational, scheduled job tool.
File Structure Analysis
• README.md: Describes the “k8s-job-pushgateway” CronJob
• job-script-configmap.yaml: Kubernetes ConfigMap manifest that stores the bash script (e.g. test.sh)
• job-script.yaml: Kubernetes CronJob (or Job) manifest referencing the ConfigMap
• test.sh: Example bash script which, when mounted, executes the actual metric collection and push logic
README Insights
• The CronJob runs at configured intervals
• It can execute any bash script from within Kubernetes (flexible metric collection)
• Targets a Prometheus Pushgateway for metrics ingestion
a. Main Components
• Kubernetes Control Plane (CronJob controller)
• Kubernetes Resources: CronJob, Job, Pod, ConfigMap
• Container running the bash script
• Metrics Collector Script (test.sh)
• Target Endpoints (the services or URLs you scrape)
• Prometheus Pushgateway (external service)
b. Relationships and Data Flows
1. The CronJob resource (job-script.yaml) is scheduled by the Kubernetes control plane.
2. At each interval, CronJob spawns a Job, which in turn creates one or more Pods.
3. The Pod mounts the ConfigMap (job-script-configmap.yaml) as a volume, exposing the bash script.
4. The container in the Pod executes the script (test.sh).
5. The script polls one or more endpoints to collect metrics.
6. The script issues an HTTP “PUT” or “POST” to the Prometheus Pushgateway to push the collected metrics.
7. On completion, the Pod terminates, and logs or status can be collected via kubectl.
c. Architectural Patterns and Principles
• Declarative Infrastructure: All behavior defined via YAML manifests.
• Single-Responsibility Job: The Pod does exactly one thing—run the script and exit.
• Config-as-Code: The script is stored in a ConfigMap for easy updates without rebuilding container images.
• Ephemeral Compute: Pods are short-lived and disposable.
d. Key Technologies and Frameworks
• Kubernetes CronJob API
• Kubernetes ConfigMap for script injection
• Bash script for metric scraping and Pushgateway HTTP API
• Prometheus Pushgateway