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\ClientFacadeFactory\GenericClientFacadeFactory;
use Kubernetes\Model\Io\K8s\Api\Core\V1\Container;
use Kubernetes\Model\Io\K8s\Api\Core\V1\Pod;
$clientFactory = new GenericClientFacadeFactory($retryProxy, $logger);
$client = $clientFactory->createClusterClient(
'https://api.k8s-cluster.example.com',
'secret-token',
'var/k8s/caCert.pem',
'default'
);
$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,
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.