# ovrdoz/k8s-job-pushgateway architecture

> Architecture diagram of the GitHub repository ovrdoz/k8s-job-pushgateway, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ovrdoz/k8s-job-pushgateway
- Repository: https://github.com/ovrdoz/k8s-job-pushgateway

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "K8s Cluster"
        CronJob["CronJob\n(schedule: 0 */1 * * *)"]:::k8s
        Job["Job"]:::k8s
        Pod["Pod"]:::k8s
        ConfigMap["ConfigMap\n(script volume)"]:::config
        Container["Container"]:::k8s
        Script["test.sh"]:::config
    end

    README["README.md"]:::docs
    Endpoints["Target Endpoints"]:::external
    Pushgateway["Prometheus Pushgateway"]:::external

    README -->|"defines CronJob"| CronJob
    CronJob -->|"schedule: 0 */1 * * *"| Job
    Job -->|"creates Pod"| Pod
    ConfigMap -.->|"mount at /scripts/test.sh"| Pod
    Pod -->|"runs container"| Container
    Container -->|"executes script"| Script
    Script -->|"scrape metrics"| Endpoints
    Script -->|"push metrics (HTTP PUT/POST)"| Pushgateway

    click CronJob "https://github.com/ovrdoz/k8s-job-pushgateway/blob/main/job-script.yaml"
    click ConfigMap "https://github.com/ovrdoz/k8s-job-pushgateway/blob/main/job-script-configmap.yaml"
    click Script "https://github.com/ovrdoz/k8s-job-pushgateway/blob/main/test.sh"
    click README "https://github.com/ovrdoz/k8s-job-pushgateway/blob/main/README.md"

    classDef k8s fill:#B3CDE3,stroke:#333,stroke-width:1px
    classDef external fill:#C7E9C0,stroke:#333,stroke-width:1px
    classDef config fill:#FEDD9E,stroke:#333,stroke-width:1px
    classDef docs fill:#FFCCCB,stroke:#333,stroke-width:1px
```
