How renoki-co/php-k8s works
Project type and purpose
• This is an open-source PHP library (“php-k8s”) that implements a Kubernetes client.
• Purpose: allow any PHP application (including Laravel via an adapter) to authenticate to a Kube API server, use the exec/logs/watch APIs, and manage core & CRD resources via PHP objects.
File structure
• Top level:
• composer.json, PHP configuration (phpunit.xml, psalm.xml), CI/deploy configs (.github, .codecov).
• src/ directory – the heart of the client:
– Contracts/: interface definitions for capabilities (Attachable, Executable, Scalable, Watchable, etc.).
– Exceptions/: typed exceptions for errors coming from kubeconfig parsing, HTTP calls, streaming, etc.
– Instances/: building blocks for JSON payload objects (Container, Volume, Probe, ResourceObject, etc.).
– Kinds/: one-per-resource classes mapping to each K8s kind (Pod, Deployment, Service, CronJob, etc.).
– Traits/: mix-ins that implement common behavior (HasName, HasSpec, CanScale, LoadsFromKubeConfig, MakesHttpCalls).
– K8s.php, KubernetesCluster.php: entry points / façade. PhpK8sServiceProvider for Laravel DI. ResourcesList for discovery.
• tests/: comprehensive unit tests against YAML fixtures and fake kubeconfigs.
README for additional insights
• Confirms it’s a generic Kubernetes client (stable, supports v1.24–v1.26).
• Highlights exec API support, CRD extensibility, any authentication mode.
• Mentions optional Laravel package but core is framework-agnostic.