Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2022-10-17 (1 month ago)  | | Not yet rated by the users | | Total: 12 This week: 3 | | All time: 10,801 This week: 270 |
|
Description | | Author |
This package can generate a configuration for a Kubernetes resource.
It provides classes to define the property values of several types of resources used in Kubernetes, like labels, containers, and pods.
The package can generate a configuration file in YAML format for a pod previously defined to be associated with a container with given labels. Innovation Award
 October 2022
Nominee
Vote |
Kubernetes is a system to manage containers used in many cloud hosting systems.
Containers are helpful for managing and running applications that can run in an isolated way, including those that implement PHP-based Web applications.
This package provides a simplified way to generate configuration files to use with Kubernetes containers from given parameters.
Manuel Lemos |
| |
 |
|
Innovation award
 Nominee: 3x |
|
Details
kubernetes-resource-generator

a PHP package to generate yaml files of Kubernetes resources.
Generate a Pod definition
use Acamposm\K8sResourceGenerator\Reference\Annotations\PodAnnotations;
use Acamposm\K8sResourceGenerator\Reference\Labels\PodLabels;
use Acamposm\K8sResourceGenerator\Enums\ImagePullPolicy;
use Acamposm\K8sResourceGenerator\Enums\OperatingSystem;
use Acamposm\K8sResourceGenerator\Enums\RestartPolicy;
use Acamposm\K8sResourceGenerator\Resources\Container;
use Acamposm\K8sResourceGenerator\Resources\Pod;
// Set well known kubernetes annotations
$podAnnotations = array_merge(
PodAnnotations::deletionCost(500),
PodAnnotations::defaultContainer('my-app-container'),
);
// Set common used kubernetes labels
$podLabels = array_merge(
PodLabels::component('database'),
PodLabels::instance('my-awesome-application-xyz'),
PodLabels::managedBy('Kustomize'),
PodLabels::name('my-awesome-application'),
PodLabels::partOf('my-awesome-application'),
PodLabels::version('1.0.0'),
);
// Now set a container for the pod
$container = new Container();
$container->name('app-name')
->addEnvVariable('DEBUG', '*')
->addPorts([
[
'containerPort' => 4000,
'name' => 'http-alt',
'protocol' => 'TCP'
]
])
->image('alpine:latest')
->imagePullPolicy(ImagePullPolicy::ALWAYS)
->setCpuRequest('100m')
->setCpuLimit(1)
->setMemoryLimit('120Mi')
->setMemoryRequest('1Gi');
// Finally fill the Pod values
$pod = new Pod();
$pod->name('pod-name')
->namespace('my-awesome-project')
->addAnnotation('imageregistry', 'https://hub.docker.com/')
->addLabels($podLabels)
->addContainers([$container->toArray()])
->addImagePullSecret('registry-access-secret')
->addNodeSelectors([
'type' => 'compute',
'diskType' => 'ssd'
])
->osName(OperatingSystem::LINUX)
->restartPolicy(RestartPolicy::NEVER)
->serviceAccount('pod-service-account')
->toYaml();
Use toYaml() method to generate a YAML representation of the Kubernetes resource.
apiVersion: v1
kind: Pod
metadata:
name: pod-name
namespace: my-awesome-project
annotations:
controller.kubernetes.io/pod-deletion-cost: 500
imageregistry: 'https://hub.docker.com/'
kubectl.kubernetes.io/default-container: my-app-container
labels:
app.kubernetes.io/component: database
app.kubernetes.io/instance: my-awesome-application-xyz
app.kubernetes.io/managed-by: Kustomize
app.kubernetes.io/name: my-awesome-application
app.kubernetes.io/part-of: my-awesome-application
app.kubernetes.io/version: 1.0.0
spec:
os:
name: linux
containers:
- env:
- name: DEBUG
value: '*'
image: 'alpine:latest'
imagePullPolicy: Always
name: app-name
ports:
- containerPort: 4000
name: http-alt
protocol: TCP
resources:
limits:
cpu: '1'
memory: '120Mi'
requests:
cpu: '100m'
memory: '1Gi'
imagePullSecrets:
- name: registry-access-secret
nodeSelector:
type: compute
diskType: ssd
restartPolicy: Never
serviceAccount: pod-service-account
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.