Download the PHP package k8s/client without Composer
On this page you can find all versions of the php package k8s/client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package client
Short Description A Kubernetes client for PHP.
License MIT
Informations about the package client
k8s-client
k8s-client is a Kubernetes API client for PHP.
- HTTP Client agnostic (supports any PSR-18 compatible HTTP Client)
- Supports all major API operations (read, watch, list, patch, delete, exec, attach, logs, port-forward, proxy, etc)
- Supports all Kinds from the Kubernetes API (via auto-generated Kind models with annotations and type-hints).
- Pluggable websocket adapter support (For executing commands in pods, attaching, port-forwarding, etc)
The Kind models are auto-generated nightly for the last 10 versions of the Kubernetes API.
- Installation
- Using a Specific Kubernetes Version
- Installing a Websocket Adapter
- Constructing the Client Automatically
- Constructing the Client Manually
- Examples
- List All Pods
- Watch All Deployments in a Namespace
- Create a Pod
- Create a Deployment
- Patch a Deployment
- Get Logs for a Pod
- Follow Logs for a Pod
- Execute a Command in a Pod
- Attach to the Running Process of a Pod
- Download Files from a Pod
- Upload Files to a Pod
- Port Forwarding from a Pod
- Proxy HTTP Requests to a Pod
Installation
Install using composer:
This library requires a PSR-18 compatible HTTP Client, such as Guzzle or Symfony's HttpClient. It can also be given a PSR-16 compatible Simple Cache implementation to help speed up the library.
Using a Specific Kubernetes API version
Each Kubernetes version may have different resources and operations. If you require a specific version, then you can
require the version of the k8s/api
library that you need to use. That library contains all the API specific versions
and models that are consumed by this library.
For instance, to use API version 1.18:
composer require k8s/api:"~1.18.0"
Note: The version of k8s/api
does not exactly reflect the version of the Kubernetes API. The patch version of
Kubernetes may not be the same as the k8s/api
patch version.
Installing a Websocket Adapter
Certain Kuberenetes API endpoints (such as exec, to run commands in a container) require websockets to communicate. If you need support for this, install one of these adapters:
-
ReactPHP based websocket adapter (https://github.com/k8s-client/ws-ratchet):
composer require k8s/ws-ratchet
-
Swoole based websocket adapter (https://github.com/k8s-client/ws-swoole):
composer require k8s/ws-swoole
See each library's readme for more configuration information.
Constructing the Client Automatically
The easiest way to construct the client is from a pre-defined KubeConfig:
Note: This requires the use of an HttpClient factory helper. Install one of these packages:
k8s/http-symfony
(Symfony based HttpClient)k8s/http-guzzle
(Guzzle based HttpClient)
Constructing the Client Manually
Construct the client with your needed options:
Note: If you need to perform certificate based authentication, check the options for the HttpClient you are using. Also check the configuration for the websocket adapter you are using.
Examples
List all Pods
Watch all Deployments in a Namespace
Create a Pod
Using model classes:
Using array data:
Create a Deployment
Using model classes:
Using array data:
Proxy HTTP requests to a Pod
The proxy method sends an HTTP request to a path of a pod, service, or node. It makes no assumptions about what type of HTTP request you want to send, so it accepts a standard PSR-7 RequestInterface and returns a ResponseInterface.
Get Logs for a Pod
Follow Logs for a Pod
Execute a command in a Pod container
Attach to the running process of a container in a Pod
Patch a Deployment
Upload Files to a Pod
Download Files from a Pod
Port Forwarding from a Pod
Note: The below example assumes a pod called portforward-example
exists with port 80 serving HTTP (such as a base nginx image).
Create a class that reacts to port forwarding events:
Use the above class as a handler for the port forward process:
All versions of client with dependencies
ext-json Version *
doctrine/annotations Version ^1.0
k8s/api Version *
k8s/core Version ^1.3
klkvsk/json-decode-stream Version ^1.0
php-http/discovery Version ^1.0
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/simple-cache Version ^1.0
symfony/yaml Version >=3.4