Skip to content

Latest commit

 

History

History
109 lines (77 loc) · 2.12 KB

Deployment.md

File metadata and controls

109 lines (77 loc) · 2.12 KB

Deployment

Example

Deployment Creation

Deployments are just configurations that relies on a Pod. So before diving in, make sure you read the Pod Documentation

$container = K8s::container();

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

$pod = K8s::pod()
    ->setName('mysql')
    ->setLabels(['tier' => 'backend'])
    ->setContainers([$mysql]);

$dep = K8s::deployment()
    ->onCluster($this->cluster)
    ->setName('mysql')
    ->setSelectors(['matchLabels' => ['tier' => 'backend']])
    ->setReplicas(1)
    ->setTemplate($pod);

Deployments support annotations, as well as labels:

$dep->setAnnotations([
    'nginx.kubernetes.io/tls' => 'true',
]);
$dep->setLabels([
    'matchesLabel' => ['app' => 'backend'],
]);

While the Deployment kind has spec, you can avoid writing this:

$dep = K8s::deployment($cluster)
    ->setAttribute('spec.template', [...]);

And use the setSpec() method:

$dep = K8s::deployment($cluster)
    ->setSpec('template', [...]);

Dot notation is supported:

$dep = K8s::deployment($cluster)
    ->setSpec('some.nested.path', [...]);

Retrieval

$dep = K8s::deployment($cluster)
    ->whereName('mysql')
    ->get();

$template = $dep->getTemplate();

Retrieving the spec attributes can be done like the setSpec() method:

$dep->getSpec('template', []);

The second value for the getSpec() method is the default value, in case the found path is not existent.

Dot notation is supported:

$dep->getSpec('some.nested.path', []);

Deployment's Pod Template Retrieval

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

$template = $dep->getTemplate();

$podName = $template->getName();

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

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

$podName = $template['name'];