Metadata Methods
Namespace
getNamespace()
getNamespace()
Get the namespace the resource is in. This usually works only for namespaceable resources.
$service->getNamespace();
setNamespace($namespace)
setNamespace($namespace)
Set the namespace for the resource, if namespaceable. This usually works only for namespaceable resources.
$service->setNamespace('staging');
The namespace also accepts a K8sNamespace
class:
$ns = $cluster->getNamespaceByName('staging');
$service->setNamespace($ns);
whereNamespace($namespace)
whereNamespace($namespace)
Alias for setNamespace($namespace)
It's just a naming convention for better filters on the get methods.
Names
setName($name)
setName($name)
Set the name of the resource.
$service->setName('nginx');
getName()
getName()
Get the name of a resource.
$namespace->getName();
whereName($name)
whereName($name)
Alias for setName($name). It's just a naming convention for better filters on get.
Labels
setLabels(array $labels)
setLabels(array $labels)
Set the labels of the resource.
$service->setLabels(['tier' => 'backend']);
getLabels()
getLabels()
Get the labels of a resource.
$service->getLabels();
getLabel($name, $default = null)
getLabel($name, $default = null)
Get the label value by key. Defaults to null.
$service->getLabel('tier'); // "backend"
$service->getLabel('not-a-label'); // null
setOrUpdateLabels(array $labels)
setOrUpdateLabels(array $labels)
Set or update the labels. The method used will be merge.
$service->setOrUpdateLabels([
'tier' => 'backend'
'some-other-label' => 'test',
]);
Annotations
setAnnotations(array $annotations)
setAnnotations(array $annotations)
Set the annotations for the resource.
$service->setAnnotations(['kubernetes.io/some-annotation' => 'yes']);
getAnnotations()
getAnnotations()
Get the annotations of a resource.
$service->getAnnotations();
getAnnotation($name, $default = null)
getAnnotation($name, $default = null)
Get the annotation value by key. Defaults to null.
$service->getAnnotation('kubernetes.io/some-annotation'); // "yes"
$service->getAnnotation('kubernetes.io/non-existing-annotation'); // null
setOrUpdateAnnotations(array $annotations)
setOrUpdateAnnotations(array $annotations)
Set or update the annotations. The method will be merging existing annotations with the ones passed via the function argument.
$service->setOrUpdateAnnotations([
'kubernetes.io/some-annotation' => 'yes'
'kubernetes.io/some-otherannotation' => 'yes',
]);
getApiVersion()
getApiVersion()
Get the resource API version.
$namespace->getApiVersion();
getKind()
getKind()
Get the resource's Kind. This method is called statically.
$kind = $namespace::getKind();
setDefaultVersion()
setDefaultVersion()
Set at runtime the default version that will be used for the resource.
use RenokiCo\PhpK8s\Kinds\K8sDeployment;
// instead of default apps/v1
K8sDeployment::setDefaultVersion('apps/v2beta1');
setDefaultNamespace()
setDefaultNamespace()
Set at runtime the default namespace that will be used for the resource.
use RenokiCo\PhpK8s\Kinds\K8sDeployment;
K8sDeployment::setDefaultNamespace('staging'); // instead of "default"
To set the default namespace for all resources, you might want to use K8sResource
instead:
use RenokiCo\PhpK8s\Kinds\K8sResource;
K8sResource::setDefaultNamespace('staging');
Now all resources will interact with the staging
namespace by default.
Transformers
toArray()
toArray()
Get the resource as an array.
$array = $namespace->toArray();
Last updated
Was this helpful?