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ΒΆ
Operator InventoryΒΆ
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.