teknoo / kubernetes-client
一个简单而优雅的客户端,用于访问和控制 Kubernetes 集群。
Requires
- php: ^8.2
- ext-json: *
- illuminate/collections: ^10.48||^11
- illuminate/contracts: ^10.48||^11
- php-http/client-common: ^2.7
- php-http/discovery: ^1.19
- psr/http-message: ^1.0.1||^2
- symfony/yaml: ^6.4||^7.0
Requires (Dev)
- behat/behat: ^v3.14
- nyholm/psr7: ^1.8.1
- php-http/curl-client: ^2.3.1
- php-http/guzzle7-adapter: ^1
- php-http/socket-client: ^2.1.1
- phpstan/phpstan: ^1.12.3
- phpunit/phpunit: ^11.3.5
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.10.2
- symfony/console: ^6.4||^7
- symfony/http-client: ^6.4||^7.0
- symfony/options-resolver: ^6.4||^7
- symfony/property-access: ^6.4||^7.0
- dev-master
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- 0.31.0
- 0.30.3
- 0.30.2
- 0.30.1
- 0.30.0
- 0.26.0
- 0.25.0
- 0.24.0
- 0.23.0
- 0.22.0
- 0.21.0
- 0.20.0
- 0.19.0
- 0.18.3
- 0.18.2
- 0.18.1
- 0.18.0
- 0.17.0
- 0.16.0
- 0.15.0
- 0.14.3
- 0.14.2
- 0.14.1
- 0.14.0
- 0.13.0
- 0.12.1
- 0.12.0
- 0.11.0
- 0.10.0
- 0.9.1
- 0.9.0
- 0.8.1
- 0.8.0
- 0.7.0
- 0.6.0
- 0.5.1
- 0.5.0
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.0
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- 0.0.10
- 0.0.9
- 0.0.8
- 0.0.7
- 0.0.6
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
This package is auto-updated.
Last update: 2024-09-24 06:45:13 UTC
README
一个用于管理 Kubernetes 集群的 PHP 客户端。通过操作 Manifests(以 PHP 数组形式)通过 Kubernetes HTTP API 来控制 Kubernetes 资源。客户端支持所有 Kubernetes API V1.28 资源,但也可以定义新的资源供客户端使用。这是一个从 Maclof Kuebrnetes 库 分支出来的重构。
支持的 API 功能
v1
- Config Maps
- 删除选项
- 端点
- 端点
- 事件
- 命名空间
- 节点
- 持久卷
- 持久卷声明
- Pods
- 配额
- 副本集
- 副本控制器
- 机密
- 服务账户
- 服务
autoscaling/v2
- 水平 pod 自动缩放器
batch/v1
- CronJobs
- 作业
batch/v1beta1
- Cron Jobs
apps/v1
- 守护进程集
- 部署
- 副本集
extensions/v1beta1
- 守护进程集
networking.k8s.io/v1
- 入口
- 网络策略
certmanager.k8s.io/v1
- 证书
- 颁发者
rbac.authorization.k8s.io/v1
- 集群角色
- 集群角色绑定
- 角色
- 角色绑定
hnc.x-k8s.io/v1
- 子命名空间锚点
基本用法
use Teknoo\Kubernetes\Client;
$client = new Client([
'master' => 'http://master.mycluster.com',
]);
// Find pods by label selector
$pods = $client->pods()
->setLabelSelector(
[
'name' => 'test',
'version' => 'a',
]
)->find();
// Both setLabelSelector and setFieldSelector can take an optional
// second parameter which lets you define inequality based selectors (ie using the != operator)
$pods = $client->pods()
->setLabelSelector(
['name' => 'test'],
['env' => 'staging']
)->find();
// Find pods by field selector
$pods = $client->pods()->setFieldSelector(['metadata.name' => 'test'])->find();
// Find first pod with label selector (same for field selector)
$pod = $client->pods()->setLabelSelector(['name' => 'test'])->first();
身份验证示例
不安全的 HTTP
use Teknoo\Kubernetes\Client; $client = new Client([ 'master' => 'http://master.mycluster.com', ]);
从 kubeconfig 文件连接
use Teknoo\Kubernetes\Client; // Parsing from the file data directly $client = Client::loadFromKubeConfig('kubeconfig yaml data'); // Parsing from the file path $client = Client::loadFromKubeConfigFile('~/.kube/config.yml');
扩展库
自定义仓库
use Teknoo\Kubernetes\Client; $repositories = new RepositoryRegistry(); $repositories['things'] = MyApp\Kubernetes\Repository\ThingRepository::class; $client = new Client( [ 'master' => 'https://master.mycluster.com', ], $repositories ); $client->things(); //ThingRepository
使用示例
创建/更新副本控制器
以下示例使用数组指定副本控制器的属性。您可以指定属性为数组、JSON 编码的字符串或 YAML 编码的字符串。模型构造函数的第二个参数是数据类型,默认为数组。
use Teknoo\Kubernetes\Model\ReplicationController; $replicationController = new ReplicationController([ 'metadata' => [ 'name' => 'nginx-test', 'labels' => [ 'name' => 'nginx-test', ], ], 'spec' => [ 'replicas' => 1, 'template' => [ 'metadata' => [ 'labels' => [ 'name' => 'nginx-test', ], ], 'spec' => [ 'containers' => [ [ 'name' => 'nginx', 'image' => 'nginx', 'ports' => [ [ 'containerPort' => 80, 'protocol' => 'TCP', ], ], ], ], ], ], ], ]); if ($client->replicationControllers()->exists($replicationController->getMetadata('name'))) { $client->replicationControllers()->update($replicationController); } else { $client->replicationControllers()->create($replicationController); } $client->replicationControllers()->apply($replicationController); // or
删除副本控制器
$replicationController = $client->replicationControllers()->setLabelSelector(['name' => 'nginx-test'])->first(); $client->replicationControllers()->delete($replicationController);
您还可以在执行删除时指定选项,例如执行 级联删除
use Teknoo\Kubernetes\Model\DeleteOptions; $client->replicationControllers()->delete( $replicationController, new DeleteOptions(['propagationPolicy' => 'Background']) );
支持此项目
此项目是免费的,并将保持免费。它完全由 EIRL 的活动支持。如果您喜欢它并帮助我维护和改进它,请不要犹豫,在 Patreon 或 Github 上支持我。
谢谢 :) Richard。
致谢
EIRL Richard Déloge - https://deloge.io - 主开发者。Teknoo Software SASU - https://teknoo.software
关于 Teknoo Software
Teknoo Software 是一家 PHP 软件编辑公司,由 Richard Déloge 创立,作为 EIRL Richard Déloge 的一部分。Teknoo Software 的目标:为我们合作伙伴和社区提供一套高质量的服务或软件,分享知识和技能。
许可证
Kubernetes 客户端根据 MIT 许可证授权 - 有关详细信息,请参阅许可证文件夹。
安装 & 要求
要使用 composer 安装此库,请运行此命令
composer require teknoo/kubernetes-client
此库需要
* PHP 8.1+
* A PHP autoloader (Composer is recommended)
* Symfony/Yaml.
* Illuminate/Collections
贡献 :)
欢迎您为此项目贡献力量。 在Github上Fork它