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
  • Setting environment variables
  • Adding variables from references
  • Attaching probes
  • Attaching volumes

Was this helpful?

Edit on GitHub
  1. Instances

Container

Example

$container = K8s::container()
    ->setName('mysql')
    ->setImage('mysql', '5.7')
    ->setPorts([
        ['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306],
    ])
    ->addPort(3307, 'TCP', 'mysql-alt')
    ->setCommand(['mysqld'])
    ->setArgs(['--test']);

Setting environment variables

To set the environment variable, simply call ->setEnv():

$container->setEnv([
    'MYSQL_ROOT_PASSWORD' => 'test',
]);

$container->addEnv('MYSQL_DATABASE', 'my_db') // this will append an env

Adding variables from references

In the below examples, the ref_key refers to the key on which the data is stored within a ConfigMap or a secret.

$container->addSecretKeyRef('MYSQL_ROOT_PASSWORD', 'secret-name', 'ref_key');

$container->addSecretKeyRefs([
    'MYSQL_ROOT_PASSWORD' => ['secret-name', 'ref_key'],
    'MYSQL_DATABASE' => ['secret-name', 'ref_key'],
]);
$container->addConfigMapRef('MYSQL_ROOT_PASSWORD', 'configmap-name', 'ref_key');

$container->addConfigMapRefs([
    'MYSQL_ROOT_PASSWORD' => ['cm-name', 'ref_key'],
    'MYSQL_DATABASE' => ['cm-name', 'ref_key'],
]);
$container->addFieldRef('NODE_NAME', 'spec.nodeName');

$container->addFieldRefs([
    'NODE_NAME' => ['spec.nodeName'],
    'POD_NAME' => ['metadata.name'],
]);

Attaching probes

You might attach the probes to the container:

$container->setLivenessProbe(
    K8s::probe()
        ->command(['sh', 'test.sh'])
        ->setInitialDelaySeconds(10)
        ->setPeriodSeconds(60)
        ->setTimeoutSeconds(10)
        ->setFailureThreshold(3)
        ->setSuccessThreshold(2)
);

$container->setStartupProbe(
    K8s::probe()
        ->http('/health', 80, ['X-CSRF-TOKEN' => 'some-token'])
        ->setInitialDelaySeconds(10)
        ->setPeriodSeconds(60)
        ->setTimeoutSeconds(10)
        ->setFailureThreshold(3)
        ->setSuccessThreshold(2)
);

$container->setReadinessProbe(
    K8s::probe()
        ->tcp(3306, '10.0.0.0')
        ->setInitialDelaySeconds(10)
        ->setPeriodSeconds(60)
        ->setTimeoutSeconds(10)
        ->setFailureThreshold(3)
        ->setSuccessThreshold(2)
);

Attaching volumes

Volumes are a tricky concept that helps you mount volumes with a pod and container. Mainly, you are given the choice to create a new Volume instance that will be attached to the pod, and you can convert that instance to a MountedVolume instance where you can attach the containers you need, just specifying the mounting path and subpath.

$awsEbsVolume = K8s::volume()->awsEbs('vol-1234', 'ext4');

$mysql = K8s::container()
    ->setName('mysql')
    ->setImage('mysql', '5.7')
    ->addMountedVolumes([
        $awsEbsVolume->mountTo('/path/in/container/to/mount/on'),
    ]);

$pod = K8s::pod()
    ->setName('mysql')
    ->setContainers([$mysql])
    ->addVolumes([$awsEbVolume]);

Limits & Requests

$container->minMemory(512, 'Mi')->maxMemory(2, 'Gi');

$container->minCpu('500m')->maxCpu(1);
PreviousAffinityNextContainer Probes

Last updated 3 years ago

Was this helpful?

To add an environment variable based on , , or , refer to the following examples.

Check docs on for more details.

Check docs on for more details, where you are given details for more volume providers.

secretKeyRef
configMapKeyRef
fieldRef
Probes
Volumes