Skip to content

PHP K8sPHP Client for Kubernetes

Control your Kubernetes clusters with this modern PHP-based client. Supports exec API, CRDs, and any form of authentication.

Quick Example

php
<?php

use RenokiCo\PhpK8s\K8s;
use RenokiCo\PhpK8s\KubernetesCluster;

// Connect to your cluster
$cluster = new KubernetesCluster('https://127.0.0.1:8443');

// Create a pod
$pod = K8s::pod($cluster)
    ->setName('my-app')
    ->setNamespace('default')
    ->setContainers([
        K8s::container()
            ->setName('app')
            ->setImage('nginx:latest')
            ->setPorts([
                K8s::containerPort()->setContainerPort(80)
            ])
    ])
    ->create();

echo $pod->getName(); // my-app
echo $pod->getPodPhase(); // PodPhase::RUNNING

Fork Information

Note: This is a maintained fork of renoki-co/php-k8s with enhanced PHP 8.2+ support and additional features.

This fork was created to continue active development and modernization of the library. Key differences from the upstream project:

  • PHP 8.2+ Modernization: Full use of enums, readonly properties, and modern type hints
  • Active Maintenance: Regular updates for new Kubernetes versions
  • Enhanced Resource Support: Additional resource types and improved trait composition
  • Comprehensive Documentation: This documentation site with extensive examples and guides

See the Fork Differences page for a detailed comparison with the upstream project.

Installation

Since this is a fork, add the repository to your composer.json:

json
{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/cuppett/php-k8s"
        }
    ]
}

Then install the package:

bash
composer require renoki-co/php-k8s

For Laravel projects:

bash
composer require renoki-co/laravel-php-k8s

Note: The laravel-php-k8s package is from the upstream project. Compatibility with this fork is not guaranteed.

Supported Kubernetes Versions

This library is tested against multiple Kubernetes versions:

  • v1.32.9
  • v1.33.5
  • v1.34.1

Requirements

  • PHP 8.2 or higher
  • ext-json
  • Guzzle 7.x
  • Symfony Process 7.x

Community & Support

Credits

License

This project is licensed under the Apache-2.0 License.

Released under the Apache-2.0 License. Originally from renoki-co/php-k8s.