1. Go to this page and download the library: Download keboola/k8s-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/ */
keboola / k8s-client example snippets
use Keboola\K8sClient\ClientFactory\StaticKubernetesApiClientFactory;
use Keboola\K8sClient\KubernetesApiClientFacade;
use Kubernetes\Model\Io\K8s\Api\Core\V1\Container;
use Kubernetes\Model\Io\K8s\Api\Core\V1\Pod;
$clientFactory = new StaticKubernetesApiClientFactory(
$retryProxy,
'https://api.k8s-cluster.example.com',
'secret-token',
'var/k8s/caCert.pem',
'default',
);
$apiClient = $clientFactory->createApiClient();
$client = KubernetesApiClientFacade::create($apiClient, $logger);
$pod = new Pod([
'metadata' => [
'name' => 'my-pod',
],
'spec' => [
'restartPolicy' => 'Never',
'containers' => [
new Container([
'name' => 'app',
'image' => 'alpine',
'command' => ['sh', '-c', 'echo hello; sleep 3; echo bye'],
]),
],
],
]);
// create the pod
$client->createModels([
$pod,
]);
// wait for pod to finish
do {
$pod = $client->pods()->getStatus($pod->metadata->name);
if (in_array($pod->status->phase, ['Succeeded', 'Failed'], true)) {
break;
}
sleep(1);
} while (true);
// check pod logs
$client->pods()->readLog($pod->metadata->name);
// delete the pod
$client->deleteModels([
$pod,
]);
$facade = KubernetesApiClientFacade::create($apiClient, $logger, [
My\Crd\Model::class => new My\Crd\ApiClient($apiClient),
]);
$facade->client(My\Crd\Model::class)->get('my-resource'); // typed access
$facade->mergePatch($myCrdModel); // generic methods route via the map too
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.