๐ญCRUD Operations
CRUD operations are available only if you have set up authentication, as the methods are available only from a KubernetesCluster
instance.
Retrieving all resources
Getting all resources can be done by calling ->all()
:
The result is an RenokiCo\PhpK8s\ResourcesList
instance. The class is extending \Illuminate\Support\Collection
, on which you can chain various methods as described here: https://laravel.com/docs/master/collections
Retrieving all resources from all namespaces
Retrieving all resources from all namespaces can also be done using the allNamespaces()
method:
For the specific method, the format should be getAll[Resource]FromAllNamespaces()
Retrieving a specific resource
Getting only one resource is done by calling ->get()
:
Filters can vary, depending if the resources are namespaceable or not. By default, the namespace is default
and can be missed from the function call.
Creating resources
Calling the ->create()
method after building your Kind will create the resource in your cluster. In fact, it will actually sync it to the Cluster as Kubernetes uses the resource names as identifiers.
Updating resources
While Kubernetes has the ability to PATCH a resource or REPLACE it entirely, PHP K8s relies on REPLACE to update your resource since you have to retrieve it first (thus getting a synced class), edit it, then triggering the update.
Deleting resources
You will have to simply call ->delete()
on the resource, after you retrieve it.
Additionally, you can pass query parameters, grace period, and the propagation policy if needed:
Creating or updating resources
Sometimes, you want to create a resource if it's not existent or update it with the current resource class info. You can do this in one chain call:
Each time the above code is running, it will create the ConfigMap if it's not existent, or it will update the existent one with a random number between 0 and 999.
Last updated