PHP K8s
Github Repo
3.x
3.x
  • ๐ŸšขIntroduction
  • ๐ŸŽ‰Support
  • โซUpgrading to 3.x
  • Getting Started
    • ๐Ÿš€Installation
    • ๐Ÿ™ŒShowcase
    • ๐Ÿ”’Authentication
    • โ™ป๏ธActive Development
      • ๐Ÿ“—Default Versions
      • ๐Ÿง™Supported Kubernetes versions
      • ๐Ÿ—ณ๏ธPackage versioning
  • Cluster Interaction
    • ๐ŸงญGetting Started
    • ๐ŸŽญCRUD Operations
    • ๐Ÿ“ฆImport from YAML
    • ๐Ÿ‘€Watching Resources
  • Resources
    • ๐Ÿ‘“Base Resource
      • Attributes Methods
      • Metadata Methods
      • Custom Callers
    • ๐Ÿง‘Namespace
    • ๐Ÿ–ฅ๏ธNode
    • ๐Ÿ“กEvent
    • ๐Ÿ“ฆWorkloads
      • Pod
      • Deployment
      • StatefulSet
      • DaemonSet
      • Job
      • CronJob
    • ๐ŸงตConfigurations
      • ConfigMap
      • Secret
    • ๐Ÿ“€Storage
      • StorageClass
      • PersistentVolume
      • PersistentVolumeClaim
    • ๐Ÿ“ถNetworking
      • Service
      • Ingress
    • โ†”๏ธScaling & Availability
      • HorizontalPodAutoscaler
      • PodDisruptionBudget
    • ๐Ÿ”‘RBAC
      • ClusterRole
      • ClusterRoleBinding
      • Role
      • RoleBinding
      • ServiceAccount
  • Instances
    • Affinity
    • Container
    • Container Probes
    • Expressions
    • Resource Metrics
    • RBAC Rules
    • Volumes
  • Advanced
    • ๐ŸฐMacros
    • โœจCreate classes for CRDs
      • ๐ŸŽ‡Getting started
      • ๐ŸฐMacros
      • ๐Ÿ‘€Watchable Resources
      • โ†”๏ธScalable Resources
      • ๐Ÿ’ŠPodable Resources
      • ๐Ÿ“„Loggable Resources
      • ๐Ÿš’Helper Traits
  • Frameworks
    • Laravel
    • PHP Helm
Powered by GitBook
On this page
  • Namespace
  • Names
  • Labels
  • Annotations
  • Transformers

Was this helpful?

  1. Resources
  2. Base Resource

Metadata Methods

PreviousAttributes MethodsNextCustom Callers

Last updated 3 years ago

Was this helpful?

Namespace

getNamespace()

Get the namespace the resource is in. This usually works only for namespaceable resources.

$service->getNamespace();

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)

Alias for

It's just a naming convention for better filters on the get methods.

Names

setName($name)

Set the name of the resource.

$service->setName('nginx');

getName()

Get the name of a resource.

$namespace->getName();

whereName($name)

Labels

setLabels(array $labels)

Set the labels of the resource.

$service->setLabels(['tier' => 'backend']);

getLabels()

Get the labels of a resource.

$service->getLabels();

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)

Set or update the labels. The method used will be merge.

$service->setOrUpdateLabels([
    'tier' => 'backend'
    'some-other-label' => 'test',
]);

Annotations

setAnnotations(array $annotations)

Set the annotations for the resource.

$service->setAnnotations(['kubernetes.io/some-annotation' => 'yes']);

getAnnotations()

Get the annotations of a resource.

$service->getAnnotations();

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)

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()

Get the resource API version.

$namespace->getApiVersion();

getKind()

Get the resource's Kind. This method is called statically.

$kind = $namespace::getKind();

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()

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()

Get the resource as an array.

$array = $namespace->toArray();

Alias for . It's just a naming convention for better filters on get.

๐Ÿ‘“
setNamespace($namespace)
setName($name)