renoki-co / php-k8s by rennokki

Control your Kubernetes clusters with this PHP-based Kubernetes client. It supports any form of authentication, the exec API, and it has an easy implementation for CRDs.
449,112
310
8
Package Data
Maintainer Username: rennokki
Package Create Date: 2020-04-29
Package Last Update: 2024-06-10
Home Page:
Language: PHP
License: Apache-2.0
Last Refreshed: 2024-12-15 15:12:36
Package Statistics
Total Downloads: 449,112
Monthly Downloads: 12,937
Daily Downloads: 100
Total Stars: 310
Total Watchers: 8
Total Forks: 61
Total Open Issues: 21

PHP K8s

CI codecov StyleCI Latest Stable Version Total Downloads Monthly Downloads License

v1.19.10 K8s Version v1.20.6 K8s Version v1.21.0 K8s Version

Client Capabilities Client Support Level

Control your Kubernetes clusters with this PHP-based Kubernetes client. It supports any form of authentication, the exec API, and it has an easy implementation for CRDs.

For Laravel projects, you might want to use renoki-co/laravel-php-k8s which eases the access for this particular case.

🤝 Supporting

Renoki Co. on GitHub aims on bringing a lot of open source projects and helpful projects to the world. Developing and maintaining projects everyday is a harsh work and tho, we love it.

If you are using your application in your day-to-day job, on presentation demos, hobby projects or even school projects, spread some kind words about our work or sponsor our work. Kind words will touch our chakras and vibe, while the sponsorships will keep the open source projects alive.

ko-fi

🚀 Installation

You can install the package via composer:

composer require renoki-co/php-k8s

🙌 Usage

Having the following YAML configuration for a Service:

apiVersion: v1
kind: Service
metadata:
  name: nginx
  namespace: frontend
spec:
  selector:
    app: frontend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

Can be written like this:

use RenokiCo\PhpK8s\KubernetesCluster;

// Create a new instance of KubernetesCluster.
$cluster = new KubernetesCluster('http://127.0.0.1:8080');

// Create a new NGINX service.
$svc = $cluster->service()
    ->setName('nginx')
    ->setNamespace('frontend')
    ->setSelectors(['app' => 'frontend'])
    ->setPorts([
        ['protocol' => 'TCP', 'port' => 80, 'targetPort' => 80],
    ])
    ->create();

📄 Getting Started

To easily get started about how the resources are being handled, take a look at the Resources: Getting Started and Cluster Authentication guides, which provides a lot of examples on how to interact with the resources within the cluster.

Once you got started with how PHPK8s works, you can get specific methods, examples and tips for each resource that's implemented.

PHP K8s comes out-of-the-box with the following listed resources. For missing core Kubernetes CRDs, refer to the Planned Resources section and if you have custom resources (CRDs), you can implement them yourself.

| Resource | Default Version | - | - | ClusterRole | rbac.authorization.k8s.io/v1 | ClusterRoleBinding | rbac.authorization.k8s.io/v1 | ConfigMap | v1 | CronJob | batch/v1beta1 | DaemonSet | apps/v1 | Deployment | apps/v1 | Event | v1 | HorizontalPodAutoscaler | autoscaling/v2beta2 | Ingress | networking.k8s.io/v1 | | Job | batch/v1 | Namespace | v1 | Node | v1 | PersistenVolume | v1 | PersistenVolumeClaim | v1 | Pod | v1 | PodDisruptionBudget | policy/v1beta1 | Role | rbac.authorization.k8s.io/v1 | RoleBinding | rbac.authorization.k8s.io/v1 | Secret | v1 | Service | v1 | ServiceAccount | v1 | StatefulSet | apps/v1 | StorageClass | storage.k8s.io/v1

🔒 Cluster Authentication

PHP K8s supports any kind of HTTP cluster authentication, from Bearer Tokens to In-Cluster configuration for Pods. The extensive documentation on authentication & security can be found here.

📗 Default Versions for resources

Since the package supports multiple K8s Cluster versions, some versions do promote certain resources to GA. Since each resource needs a default version, the package will set the default versions for the oldest Kubernetes version supported.

For example, if the package supports v1.18+, then the package will make sure the versions are defaults for v1.18. In some cases, like Ingress in v1.19 that switched from Beta to GA, the v1beta1 is no longer a default and instead, the v1 is now a default. If v1.17 is the oldest supported version, then it will stay to v1beta.

The minimum Kubernetes version that is supported by a given package version can be found at the top of this file. Maintainers try as hard as possible to update the Kubernetes versions that are put into test to the latest patch as often as possible.

🐛 Testing

vendor/bin/phpunit

🤝 Contributing

Please see CONTRIBUTING for details.

🔒 Security

If you discover any security related issues, please email alex@renoki.org instead of using the issue tracker.

🎉 Credits