1. Go to this page and download the library: Download kubernetes/php-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/ */
kubernetes / php-client example snippets
ubernetesRuntime\Client;
use Kubernetes\API\ConfigMap as ConfigMapAPI;
use Kubernetes\Model\Io\K8s\Api\Core\V1\ConfigMap;
$master = 'https://you-kubernetes-cluster.com';
$authentication = [
'caCert' => '/usr/local/your-ca-file-location',
'token' => 'base64-based-token'
];
// This configure function only need to run once in the whole session
Client::configure($master, $authentication);
$ConfigMapAPI = new ConfigMapAPI();
$ConfigMap = new ConfigMap([
'metadata' => [
'name' => 'kubernetes-php-client-test'
],
'data' => [
'bar' => 'foo'
]
]);
$ConfigMapAPI->create('default',$ConfigMap);
$response = $ConfigMapAPI->read('default','kubernetes-php-client-test');
print_r($response);
/*
Kubernetes\Model\Io\K8s\Api\Core\V1\ConfigMap Object
(
[apiVersion] => v1
[data] => Array
(
[bar] => foo
)
[kind] => ConfigMap
[metadata] => Kubernetes\Model\Io\K8s\Apimachinery\Pkg\Apis\Meta\V1\ObjectMeta Object
(
[annotations] =>
[clusterName] =>
[creationTimestamp] => 2018-08-07T10:32:06Z
[deletionGracePeriodSeconds] =>
[deletionTimestamp] =>
[finalizers] =>
[generateName] =>
[generation] =>
[initializers] =>
[labels] =>
[name] => kubernetes-php-client-test
[namespace] => default
[ownerReferences] =>
[resourceVersion] => 24374466
[selfLink] => /api/v1/namespaces/default/configmaps/kubernetes-php-client-test
[uid] => 21f7036f-9a2d-11e8-89e9-0eeed2d5ffa8
[isRawObject:protected] =>
[rawData:protected] =>
)
[isRawObject:protected] =>
[rawData:protected] =>
)
*/