背景
在寫k8s介面呼叫的時候,引數特別多,繁雜,需要寫多很多重複的東西,記得很早之前想找一個可以直接傳簡單引數,就可以發起k8s,Service 、Pod 、Job、ConfigMap、Pvc 等
,生態上的這種庫是有的,只不過並沒有一個使我比較滿足的,當然、看個人所需,我需要一個比較清晰明瞭的。
於是kubernetes-client
就出現了、應用而生,它是一款基於 composer 的包,適用於laravel框架,那麼它可以做什麼?
KubernetesClient
安裝
composer require alicfeng/kubernetes-client -vvv
支援
- Service
- Deployment
- Pod
- Job
- ConfigMap
- DaemonSet
- Node
- Secrets
- StatefulSet
- Event
- Pvc
- PersistentVolumeClaim
- Ingress
- ReplicationController
使用說明
$config = [
'base_uri' => 'https://127.0.0.1:6443',
'token' => 'token',
'namespace' => 'default'
];
$service = Kubernetes::service($config);
$metadata = [
'name' => 'demo-service'
];
$spec = [
'type' => 'NodePort',
'selector' => [
'k8s-app' => 'demo-service',
],
'ports' => [
[
'protocol' => 'TCP',
'port' => 80,
'targetPort' => 80,
'nodePort' => 30008
]
]
];
# Create Service
$service->setMetadata($metadata)->setSpec($spec)->create();
# or
$service->setApiVersion('v1')->setKind('Service')->create($yaml);
# Patch Service
$service->apply();
# Delete Service
$service->delete('service-name');
# Service Exist
$service->list()->exist('service-name');
# Item Service
$service->list()->item('service-name');
本作品採用《CC 協議》,轉載必須註明作者和本文連結