{"id":25553935,"url":"https://github.com/prezly/kubernetes-client","last_synced_at":"2026-04-11T20:33:22.273Z","repository":{"id":57044578,"uuid":"373114823","full_name":"prezly/kubernetes-client","owner":"prezly","description":"Minimalistic Kubernetes API client implementation in PHP","archived":false,"fork":false,"pushed_at":"2021-11-05T13:26:40.000Z","size":42,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-16T16:19:22.047Z","etag":null,"topics":["api","client","kubernetes","php","watch"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prezly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-02T09:46:57.000Z","updated_at":"2024-12-18T23:06:13.000Z","dependencies_parsed_at":"2022-08-24T04:11:18.534Z","dependency_job_id":null,"html_url":"https://github.com/prezly/kubernetes-client","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prezly%2Fkubernetes-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prezly%2Fkubernetes-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prezly%2Fkubernetes-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prezly%2Fkubernetes-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prezly","download_url":"https://codeload.github.com/prezly/kubernetes-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239833544,"owners_count":19704629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","client","kubernetes","php","watch"],"created_at":"2025-02-20T12:03:31.009Z","updated_at":"2026-02-18T23:30:18.077Z","avatar_url":"https://github.com/prezly.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Prezly's Kubernetes Client\n\nPrezly's Kubernetes Client is a minimalistic Kubernetes API client implementation in PHP \nwhich allows you to list, fetch, update, delete and **watch** resources in your Kubernetes cluster.\n\n![Tests Status](https://github.com/prezly/kubernetes-client/actions/workflows/test.yml/badge.svg)\n\n\n## Features\n\n- [Kubernetes Watch API](https://kubernetes.io/docs/reference/using-api/api-concepts/#efficient-detection-of-changes) support\n- Unlimited authentication functionality\n- No knowledge about any specific Kubernetes resources: it supports every resource or collection you have\n- PHP 7.4+\n- PHP 8.0\n- Semver\n- Tests\n\n\n## Installation\n\nUse [Composer](https://getcomposer.org/) package manager to add *Prezly's Kubernetes Client* to your project:\n\n```\ncomposer require prezly/kubernetes-client\n```\n\n\n## Authentication\n\n*Prezly's Kubernetes Client* accepts a pre-configured Guzzle HTTP client as constructor argument,\nso you can configure it to any exotic connection, authentication or proxy setup you may have.\n\n```php\nuse GuzzleHttp\\Client as HttpClient;\nuse Prezly\\KubernetesClient\\KubernetesClient;\n\n$http = new HttpClient([\n    'base_uri' =\u003e 'https://kubernetes.local/',\n    'verify'   =\u003e false,\n]);\n\n$client = new KubernetesClient($http);\n```\n\nThere's also a `KubernetesClientFactory` to provide a fluent API to configure a KubernetesClient\nfor most common use-cases: \n\n```php\n\u003c?php\nuse Prezly\\KubernetesClient\\KubernetesClientFactory as Factory;\n\n$client = Factory::connectTo('https://kubernetes.companyintranet.local')\n    -\u003ewithAccessToken(getenv('KUBERNETES_ACCESS_TOKEN'))\n    -\u003ewithCertificateAuthority('/app/kubernetes.ca')\n    -\u003econstructClient();\n    \n// Interact with Kubernetes API with $client\n```\n\n\n## Logging\n\n*Prezly's Kubernetes Client* can be configured with any PSR logger implementation to provide internal log\nfor application monitoring. This is especially recommended for long-running resource-watching *daemon applications*.\n\n```php\nuse Prezly\\KubernetesClient\\KubernetesClient;\nuse Psr\\Log\\LoggerInterface;\n\n$logger = new MyCustomLogger();\nassert($logger instanceof LoggerInterface);\n\n$client = new KubernetesClient($http, $logger);\n```\n\nOr you can also configure a logger with `KubernetesClientFactory` fluent API:\n\n```php\nuse Prezly\\KubernetesClient\\KubernetesClientFactory as Factory;\n\n$client = Factory::connectTo('https://kubernetes.companyintranet.local')\n    -\u003ewithLogger(new MyCustomLogger())\n    -\u003econstructClient();\n```\n\n\n## API Interaction\n\nOnce you have a *KubernetesClient* instance, you can interact with Kubernetes APIs \nwith the plain-simple REST client abstraction: \n\n- `$client-\u003eget($uri, $queryParams)` \u0026mdash; to perform `GET` requests\n- `$client-\u003epost($uri, $body, $queryParams)` \u0026mdash; to perform `POST` requests\n- `$client-\u003eput($uri, $body, $queryParams)` \u0026mdash; to perform `PUT` requests\n- `$client-\u003epatch($uri, $body, $queryParams)` \u0026mdash; to perform `PATCH` requests\n- `$client-\u003edelete($uri, $queryParams)` \u0026mdash; to perform `DELETE` requests\n\n```php\n\u003c?php\n/** @var \\Prezly\\KubernetesClient\\KubernetesClient $client */\n$ingresses = $client-\u003eget('/apis/networking.k8s.io/v1/namespaces/default/ingresses');\n\nforeach ($ingresses['items'] as $ingress) {\n    $client-\u003edelete(\"/apis/networking.k8s.io/v1/namespaces/default/ingresses/{$ingress['metadata']['name']}\");\n}\n```\n\n\n## Watching resources\n\n*KubernetesClient* implements a simple yet powerful abstraction to access Kubernetes *Watch API*:\n\n```php\n/** @var \\Prezly\\KubernetesClient\\KubernetesClient $client */\n$client-\u003ewatch($url, $watcher, $initializer = null);\n```\n\nA `watch()` call starts an **infinite daemon process** that will *self-recover and retry* from any HTTP errors.\nTo better monitor what's going on during a watch call it is strongly recommended configuring a logger.\n\n```php\n/** @var \\Prezly\\KubernetesClient\\KubernetesClient $client */\n$client-\u003ewatch('/apis/networking.k8s.io/v1/namespaces/default/ingresses', function (array $event) {\n    if ($event['type'] === 'ADDED') {\n        echo \"Ingress `{$event['object']['metadata']['name']}` was added\\n\";\n    }\n});\n```\n\n\n### Initializing state before starting watcher\n\nYou can also provide an *initializer* to initialize state before *watch* starts:\n\n```php\n/** @var \\Prezly\\KubernetesClient\\KubernetesClient $client */\n$client-\u003ewatch(\n    '/apis/networking.k8s.io/v1/namespaces/default/ingresses', \n    function (array $event) {\n        if ($event['type'] === 'ADDED') {\n            echo \"Ingress `{$event['object']['metadata']['name']}` was added\\n\";\n        }\n    },\n    function (array $ingresses) {\n        foreach ($ingresses['items'] as $ingress) {\n            echo \"Ingress `{$ingress['metadata']['name']}` existed before the watcher started\\n\";\n        }\n    }\n);\n```\n\n\n### Stopping daemon\n\nBy default, the watcher will run indefinitely, but you can return `false` from your *watch* callback to force it exit.\n\n```php\n/** @var \\Prezly\\KubernetesClient\\KubernetesClient $client */\n$client-\u003ewatch('/apis/networking.k8s.io/v1/namespaces/default/ingresses', function (array $event) {\n    if ($event['type'] === 'DELETED') {\n        return false; // force exit\n    }\n});\n```\n\n\n## Credits\n\nBrought to you with :heart: by [Prezly](https://www.prezly.com/?utm_source=github\u0026utm_campaign=prezly/kubernetes-client) \u0026mdash; PR software for better, faster communication.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprezly%2Fkubernetes-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprezly%2Fkubernetes-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprezly%2Fkubernetes-client/lists"}