DeployingRelated packages

Deploying

Related packages

The packages around Klass8s - the Kubernetes API as classes, its generator, and the proxies under the events - and how they fit together.

Klass8s is one of four packages, each with one job, all under the MIT License:

PackageJob
klass8s/klass8sthe library and Symfony bundle: manifest classes, configurators, events, console commands
klass8s/k8schemathe Kubernetes API as PHP classes, one release line per Kubernetes version
klass8s/proximityproxy objects: the mechanism under the event system
klass8s/k8schema-generatorthe application that generates k8schema from the Kubernetes API's schema

The sources are in the klass8s organisation on GitHub. A project needs the first; Composer brings the second and the third with it.

k8schema

Every Kubernetes API object as a PHP class: K8Schema\Api\Apps\V1\Deployment, K8Schema\Api\Core\V1\ConfigMap, the ObjectMeta family, and collection types (StringMap, StringList, StringOrFloatMap) where YAML has loose maps. The classes have fluent setters, API_VERSION and KIND constants, and a <Type>List for every resource.

The versions follow Kubernetes: one release line per Kubernetes minor version, tagged v<minor>.<patch> (v1.35.8 is for Kubernetes 1.35). So the constraint in composer.json states the Kubernetes API a project targets:

{ "require": { "klass8s/k8schema": "~1.35.8" } }

Upgrading the cluster is a constraint change followed by whatever the type checker reports. Use a tilde, never a caret: a caret would let a routine composer update move the project to another Kubernetes API. Klass8s accepts the lines for Kubernetes 1.34 to 1.37.

k8schema-generator

The command-line application that writes k8schema: schema:fetch downloads the JSON schema of a Kubernetes release's API, generate writes one class per API object and nested type under a namespace prefix, and schema:versions lists the newest patch release upstream for each recent minor. You need it only to generate the classes yourself, for a Kubernetes version k8schema does not have yet or under another namespace.

proximity

A proxy library: it generates a subclass of an object at run time and routes every method call through interceptors that run before the method (and may skip it) or after it (and may replace the result). Klass8s turns those interceptors into Symfony events, and the event system follows. Two consequences you will meet: manifest and container classes must not be final, since a proxy is a subclass; and the class of a manifest is read with $manifest::className(), since $manifest::class is the proxy's.

How they meet

# a project, with Klass8s and the Kubernetes version you target
composer create-project symfony/skeleton k8s && cd k8s
composer require klass8s/klass8s klass8s/k8schema:~1.35.8

# manifests as classes, then: what would change, and apply it
bin/console k8s:render:apps | kubectl diff -f -
bin/console k8s:render:apps | kubectl apply -f -

k8schema knows Kubernetes, its generator keeps it current, Klass8s knows your resources, and your base classes and subscribers know your conventions.