PHP K8s
Github Repo
master
master
  • ๐Ÿšข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
  • Example
  • Pod Template Retrieval
  • Getting Pods
  • Custom Pod Labels
  • Scaling
  • Daemon Set Status

Was this helpful?

Edit on GitHub
  1. Resources
  2. Workloads

DaemonSet

PreviousStatefulSetNextJob

Last updated 3 years ago

Was this helpful?

Default version: apps/v1

Example

use RenokiCo\PhpK8s\K8s;

$container = K8s::container()
    ->setName('mysql')
    ->setImage('mysql', '5.7')
    ->setPorts([
        ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306],
    ]);

$pod = K8s::pod()
    ->setName('mysql')
    ->setLabels(['daemonset-name' => 'mysql']) // needs daemonset-name: mysql so that ->getPods() can work
    ->setContainers([$mysql]);

$ds = $this->cluster
    ->daemonSet()
    ->setName('mysql')
    ->setLabels(['tier' => 'backend'])
    ->setUpdateStrategy('RollingUpdate')
    ->setMinReadySeconds(0)
    ->setTemplate($pod);

Pod Template Retrieval

Daemon Sets rely on pods, so you can get the pod template as K8sPod class:

$template = $ds->getTemplate();

$podName = $template->getName();

To retrieve the pod template as an array, pass false to the retrieval method:

$pod = $ds->getTemplate(false);

$podName = $template['name'];

Getting Pods

To get the pods, the Pod template must have the daemonset-name label set. This way, the labelSelector API parameter is issued and you may retrieve the associated pods:

metadata:
  name: [here it goes the daemonset name]
spec:
  template:
    metadata:
      labels:
        daemonset-name: [here it goes the daemonset name]

You can retrieve the pods as resources controlled by the Daemon Set by issuing ->getPods():

foreach ($ds->getPods() as $pod) {
    // $pod->logs()
}

Custom Pod Labels

If you cannot declare the daemonset-name label or simply want to use something else, you may call selectPods from the resource:

use RenokiCo\PhpK8s\Kinds\K8sDaemonSet;

K8sDaemonSet::selectPods(function (K8sDaemonSet $ds) {
    // $ds is the current DaemonSet

    return [
        'some-label' => 'some-label-value',
        'some-other-label' => "{$ds->getName()}-custom-name",
    ];
});

Scaling

The Scaling API is available via a K8sScale resource:

$scaler = $ds->scaler();

$scaler->setReplicas(3)->update(); // autoscale the Daemon Set to 3 replicas

Shorthand, you can use scale() directly from the Daemon Set:

$scaler = $ds->scale(3);

$pods = $ds->getPods(); // Expecting 3 pods

Daemon Set Status

The Status API is available to be accessed for fresh instances:

$ds->refresh();

$ds->getScheduledCount();
$ds->getMisscheduledCount();
$ds->getNodesCount();
$ds->getDesiredCount();
$ds->getReadyCount();
$ds->getUnavailableClount();

You can check if all the pods within the Daemon Set are running:

if ($ds->allPodsAreRunning()) {
    //
}
๐Ÿ“ฆ
Official Documentation
PHP K8s Pod Kind