kubric
Pythonic Kubernetes DSL — as powerful as Helm, as easy as Pulumi, with the readability of contextlib.
with Deployment("api", replicas=3):
with Container("api", image="myorg/api:v2"):
Port(8080)
EnvVar("DB_HOST", "postgresql")
Resources(cpu="250m", memory="256Mi")
Probe("readiness", http_get={"path": "/health", "port": 8080})
Service(port=8080)
Installation
pip install kubric
Quick Start
Deploy with CLI
# Single chart
tkubric up postgresql
kubric up postgresql --set replicas=3 --set storage=50Gi
kubric up postgresql -f values.yaml
# With stack file
kubric up -f stack.yaml
kubric up -f stack.yaml -f values.prod.yaml
# YAML preview (without apply)
kubric template postgresql --set metrics.enabled=true
Stack file
# stack.yaml
apiVersion: kubric.io/v1
kind: Stack
metadata:
name: my-project
namespace: my-project
components:
- chart: postgresql
name: db
values:
database: myapp
storage: 50Gi
- chart: redis
name: cache
values:
storage: 5Gi
- chart: redmine
name: redmine
values:
postgresql:
enabled: false
name: "${db.host}"
Environment overlay
# values.prod.yaml
components:
db:
values:
replicas: 3
storage: 200Gi
redmine:
values:
replicas: 5
ingress:
enabled: true
host: redmine.example.com
tls: true
kubric up -f stack.yaml -f values.prod.yaml
Three Usage Layers
Layer 1: CLI one-liner
kubric up postgresql --set storage=50Gi
Layer 2: YAML Stack
Declarative component architecture without Python knowledge:
kubric up -f stack.yaml -f values.prod.yaml --set components.db.values.replicas=5
Layer 3: Python Chart Development
Chart authors define reusable components with contextlib:
from contextlib import contextmanager
from kubric.chart.base import Chart
from kubric.core.resources import *
@contextmanager
def my_container(name, image, port=8080):
with Container(name, image=image):
Port(port, name="http")
Probe("readiness", http_get={"path": "/health", "port": port})
yield # can be extended inside the with block
class MyChart(Chart):
name = "myapp"
version = "1.0.0"
def render(self, values):
with Deployment(values["name"], replicas=values.get("replicas", 1)):
with my_container(values["name"], values["image"]):
EnvVar("DB_HOST", values.get("db_host", "localhost"))
Service(port=8080)
Resource Reference
with (context manager) — can have children
with Deployment("api", replicas=3): # Pod spec parent
with Container("api", image="app:v1"): # Leaf parent
...
with Service(type="NodePort"): # Multi-port mode
ServicePort(80, name="http")
ServicePort(443, name="https")
with StatefulSet("db", replicas=3): # StatefulSet
...
with ConfigMap("cfg"): # Key-value store
Data("key", "value")
with Secret("creds"): # Encoded data
Data("password", "s3cret")
with Ingress("ing", host="app.example.com"): # Parametric
IngressRule("/", "web", 80)
IngressRule("/api", "api", 8080)
with CronJob("backup", schedule="0 2 * * *"):
with Container("backup", image="backup:v1"):
...
Leaf — cannot have children, plain call
Port(8080, name="http")
EnvVar("DB_HOST", "localhost")
EnvVar("PASSWORD", secret_ref="my-secret", secret_key="pass")
Resources(cpu="250m", memory="256Mi", limits_cpu="500m", limits_memory="512Mi")
VolumeMount("/data", "my-vol", read_only=True)
Probe("liveness", http_get={"path": "/health", "port": 8080})
Service(port=80) # Simple mode (leaf)
Data("key", "value") # Inside ConfigMap/Secret
IngressRule("/", "web", 80) # Inside Ingress
PersistentVolumeClaim("data", size="50Gi")
EmptyDirVolume("tmp")
ConfigMapVolume("cfg", "my-config")
SecretVolume("certs", "tls-certs")
Chart Development
Each chart is a pip package:
kubric-myapp/
├── pyproject.toml
├── src/kubric_myapp/
│ ├── __init__.py # MyChart class
│ └── defaults.yaml # Default values
# pyproject.toml
[project]
name = "kubric-myapp"
version = "1.0.0"
dependencies = ["kubric>=0.1.0"]
[project.entry-points."kubric.charts"]
myapp = "kubric_myapp:MyChart"
Dependency
# kubric-redmine/pyproject.toml
dependencies = [
"kubric>=0.1.0",
"kubric-postgresql>=16.0.0",
]
from kubric.chart.dependency import ChartDep
class RedmineChart(Chart):
requires = [
ChartDep("postgresql", deploy=True, condition="postgresql.enabled"),
]
CLI Commands
kubric up <chart> [flags] # Deploy
kubric template <chart> [flags] # YAML preview
kubric list # List installed charts
kubric inspect <chart> # Chart details + defaults
Flags
| Flag | Description |
|---|---|
-f <file> |
Values or stack file (multiple allowed) |
--set key=val |
Value override |
-n <namespace> |
Kubernetes namespace |
--create-namespace |
Create namespace if not exists |
--dry-run |
kubectl dry-run |
-o <file> |
Output file (template) |
Value precedence
defaults.yaml → -f values.yaml → -f values.prod.yaml → --set key=val
License
MIT
Metadata
Release files for kubric-cli 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kubric_cli-0.1.1.tar.gz | 49.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kubric_cli-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 86.2 kB
Release files / kubric_cli-0.1.1.tar.gz
| Download URL | kubric_cli-0.1.1.tar.gz |
|---|---|
| Size | 49.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f374c4902a8542be2a8a46fd12a9385e7cfd352ca85b6fc61a676ab1abb53808
|
|
BLAKE2b-256 checksum How to use checksums |
dbaf6945b2c01e3d5e889076ed099f5511edace17aaf62830d0ac824de99ef40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / kubric_cli-0.1.1-py3-none-any.whl
| Download URL | kubric_cli-0.1.1-py3-none-any.whl |
|---|---|
| Size | 36.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6057f04b19c497535194750e28182ff2d8545d011ed637d8cd2ec365b7549d42
|
|
BLAKE2b-256 checksum How to use checksums |
fa105d501eb0c97f520a991739ba83f718b217acc48d153c6ce79c85b3524ec7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|