Skip to content

K8s DataModelΒΆ

Version 0.4.0

A comprehensive CLI tool to model and analyze Kubernetes cluster data including CRDs, operators, and OLM components.

FeaturesΒΆ

  • CRD Inventory: List and analyze all Custom Resource Definitions in your cluster
  • Operator Detection: Automatically identify and inventory operators (deployments, statefulsets)
  • Framework Detection: Detect operator frameworks (OLM, Helm, Manual)
  • Database Storage: Persistent SQLite storage for historical tracking and snapshots
  • Snapshot Management: Store, list, view, and compare inventory snapshots over time
  • Multiple Output Formats: Support for table, JSON, YAML, and rich terminal output
  • Filtering & Search: Filter resources by namespace, group, framework, and more
  • Export Capabilities: Export complete inventories for analysis and reporting
  • Cluster Analysis: Comprehensive cluster summaries and statistics

ArchitectureΒΆ

System OverviewΒΆ

graph TB
    subgraph "User Interface"
        CLI["πŸ–₯️ CLI Commands"]
        CONFIG["βš™οΈ Configuration"]
    end

    subgraph "Core Engine"
        MAIN["🎯 Main Controller"]
        CLIENT["πŸ”Œ K8s Client"]

        subgraph "Inventory Modules"
            CRD_INV["πŸ“‹ CRD Inventory"]
            OP_INV["πŸ€– Operator Inventory"]
            CLUSTER["πŸ—οΈ Cluster Operations"]
        end

        subgraph "Analysis Engine"
            DETECT["πŸ” Framework Detection"]
            CLASSIFY["πŸ“Š Classification"]
            HEALTH["πŸ’š Health Assessment"]
        end
    end

    subgraph "Output Layer"
        FORMATTER["🎨 Formatters"]

        subgraph "Output Formats"
            TABLE["πŸ“‹ Table"]
            JSON["πŸ“„ JSON"]
            YAML["πŸ“ YAML"]
            RICH["🌈 Rich"]
        end
    end

    subgraph "Storage Layer"
        DATABASE["πŸ’Ύ SQLite Database"]

        subgraph "Database Operations"
            SNAPSHOTS["πŸ“Έ Snapshots"]
            HISTORY["πŸ“Š Historical Data"]
            EXPORT_DB["πŸ“€ Export"]
        end
    end

    subgraph "Kubernetes Cluster"
        API["⚑ API Server"]

        subgraph "Resources"
            CRDS["πŸ“¦ CRDs"]
            DEPLOYS["πŸš€ Deployments"]
            PODS["🐳 Pods"]
            SVC["🌐 Services"]
        end
    end

    CLI --> CONFIG
    CLI --> MAIN
    MAIN --> CLIENT
    CLIENT --> CRD_INV
    CLIENT --> OP_INV
    CLIENT --> CLUSTER

    CRD_INV --> DETECT
    OP_INV --> DETECT
    OP_INV --> CLASSIFY
    OP_INV --> HEALTH

    CRD_INV --> FORMATTER
    OP_INV --> FORMATTER
    CLUSTER --> FORMATTER

    CRD_INV --> DATABASE
    OP_INV --> DATABASE
    CLUSTER --> DATABASE

    DATABASE --> SNAPSHOTS
    DATABASE --> HISTORY
    DATABASE --> EXPORT_DB

    FORMATTER --> TABLE
    FORMATTER --> JSON
    FORMATTER --> YAML
    FORMATTER --> RICH

    CLIENT --> API
    API --> CRDS
    API --> DEPLOYS
    API --> PODS
    API --> SVC

Data Flow ArchitectureΒΆ

flowchart LR
    subgraph "Input"
        USER["πŸ‘€ User Command"]
        KUBECONFIG["πŸ” Kubeconfig"]
    end

    subgraph "Processing Pipeline"
        AUTH["πŸ”“ Authentication"]
        CONNECT["πŸ”— Connection"]
        DISCOVER["πŸ” Discovery"]
        ANALYZE["πŸ“Š Analysis"]
        FORMAT["🎨 Formatting"]
    end

    subgraph "Output"
        DISPLAY["πŸ’» Display"]
        EXPORT["πŸ“ Export"]
    end

    USER --> AUTH
    KUBECONFIG --> AUTH
    AUTH --> CONNECT
    CONNECT --> DISCOVER
    DISCOVER --> ANALYZE
    ANALYZE --> FORMAT
    FORMAT --> DISPLAY
    FORMAT --> EXPORT

    style USER fill:#e1f5fe
    style DISPLAY fill:#e8f5e8
    style EXPORT fill:#e8f5e8

Quick StartΒΆ

InstallationΒΆ

# Install with pipx (recommended)
pipx install k8s-datamodel

# Or install with pip
pip install k8s-datamodel

Basic UsageΒΆ

# List all CRDs in the cluster
k8s-datamodel crd list

# List all operators
k8s-datamodel operators list

# Get cluster summary
k8s-datamodel cluster summary

# Export complete inventory
k8s-datamodel cluster export --file inventory.json

# Store inventory snapshot in database
k8s-datamodel database store --notes "Production cluster snapshot"

# List stored snapshots
k8s-datamodel database list

Common WorkflowsΒΆ

Cluster Analysis WorkflowΒΆ

flowchart TD
    START(["πŸš€ Start Analysis"]) --> CONNECT{"πŸ”— Test Connection"}
    CONNECT -->|"βœ… Success"| INFO["ℹ️ Get Cluster Info"]
    CONNECT -->|"❌ Failed"| ERROR1["⚠️ Connection Error"]

    INFO --> SUMMARY["πŸ“Š Generate Summary"]
    SUMMARY --> CRD_LIST["πŸ“‹ List CRDs"]
    CRD_LIST --> OP_LIST["πŸ€– List Operators"]
    OP_LIST --> ANALYZE["πŸ” Analyze Relationships"]
    ANALYZE --> EXPORT["πŸ“€ Export Results"]
    EXPORT --> END(["βœ… Analysis Complete")

    ERROR1 --> END

    style START fill:#e3f2fd
    style END fill:#e8f5e8
    style ERROR1 fill:#ffebee

Operator Discovery ProcessΒΆ

sequenceDiagram
    participant CLI as πŸ–₯️ CLI
    participant Client as πŸ”Œ K8s Client
    participant API as ⚑ API Server
    participant Analyzer as πŸ” Analyzer

    CLI->>Client: List operators request
    Client->>API: Get deployments
    API-->>Client: Deployment list

    Client->>API: Get statefulsets
    API-->>Client: StatefulSet list

    Client->>Analyzer: Analyze workloads

    loop For each workload
        Analyzer->>Analyzer: Check image patterns
        Analyzer->>Analyzer: Analyze labels
        Analyzer->>Analyzer: Check CRD ownership
        Analyzer->>Analyzer: Assess framework
    end

    Analyzer-->>Client: Operator classification
    Client-->>CLI: Formatted results

    Note over CLI,Analyzer: Parallel processing for performance

Database Storage and Historical TrackingΒΆ

flowchart TD
    subgraph "Data Collection"
        LIVE_CRDS["πŸ“¦ Live CRDs"]
        LIVE_OPS["πŸ€– Live Operators"]
        LIVE_CLUSTER["πŸ—οΈ Live Cluster"]
    end

    subgraph "Database Storage"
        SNAPSHOT["πŸ“Έ Create Snapshot"]
        DB[("πŸ’Ύ SQLite Database")]

        subgraph "Stored Data"
            SNAP_META["πŸ“‹ Snapshot Metadata"]
            HIST_CRDS["πŸ“¦ Historical CRDs"]
            HIST_OPS["πŸ€– Historical Operators"]
            HIST_CSVS["πŸ“œ Historical CSVs"]
        end
    end

    subgraph "Database Operations"
        LIST["πŸ“ List Snapshots"]
        COMPARE["πŸ” Compare"]
        EXPORT["πŸ“€ Export"]
        CLEANUP["🧹 Cleanup"]
    end

    subgraph "Analysis & Reporting"
        TRENDS["πŸ“ˆ Trend Analysis"]
        COMPLIANCE["πŸ›‘οΈ Compliance Reports"]
        AUDIT["πŸ“Š Audit Trails"]
        ALERTS["🚨 Change Alerts"]
    end

    LIVE_CRDS --> SNAPSHOT
    LIVE_OPS --> SNAPSHOT
    LIVE_CLUSTER --> SNAPSHOT

    SNAPSHOT --> DB
    DB --> SNAP_META
    DB --> HIST_CRDS
    DB --> HIST_OPS
    DB --> HIST_CSVS

    DB --> LIST
    DB --> COMPARE
    DB --> EXPORT
    DB --> CLEANUP

    LIST --> TRENDS
    COMPARE --> COMPLIANCE
    EXPORT --> AUDIT
    COMPARE --> ALERTS

    style DB fill:#e1f5fe
    style SNAPSHOT fill:#e8f5e8
    style TRENDS fill:#fff3e0

Export and Integration FlowΒΆ

graph LR
    subgraph "Data Sources"
        CRDS["πŸ“¦ CRDs"]
        OPS["πŸ€– Operators"]
        CLUSTER["πŸ—οΈ Cluster Info"]
        DATABASE_SRC["πŸ’Ύ Database Snapshots"]
    end

    subgraph "Processing"
        COLLECT["πŸ“₯ Collect Data"]
        ENRICH["✨ Enrich Metadata"]
        VALIDATE["βœ… Validate"]
    end

    subgraph "Output Formats"
        JSON_OUT["πŸ“„ JSON"]
        YAML_OUT["πŸ“ YAML"]
        CSV_OUT["πŸ“Š CSV"]
    end

    subgraph "Integration Targets"
        MONITORING["πŸ“ˆ Monitoring"]
        CICD["πŸ”„ CI/CD"]
        DOCS["πŸ“š Documentation"]
        COMPLIANCE["πŸ›‘οΈ Compliance"]
    end

    CRDS --> COLLECT
    OPS --> COLLECT
    CLUSTER --> COLLECT
    DATABASE_SRC --> COLLECT

    COLLECT --> ENRICH
    ENRICH --> VALIDATE

    VALIDATE --> JSON_OUT
    VALIDATE --> YAML_OUT
    VALIDATE --> CSV_OUT

    JSON_OUT --> MONITORING
    JSON_OUT --> CICD
    YAML_OUT --> DOCS
    JSON_OUT --> COMPLIANCE

Use CasesΒΆ

  • Cluster Auditing: Understand what custom resources and operators are deployed
  • Historical Tracking: Store and compare cluster inventories over time using database snapshots
  • Migration Planning: Inventory resources before cluster migrations and track changes
  • Security Assessment: Identify all operators and their frameworks with audit trails
  • Compliance Reporting: Generate historical compliance reports from stored snapshots
  • Change Management: Track and alert on changes to critical cluster resources
  • Documentation: Generate cluster documentation automatically with historical context
  • Monitoring: Track changes in CRDs and operators over time with persistent storage
  • Trend Analysis: Analyze resource growth and changes across multiple time periods

πŸ“š Comprehensive ExamplesΒΆ

Explore our extensive collection of real-world examples and workflows:

  • Database Workflows - Complete database operations, CI/CD integration, and monitoring
  • OLM Management - Operator Lifecycle Manager operations, RBAC analysis, and troubleshooting
  • Security & Compliance - Enterprise security baselines, compliance reporting (SOC 2, PCI DSS), and automated monitoring

Each section includes ready-to-use scripts, detailed explanations, and enterprise-grade best practices.

Output ExamplesΒΆ

CRD ListingΒΆ

$ k8s-datamodel crd list --output rich

Operator InventoryΒΆ

$ k8s-datamodel operators list --framework OLM

Cluster SummaryΒΆ

$ k8s-datamodel cluster summary

RequirementsΒΆ

  • Python 3.10+
  • Access to a Kubernetes cluster
  • Valid kubeconfig file

LicenseΒΆ

This project is licensed under the MIT License - see the LICENSE file for details.

ContributingΒΆ

Contributions are welcome! Please see Contributing for guidelines.