useRenokiCo\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:
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:
useRenokiCo\PhpK8s\Kinds\K8sDaemonSet;K8sDaemonSet::selectPods(function (K8sDaemonSet $ds) {// $ds is the current DaemonSetreturn ['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: