PHP code example of roundly-consulting / kubernetes-api-for-laravel
1. Go to this page and download the library: Download roundly-consulting/kubernetes-api-for-laravel 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/ */
roundly-consulting / kubernetes-api-for-laravel example snippets
use RoundlyConsulting\KubernetesApi\Facades\Kubernetes;
use RoundlyConsulting\KubernetesApi\Resources\Pod;
use RoundlyConsulting\KubernetesApi\Resources\Types\Container;
$shop = Kubernetes::namespace('shop'); // every request stays in `shop`
$pods = $shop->pods()->whereLabel('app', 'web')->get(); // a collection of Pod resources
$shop->deployments()
->setName('checkout')
->setReplicas(3)
->setPodsSelectors(['app' => 'checkout'])
->setTemplate(Pod::make()
->setLabels(['app' => 'checkout'])
->setContainers([Container::make()->setName('app')->setImage('nginx', '1.27-alpine')]))
->create();
$shop->deployments()->withName('checkout')->scale(5); // via the /scale subresource
$shop->deployments()->withName('checkout')->rolloutRestart(); // like `kubectl rollout restart`
Kubernetes::cluster('production')->nodes()->get(); // a cluster from config/kubernetes.php
Kubernetes::fromKubeConfig(context: 'staging')->pods()->get(); // a kubeconfig context
Kubernetes::ping(); // does the apiserver answer?