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

Was this helpful?

Edit on GitHub
  1. Cluster Interaction

Import from YAML

For the imports to work, you will need the ext-yaml extension.

If you already have YAML files or YAML as a string, you can import them into PHP K8s resource classes:

$cluster->fromYaml($yamlAsString); // import using YAML as string

$cluster->fromYamlFile($yamlPath); // import using a path to the YAML file

The result would be a \RenokiCo\PhpK8s\Kinds\K8sResource instance you can call methods on.

If there are more resources in the same YAML file, like the ones separated by dashes, you will be given an array of them, representing each of their kind, in order.

Keep in mind, the resources are not synced, since it's not known if they exist already or not. So everything you have to do is to loop through them and make sure to call ->create() if it's needed or sync them using ->createOrUpdate():

$storageClasses = $cluster->fromYaml($awsStorageClassesYamlPath);

foreach ($storageClasses as $sc) {
    $sc->createOrUpdate();

    echo "{$sc->getName()} storage class got synced!";
}

Import templated YAMLs

This can be really useful if you decide to use the YAML import feature with local files to fill data that is being added dynamically. You would want to define your YAMLs and use curly brackets {} to define variables.

apiVersion: v1
kind: ConfigMap
metadata:
  name: settings
data:
  key1: "{value1}"
  key2: "{value2}"

In your code, you would use the fromTemplatedYamlFile and inject the values dynamically:

$cm = $cluster->fromTemplatedYamlFile('file.yaml', [
    'value1' => 'some-value-for-key-1',
    'value2' => 'some-value-for-key-2',
]);
PreviousCRUD OperationsNextWatching Resources

Last updated 3 years ago

Was this helpful?

๐Ÿ“ฆ