PHP code example of alicfeng / kubernetes-client
1. Go to this page and download the library: Download alicfeng/kubernetes-client library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alicfeng / kubernetes-client example snippets
use AlicFeng\Kubernetes\Kubernetes;
$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();
# Patch Service
$service->apply('name');
# Delete Service
$service->delete('name');
# Service Exist
$service->list()->exist('name');
# Item Service
$service->list()->item('name');
shell
php artisan vendor:publish --provider="AlicFeng\Kubernetes\ServiceProvider\AsmServiceProvider"
php artisan vendor:publish --provider="AlicFeng\Kubernetes\ServiceProvider\KubernetesServiceProvider"
# OR
php artisan vendor:publish --tag=kubernetes
php artisan vendor:publish --tag=asm