Skip to main content

Pythonic Kubernetes DSL — as powerful as Helm, as easy as Pulumi, with the readability of contextlib.

Project description

kubric

Pythonic Kubernetes DSL — contextlib ile Helm kadar güçlü, Pulumi kadar kolay.

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)

Kurulum

pip install kubric

Hızlı Başlangıç

CLI ile deploy

# Tek chart
kubric up postgresql
kubric up postgresql --set replicas=3 --set storage=50Gi
kubric up postgresql -f values.yaml

# Stack dosyası ile
kubric up -f stack.yaml
kubric up -f stack.yaml -f values.prod.yaml

# YAML preview (apply etmeden)
kubric template postgresql --set metrics.enabled=true

Stack dosyası

# 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

Üç Kullanım Katmanı

Katman 1: CLI one-liner

kubric up postgresql --set storage=50Gi

Katman 2: YAML Stack

Python bilmeden deklaratif component mimarisi:

kubric up -f stack.yaml -f values.prod.yaml --set components.db.values.replicas=5

Katman 3: Python Chart geliştirme

Chart yazarları contextlib ile reusable component'ler tanımlar:

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  # with bloğu içinde extend edilebilir

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 Referansı

with (context manager) — children alabilir

with Deployment("api", replicas=3):          # Pod spec parent
    with Container("api", image="app:v1"):   # Leaf parent
        ...
    with Service(type="NodePort"):           # Multi-port mod
        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"): # Parametrik
    IngressRule("/", "web", 80)
    IngressRule("/api", "api", 8080)

with CronJob("backup", schedule="0 2 * * *"):
    with Container("backup", image="backup:v1"):
        ...

Leaf — children almaz, düz çağrı

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)                              # Basit mod (leaf)
Data("key", "value")                          # ConfigMap/Secret içinde
IngressRule("/", "web", 80)                   # Ingress içinde
PersistentVolumeClaim("data", size="50Gi")
EmptyDirVolume("tmp")
ConfigMapVolume("cfg", "my-config")
SecretVolume("certs", "tls-certs")

Chart Geliştirme

Her chart bir pip paketidir:

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 Komutları

kubric up <chart> [flags]       # Deploy
kubric template <chart> [flags] # YAML preview
kubric list                     # Kurulu chart'lar
kubric inspect <chart>          # Chart detayları + defaults

Flags

Flag Açıklama
-f <file> Values veya stack dosyası (birden fazla)
--set key=val Değer override
-n <namespace> Kubernetes namespace
--create-namespace Namespace yoksa oluştur
--dry-run kubectl dry-run
-o <file> Çıktı dosyası (template)

Değer önceliği

defaults.yaml → -f values.yaml → -f values.prod.yaml → --set key=val

Lisans

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kubric_cli-0.1.0.tar.gz (50.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kubric_cli-0.1.0-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

Details for the file kubric_cli-0.1.0.tar.gz.

File metadata

  • Download URL: kubric_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 50.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for kubric_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5fb9c6f367f28e3f6ad748645cc4571f0cd7a6f8e3b507b6111a04245c959cef
MD5 cd164109e845994c2dd391a81f566852
BLAKE2b-256 a160954928f92c129c0bd4bc936f459393e0d6e2685651cae13e20e0005d7ece

See more details on using hashes here.

File details

Details for the file kubric_cli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kubric_cli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 37.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for kubric_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc8e34d24216c6e4d65aefa86db34a065fc33c51c9e681cf3e6ae047feb82ec6
MD5 e995fe291c2dc24d7c04a87b089feb58
BLAKE2b-256 4b8d34f6d641b7b1730f2967b04a17ad8388506c00ce28d4d4625c734a0384e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page